@edgestore/react 0.5.1 → 0.5.2
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/dist/contextProvider.d.ts +7 -0
- package/dist/contextProvider.d.ts.map +1 -1
- package/dist/createNextProxy.d.ts +2 -1
- package/dist/createNextProxy.d.ts.map +1 -1
- package/dist/index.js +12 -10
- package/dist/index.mjs +12 -10
- package/package.json +3 -3
- package/src/contextProvider.tsx +11 -0
- package/src/createNextProxy.ts +23 -12
|
@@ -27,6 +27,13 @@ export declare function createEdgeStoreProvider<TRouter extends AnyRouter>(opts?
|
|
|
27
27
|
* @default 5
|
|
28
28
|
*/
|
|
29
29
|
maxConcurrentUploads?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Accessing EdgeStore protected files in development mode requires a proxy.
|
|
32
|
+
* You might want to disable this for other providers if you are overwriting the path.
|
|
33
|
+
*
|
|
34
|
+
* @default false
|
|
35
|
+
*/
|
|
36
|
+
disableDevProxy?: boolean;
|
|
30
37
|
}): {
|
|
31
38
|
EdgeStoreProvider: ({ children, basePath, }: {
|
|
32
39
|
children: React.ReactNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contextProvider.d.ts","sourceRoot":"","sources":["../src/contextProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAU1E,KAAK,qBAAqB,CAAC,OAAO,SAAS,SAAS,IAAI;IACtD,SAAS,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;IACpC;;;;;OAKG;IACH,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B;;;;;OAKG;IACH,KAAK,EAAE,aAAa,CAAC;CACtB,CAAC;AAEF,wBAAgB,uBAAuB,CAAC,OAAO,SAAS,SAAS,EAAE,IAAI,CAAC,EAAE;IACxE;;;;;;OAMG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"contextProvider.d.ts","sourceRoot":"","sources":["../src/contextProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAU1E,KAAK,qBAAqB,CAAC,OAAO,SAAS,SAAS,IAAI;IACtD,SAAS,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;IACpC;;;;;OAKG;IACH,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B;;;;;OAKG;IACH,KAAK,EAAE,aAAa,CAAC;CACtB,CAAC;AAEF,wBAAgB,uBAAuB,CAAC,OAAO,SAAS,SAAS,EAAE,IAAI,CAAC,EAAE;IACxE;;;;;;OAMG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;;OAKG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;iDAQI;QACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;QAC1B;;;;;;WAMG;QACH,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB;;EA+BF;AAED,KAAK,aAAa,GACd;IACE,OAAO,EAAE,IAAI,CAAC;IACd,WAAW,EAAE,KAAK,CAAC;IACnB,KAAK,EAAE,KAAK,CAAC;CACd,GACD;IACE,OAAO,EAAE,KAAK,CAAC;IACf,WAAW,EAAE,KAAK,CAAC;IACnB,KAAK,EAAE,IAAI,CAAC;CACb,GACD;IACE,OAAO,EAAE,KAAK,CAAC;IACf,WAAW,EAAE,IAAI,CAAC;IAClB,KAAK,EAAE,KAAK,CAAC;CACd,CAAC"}
|
|
@@ -61,10 +61,11 @@ export type BucketFunctions<TRouter extends AnyRouter> = {
|
|
|
61
61
|
};
|
|
62
62
|
};
|
|
63
63
|
type OnProgressChangeHandler = (progress: number) => void;
|
|
64
|
-
export declare function createNextProxy<TRouter extends AnyRouter>({ apiPath, uploadingCountRef, maxConcurrentUploads, }: {
|
|
64
|
+
export declare function createNextProxy<TRouter extends AnyRouter>({ apiPath, uploadingCountRef, maxConcurrentUploads, disableDevProxy, }: {
|
|
65
65
|
apiPath: string;
|
|
66
66
|
uploadingCountRef: React.MutableRefObject<number>;
|
|
67
67
|
maxConcurrentUploads?: number;
|
|
68
|
+
disableDevProxy?: boolean;
|
|
68
69
|
}): BucketFunctions<TRouter>;
|
|
69
70
|
export {};
|
|
70
71
|
//# sourceMappingURL=createNextProxy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createNextProxy.d.ts","sourceRoot":"","sources":["../src/createNextProxy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,SAAS,EACd,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EAExB,KAAK,aAAa,EACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,CAAC;AAK7B;;;GAGG;AACH,MAAM,MAAM,QAAQ,CAAC,KAAK,IAAI;KAC3B,CAAC,IAAI,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC;CAE7B,GAAG,EAAE,CAAC;AAEP,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,SAAS,IAAI;KACtD,CAAC,IAAI,MAAM,OAAO,CAAC,SAAS,CAAC,GAAG;QAC/B;;;;;;;;;;;;;;;WAeG;QACH,MAAM,EAAE,CACN,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,SAAS,KAAK,GACjE;YACE,IAAI,EAAE,IAAI,CAAC;YACX,MAAM,CAAC,EAAE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AAqB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CACnD,EAAE,CAAC;SACL,CACN,CAAC;QACF,aAAa,EAAE,CAAC,MAAM,EAAE;YAAE,GAAG,EAAE,MAAM,CAAA;SAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;QAC1D,MAAM,EAAE,CAAC,MAAM,EAAE;YAAE,GAAG,EAAE,MAAM,CAAA;SAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;KACpD;CACF,CAAC;AAEF,KAAK,uBAAuB,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;AAE1D,wBAAgB,eAAe,CAAC,OAAO,SAAS,SAAS,EAAE,EACzD,OAAO,EACP,iBAAiB,EACjB,oBAAwB,EACxB,eAAe,GAChB,EAAE;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,KAAK,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAClD,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,4BAqEA"}
|
package/dist/index.js
CHANGED
|
@@ -45,7 +45,7 @@ async function handleError(res) {
|
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
function createNextProxy({ apiPath, uploadingCountRef, maxConcurrentUploads = 5 }) {
|
|
48
|
+
function createNextProxy({ apiPath, uploadingCountRef, maxConcurrentUploads = 5, disableDevProxy }) {
|
|
49
49
|
return new Proxy({}, {
|
|
50
50
|
get (_, prop) {
|
|
51
51
|
const bucketName = prop;
|
|
@@ -74,7 +74,7 @@ function createNextProxy({ apiPath, uploadingCountRef, maxConcurrentUploads = 5
|
|
|
74
74
|
const fileInfo = await uploadFile(params, {
|
|
75
75
|
bucketName: bucketName,
|
|
76
76
|
apiPath
|
|
77
|
-
});
|
|
77
|
+
}, disableDevProxy);
|
|
78
78
|
return fileInfo;
|
|
79
79
|
} finally{
|
|
80
80
|
uploadingCountRef.current--;
|
|
@@ -103,7 +103,7 @@ function createNextProxy({ apiPath, uploadingCountRef, maxConcurrentUploads = 5
|
|
|
103
103
|
}
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
|
-
async function uploadFile({ file, signal, input, onProgressChange, options }, { apiPath, bucketName }) {
|
|
106
|
+
async function uploadFile({ file, signal, input, onProgressChange, options }, { apiPath, bucketName }, disableDevProxy) {
|
|
107
107
|
try {
|
|
108
108
|
onProgressChange?.(0);
|
|
109
109
|
const res = await fetch(`${apiPath}/request-upload`, {
|
|
@@ -152,8 +152,8 @@ async function uploadFile({ file, signal, input, onProgressChange, options }, {
|
|
|
152
152
|
throw new EdgeStoreClientError('An error occurred');
|
|
153
153
|
}
|
|
154
154
|
return {
|
|
155
|
-
url: getUrl(json.accessUrl, apiPath),
|
|
156
|
-
thumbnailUrl: json.thumbnailUrl ? getUrl(json.thumbnailUrl, apiPath) : null,
|
|
155
|
+
url: getUrl(json.accessUrl, apiPath, disableDevProxy),
|
|
156
|
+
thumbnailUrl: json.thumbnailUrl ? getUrl(json.thumbnailUrl, apiPath, disableDevProxy) : null,
|
|
157
157
|
size: json.size,
|
|
158
158
|
uploadedAt: new Date(json.uploadedAt),
|
|
159
159
|
path: json.path,
|
|
@@ -172,9 +172,9 @@ async function uploadFile({ file, signal, input, onProgressChange, options }, {
|
|
|
172
172
|
* Protected files need third-party cookies to work.
|
|
173
173
|
* Since third party cookies don't work on localhost,
|
|
174
174
|
* we need to proxy the file through the server.
|
|
175
|
-
*/ function getUrl(url, apiPath) {
|
|
175
|
+
*/ function getUrl(url, apiPath, disableDevProxy) {
|
|
176
176
|
const mode = typeof process !== 'undefined' ? process.env.NODE_ENV : undefined?.DEV ? 'development' : 'production';
|
|
177
|
-
if (mode === 'development' && !url.includes('/_public/')) {
|
|
177
|
+
if (mode === 'development' && !url.includes('/_public/') && !disableDevProxy) {
|
|
178
178
|
const proxyUrl = new URL(window.location.origin);
|
|
179
179
|
proxyUrl.pathname = `${apiPath}/proxy-file`;
|
|
180
180
|
proxyUrl.search = new URLSearchParams({
|
|
@@ -368,7 +368,8 @@ function createEdgeStoreProvider(opts) {
|
|
|
368
368
|
children,
|
|
369
369
|
context: EdgeStoreContext,
|
|
370
370
|
basePath,
|
|
371
|
-
maxConcurrentUploads: opts?.maxConcurrentUploads
|
|
371
|
+
maxConcurrentUploads: opts?.maxConcurrentUploads,
|
|
372
|
+
disableDevProxy: opts?.disableDevProxy
|
|
372
373
|
});
|
|
373
374
|
};
|
|
374
375
|
function useEdgeStore() {
|
|
@@ -387,7 +388,7 @@ function createEdgeStoreProvider(opts) {
|
|
|
387
388
|
useEdgeStore
|
|
388
389
|
};
|
|
389
390
|
}
|
|
390
|
-
function EdgeStoreProviderInner({ children, context, basePath, maxConcurrentUploads }) {
|
|
391
|
+
function EdgeStoreProviderInner({ children, context, basePath, maxConcurrentUploads, disableDevProxy }) {
|
|
391
392
|
const apiPath = basePath ? `${basePath}` : '/api/edgestore';
|
|
392
393
|
const [state, setState] = React__namespace.useState({
|
|
393
394
|
loading: true,
|
|
@@ -465,7 +466,8 @@ function EdgeStoreProviderInner({ children, context, basePath, maxConcurrentUplo
|
|
|
465
466
|
edgestore: createNextProxy({
|
|
466
467
|
apiPath,
|
|
467
468
|
uploadingCountRef,
|
|
468
|
-
maxConcurrentUploads
|
|
469
|
+
maxConcurrentUploads,
|
|
470
|
+
disableDevProxy
|
|
469
471
|
}),
|
|
470
472
|
reset,
|
|
471
473
|
state
|
package/dist/index.mjs
CHANGED
|
@@ -21,7 +21,7 @@ async function handleError(res) {
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
function createNextProxy({ apiPath, uploadingCountRef, maxConcurrentUploads = 5 }) {
|
|
24
|
+
function createNextProxy({ apiPath, uploadingCountRef, maxConcurrentUploads = 5, disableDevProxy }) {
|
|
25
25
|
return new Proxy({}, {
|
|
26
26
|
get (_, prop) {
|
|
27
27
|
const bucketName = prop;
|
|
@@ -50,7 +50,7 @@ function createNextProxy({ apiPath, uploadingCountRef, maxConcurrentUploads = 5
|
|
|
50
50
|
const fileInfo = await uploadFile(params, {
|
|
51
51
|
bucketName: bucketName,
|
|
52
52
|
apiPath
|
|
53
|
-
});
|
|
53
|
+
}, disableDevProxy);
|
|
54
54
|
return fileInfo;
|
|
55
55
|
} finally{
|
|
56
56
|
uploadingCountRef.current--;
|
|
@@ -79,7 +79,7 @@ function createNextProxy({ apiPath, uploadingCountRef, maxConcurrentUploads = 5
|
|
|
79
79
|
}
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
|
-
async function uploadFile({ file, signal, input, onProgressChange, options }, { apiPath, bucketName }) {
|
|
82
|
+
async function uploadFile({ file, signal, input, onProgressChange, options }, { apiPath, bucketName }, disableDevProxy) {
|
|
83
83
|
try {
|
|
84
84
|
onProgressChange?.(0);
|
|
85
85
|
const res = await fetch(`${apiPath}/request-upload`, {
|
|
@@ -128,8 +128,8 @@ async function uploadFile({ file, signal, input, onProgressChange, options }, {
|
|
|
128
128
|
throw new EdgeStoreClientError('An error occurred');
|
|
129
129
|
}
|
|
130
130
|
return {
|
|
131
|
-
url: getUrl(json.accessUrl, apiPath),
|
|
132
|
-
thumbnailUrl: json.thumbnailUrl ? getUrl(json.thumbnailUrl, apiPath) : null,
|
|
131
|
+
url: getUrl(json.accessUrl, apiPath, disableDevProxy),
|
|
132
|
+
thumbnailUrl: json.thumbnailUrl ? getUrl(json.thumbnailUrl, apiPath, disableDevProxy) : null,
|
|
133
133
|
size: json.size,
|
|
134
134
|
uploadedAt: new Date(json.uploadedAt),
|
|
135
135
|
path: json.path,
|
|
@@ -148,9 +148,9 @@ async function uploadFile({ file, signal, input, onProgressChange, options }, {
|
|
|
148
148
|
* Protected files need third-party cookies to work.
|
|
149
149
|
* Since third party cookies don't work on localhost,
|
|
150
150
|
* we need to proxy the file through the server.
|
|
151
|
-
*/ function getUrl(url, apiPath) {
|
|
151
|
+
*/ function getUrl(url, apiPath, disableDevProxy) {
|
|
152
152
|
const mode = typeof process !== 'undefined' ? process.env.NODE_ENV : import.meta.env?.DEV ? 'development' : 'production';
|
|
153
|
-
if (mode === 'development' && !url.includes('/_public/')) {
|
|
153
|
+
if (mode === 'development' && !url.includes('/_public/') && !disableDevProxy) {
|
|
154
154
|
const proxyUrl = new URL(window.location.origin);
|
|
155
155
|
proxyUrl.pathname = `${apiPath}/proxy-file`;
|
|
156
156
|
proxyUrl.search = new URLSearchParams({
|
|
@@ -344,7 +344,8 @@ function createEdgeStoreProvider(opts) {
|
|
|
344
344
|
children,
|
|
345
345
|
context: EdgeStoreContext,
|
|
346
346
|
basePath,
|
|
347
|
-
maxConcurrentUploads: opts?.maxConcurrentUploads
|
|
347
|
+
maxConcurrentUploads: opts?.maxConcurrentUploads,
|
|
348
|
+
disableDevProxy: opts?.disableDevProxy
|
|
348
349
|
});
|
|
349
350
|
};
|
|
350
351
|
function useEdgeStore() {
|
|
@@ -363,7 +364,7 @@ function createEdgeStoreProvider(opts) {
|
|
|
363
364
|
useEdgeStore
|
|
364
365
|
};
|
|
365
366
|
}
|
|
366
|
-
function EdgeStoreProviderInner({ children, context, basePath, maxConcurrentUploads }) {
|
|
367
|
+
function EdgeStoreProviderInner({ children, context, basePath, maxConcurrentUploads, disableDevProxy }) {
|
|
367
368
|
const apiPath = basePath ? `${basePath}` : '/api/edgestore';
|
|
368
369
|
const [state, setState] = React.useState({
|
|
369
370
|
loading: true,
|
|
@@ -441,7 +442,8 @@ function EdgeStoreProviderInner({ children, context, basePath, maxConcurrentUplo
|
|
|
441
442
|
edgestore: createNextProxy({
|
|
442
443
|
apiPath,
|
|
443
444
|
uploadingCountRef,
|
|
444
|
-
maxConcurrentUploads
|
|
445
|
+
maxConcurrentUploads,
|
|
446
|
+
disableDevProxy
|
|
445
447
|
}),
|
|
446
448
|
reset,
|
|
447
449
|
state
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edgestore/react",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "Upload files with ease from React/Next.js",
|
|
5
5
|
"homepage": "https://edgestore.dev",
|
|
6
6
|
"repository": "https://github.com/edgestorejs/edgestore.git",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"@aws-sdk/client-s3": "^3.294.0",
|
|
68
68
|
"@aws-sdk/s3-request-presigner": "^3.294.0",
|
|
69
|
-
"@edgestore/shared": "0.5.
|
|
69
|
+
"@edgestore/shared": "0.5.2",
|
|
70
70
|
"@panva/hkdf": "^1.0.4",
|
|
71
71
|
"cookie": "^0.5.0",
|
|
72
72
|
"jose": "^4.13.1",
|
|
@@ -88,5 +88,5 @@
|
|
|
88
88
|
"typescript": "^5",
|
|
89
89
|
"zod": "3.21.4"
|
|
90
90
|
},
|
|
91
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "97cb861d3f56e4e04c83acc6808d56771433df29"
|
|
92
92
|
}
|
package/src/contextProvider.tsx
CHANGED
|
@@ -37,6 +37,13 @@ export function createEdgeStoreProvider<TRouter extends AnyRouter>(opts?: {
|
|
|
37
37
|
* @default 5
|
|
38
38
|
*/
|
|
39
39
|
maxConcurrentUploads?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Accessing EdgeStore protected files in development mode requires a proxy.
|
|
42
|
+
* You might want to disable this for other providers if you are overwriting the path.
|
|
43
|
+
*
|
|
44
|
+
* @default false
|
|
45
|
+
*/
|
|
46
|
+
disableDevProxy?: boolean;
|
|
40
47
|
}) {
|
|
41
48
|
const EdgeStoreContext = React.createContext<
|
|
42
49
|
EdgeStoreContextValue<TRouter> | undefined
|
|
@@ -61,6 +68,7 @@ export function createEdgeStoreProvider<TRouter extends AnyRouter>(opts?: {
|
|
|
61
68
|
context: EdgeStoreContext,
|
|
62
69
|
basePath,
|
|
63
70
|
maxConcurrentUploads: opts?.maxConcurrentUploads,
|
|
71
|
+
disableDevProxy: opts?.disableDevProxy,
|
|
64
72
|
});
|
|
65
73
|
};
|
|
66
74
|
|
|
@@ -109,11 +117,13 @@ function EdgeStoreProviderInner<TRouter extends AnyRouter>({
|
|
|
109
117
|
context,
|
|
110
118
|
basePath,
|
|
111
119
|
maxConcurrentUploads,
|
|
120
|
+
disableDevProxy,
|
|
112
121
|
}: {
|
|
113
122
|
children: React.ReactNode;
|
|
114
123
|
context: React.Context<EdgeStoreContextValue<TRouter> | undefined>;
|
|
115
124
|
basePath?: string;
|
|
116
125
|
maxConcurrentUploads?: number;
|
|
126
|
+
disableDevProxy?: boolean;
|
|
117
127
|
}) {
|
|
118
128
|
const apiPath = basePath ? `${basePath}` : '/api/edgestore';
|
|
119
129
|
const [state, setState] = React.useState<ProviderState>({
|
|
@@ -199,6 +209,7 @@ function EdgeStoreProviderInner<TRouter extends AnyRouter>({
|
|
|
199
209
|
apiPath,
|
|
200
210
|
uploadingCountRef,
|
|
201
211
|
maxConcurrentUploads,
|
|
212
|
+
disableDevProxy,
|
|
202
213
|
}),
|
|
203
214
|
reset,
|
|
204
215
|
state,
|
package/src/createNextProxy.ts
CHANGED
|
@@ -87,10 +87,12 @@ export function createNextProxy<TRouter extends AnyRouter>({
|
|
|
87
87
|
apiPath,
|
|
88
88
|
uploadingCountRef,
|
|
89
89
|
maxConcurrentUploads = 5,
|
|
90
|
+
disableDevProxy,
|
|
90
91
|
}: {
|
|
91
92
|
apiPath: string;
|
|
92
93
|
uploadingCountRef: React.MutableRefObject<number>;
|
|
93
94
|
maxConcurrentUploads?: number;
|
|
95
|
+
disableDevProxy?: boolean;
|
|
94
96
|
}) {
|
|
95
97
|
return new Proxy<BucketFunctions<TRouter>>({} as BucketFunctions<TRouter>, {
|
|
96
98
|
get(_, prop) {
|
|
@@ -125,10 +127,14 @@ export function createNextProxy<TRouter extends AnyRouter>({
|
|
|
125
127
|
}
|
|
126
128
|
|
|
127
129
|
uploadingCountRef.current++;
|
|
128
|
-
const fileInfo = await uploadFile(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
const fileInfo = await uploadFile(
|
|
131
|
+
params,
|
|
132
|
+
{
|
|
133
|
+
bucketName: bucketName as string,
|
|
134
|
+
apiPath,
|
|
135
|
+
},
|
|
136
|
+
disableDevProxy,
|
|
137
|
+
);
|
|
132
138
|
return fileInfo;
|
|
133
139
|
} finally {
|
|
134
140
|
uploadingCountRef.current--;
|
|
@@ -179,6 +185,7 @@ async function uploadFile(
|
|
|
179
185
|
apiPath: string;
|
|
180
186
|
bucketName: string;
|
|
181
187
|
},
|
|
188
|
+
disableDevProxy?: boolean,
|
|
182
189
|
) {
|
|
183
190
|
try {
|
|
184
191
|
onProgressChange?.(0);
|
|
@@ -228,9 +235,9 @@ async function uploadFile(
|
|
|
228
235
|
throw new EdgeStoreClientError('An error occurred');
|
|
229
236
|
}
|
|
230
237
|
return {
|
|
231
|
-
url: getUrl(json.accessUrl, apiPath),
|
|
238
|
+
url: getUrl(json.accessUrl, apiPath, disableDevProxy),
|
|
232
239
|
thumbnailUrl: json.thumbnailUrl
|
|
233
|
-
? getUrl(json.thumbnailUrl, apiPath)
|
|
240
|
+
? getUrl(json.thumbnailUrl, apiPath, disableDevProxy)
|
|
234
241
|
: null,
|
|
235
242
|
size: json.size,
|
|
236
243
|
uploadedAt: new Date(json.uploadedAt),
|
|
@@ -252,15 +259,19 @@ async function uploadFile(
|
|
|
252
259
|
* Since third party cookies don't work on localhost,
|
|
253
260
|
* we need to proxy the file through the server.
|
|
254
261
|
*/
|
|
255
|
-
function getUrl(url: string, apiPath: string) {
|
|
262
|
+
function getUrl(url: string, apiPath: string, disableDevProxy?: boolean) {
|
|
256
263
|
const mode =
|
|
257
264
|
typeof process !== 'undefined'
|
|
258
265
|
? process.env.NODE_ENV
|
|
259
266
|
: // @ts-expect-error - DEV is injected by Vite
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
if (
|
|
267
|
+
import.meta.env?.DEV
|
|
268
|
+
? 'development'
|
|
269
|
+
: 'production';
|
|
270
|
+
if (
|
|
271
|
+
mode === 'development' &&
|
|
272
|
+
!url.includes('/_public/') &&
|
|
273
|
+
!disableDevProxy
|
|
274
|
+
) {
|
|
264
275
|
const proxyUrl = new URL(window.location.origin);
|
|
265
276
|
proxyUrl.pathname = `${apiPath}/proxy-file`;
|
|
266
277
|
proxyUrl.search = new URLSearchParams({
|
|
@@ -339,7 +350,7 @@ async function multipartUpload(params: {
|
|
|
339
350
|
progress: number;
|
|
340
351
|
}[] = [];
|
|
341
352
|
const uploadPart = async (params: {
|
|
342
|
-
part: typeof parts[number];
|
|
353
|
+
part: (typeof parts)[number];
|
|
343
354
|
chunk: Blob;
|
|
344
355
|
}) => {
|
|
345
356
|
const { part, chunk } = params;
|