robodev 0.17.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/templates/auth-chat/apps/fe/src/config/app.config.ts +2 -2
- package/templates/auth-chat/package.json +1 -1
- package/templates/backend/package.json +1 -1
- package/templates/empty/package.json +1 -1
- package/templates/space/apps/fe/src/config/app.config.ts +2 -2
- package/templates/space/apps/fe/src/utils/media-upload-headers.ts +8 -0
- package/templates/space/apps/fe/src/utils/media-upload.test.ts +19 -0
- package/templates/space/apps/fe/src/utils/media-upload.ts +12 -3
- package/templates/space/package.json +1 -1
package/package.json
CHANGED
|
@@ -2,8 +2,8 @@ const authCustomJWT = {
|
|
|
2
2
|
enableMagicLink: import.meta.env.VITE_PUBLIC_AUTH_CUSTOM_JWT_ENABLE_MAGIC_LINK === "true",
|
|
3
3
|
};
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const apiOrigin =
|
|
5
|
+
const rawApiUrl = import.meta.env.VITE_PUBLIC_API_URL?.trim() ?? "";
|
|
6
|
+
const apiOrigin = /^https?:\/\//i.test(rawApiUrl) ? rawApiUrl.replace(/\/+$/, "") : "";
|
|
7
7
|
const apiMode = import.meta.env.VITE_PUBLIC_API_MODE ?? "real";
|
|
8
8
|
export const AppConfig = {
|
|
9
9
|
isProduction: import.meta.env.NODE_ENV === "production",
|
|
@@ -2,8 +2,8 @@ const authCustomJWT = {
|
|
|
2
2
|
enableMagicLink: import.meta.env.VITE_PUBLIC_AUTH_CUSTOM_JWT_ENABLE_MAGIC_LINK === "true",
|
|
3
3
|
};
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const apiOrigin =
|
|
5
|
+
const rawApiUrl = import.meta.env.VITE_PUBLIC_API_URL?.trim() ?? "";
|
|
6
|
+
const apiOrigin = /^https?:\/\//i.test(rawApiUrl) ? rawApiUrl.replace(/\/+$/, "") : "";
|
|
7
7
|
const apiMode = import.meta.env.VITE_PUBLIC_API_MODE ?? "real";
|
|
8
8
|
export const AppConfig = {
|
|
9
9
|
isProduction: import.meta.env.NODE_ENV === "production",
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Raw FormData upload headers. Never set Content-Type — the browser must add the multipart boundary. */
|
|
2
|
+
export function mediaUploadHeaders(accessToken: string | null): Headers {
|
|
3
|
+
const headers = new Headers();
|
|
4
|
+
if (accessToken) {
|
|
5
|
+
headers.set("Authorization", `Bearer ${accessToken}`);
|
|
6
|
+
}
|
|
7
|
+
return headers;
|
|
8
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { mediaUploadHeaders } from "./media-upload-headers";
|
|
4
|
+
|
|
5
|
+
describe("raw FormData upload headers", () => {
|
|
6
|
+
it("sends Bearer when a token exists and does not set Content-Type", () => {
|
|
7
|
+
const headers = mediaUploadHeaders("test-access-token");
|
|
8
|
+
|
|
9
|
+
expect(headers.get("Authorization")).toBe("Bearer test-access-token");
|
|
10
|
+
expect(headers.get("Content-Type")).toBeNull();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("omits Authorization when no token exists and still does not set Content-Type", () => {
|
|
14
|
+
const headers = mediaUploadHeaders(null);
|
|
15
|
+
|
|
16
|
+
expect(headers.get("Authorization")).toBeNull();
|
|
17
|
+
expect(headers.get("Content-Type")).toBeNull();
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { FileUploadRequest } from "@povio/ui";
|
|
2
2
|
|
|
3
|
+
import { authTokenStore } from "@/clients/auth-token-store";
|
|
3
4
|
import { AppConfig } from "@/config/app.config";
|
|
4
5
|
import type { MediaModels } from "@/openapi/media/media.models";
|
|
5
6
|
import { MediaQueries } from "@/openapi/media/media.queries";
|
|
7
|
+
import { mediaUploadHeaders } from "@/utils/media-upload-headers";
|
|
6
8
|
|
|
7
9
|
interface UseMediaUploadHandlerOptions {
|
|
8
10
|
resourceName: MediaModels.MediaResourceName;
|
|
@@ -40,13 +42,20 @@ export function useMediaUploadHandler({ resourceName, method, onUploaded }: UseM
|
|
|
40
42
|
});
|
|
41
43
|
formData.append("file", file);
|
|
42
44
|
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
const origin = AppConfig.api.url.replace(/\/+$/, "");
|
|
46
|
+
const path = instructions.url;
|
|
47
|
+
const uploadUrl = /^https?:\/\//i.test(path)
|
|
48
|
+
? path
|
|
49
|
+
: origin
|
|
50
|
+
? `${origin}${path}`
|
|
51
|
+
: path.startsWith("/")
|
|
52
|
+
? path
|
|
53
|
+
: `/${path}`;
|
|
46
54
|
|
|
47
55
|
const response = await fetch(uploadUrl, {
|
|
48
56
|
method: instructions.method.toUpperCase(),
|
|
49
57
|
body: formData,
|
|
58
|
+
headers: mediaUploadHeaders(authTokenStore.getAccessToken()),
|
|
50
59
|
signal: options?.abortController?.signal,
|
|
51
60
|
});
|
|
52
61
|
|