@edgestore/react 0.1.5-alpha.9 → 0.1.5
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 +1 -1
- package/dist/contextProvider.d.ts.map +1 -1
- package/dist/createNextProxy.d.ts +1 -1
- package/dist/createNextProxy.d.ts.map +1 -1
- package/dist/index.js +17 -9
- package/dist/index.mjs +17 -9
- package/dist/libs/errors/handleError.d.ts.map +1 -1
- package/dist/shared/index.d.ts +2 -0
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/shared/index.js +12 -0
- package/dist/shared/index.mjs +1 -0
- package/package.json +12 -5
- package/shared/index.d.ts +1 -0
- package/shared/index.js +1 -0
- package/src/contextProvider.tsx +6 -2
- package/src/createNextProxy.ts +21 -6
- package/src/libs/errors/handleError.ts +4 -3
- package/src/shared/index.ts +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contextProvider.d.ts","sourceRoot":"","sources":["../src/contextProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,
|
|
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;CAC/B;;kBASa,MAAM,SAAS;QACzB;;;;;;WAMG;;;;EAgCN;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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { type AnyRouter, type InferBucketPathObject, type InferMetadataObject, type UploadOptions } from '@edgestore/
|
|
2
|
+
import { type AnyRouter, type InferBucketPathObject, type InferMetadataObject, type UploadOptions } from '@edgestore/shared';
|
|
3
3
|
import { type z } from 'zod';
|
|
4
4
|
/**
|
|
5
5
|
* @internal
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createNextProxy.d.ts","sourceRoot":"","sources":["../src/createNextProxy.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"createNextProxy.d.ts","sourceRoot":"","sources":["../src/createNextProxy.ts"],"names":[],"mappings":"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"}
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var React = require('react');
|
|
6
|
-
var
|
|
6
|
+
var shared = require('@edgestore/shared');
|
|
7
7
|
|
|
8
8
|
function _interopNamespace(e) {
|
|
9
9
|
if (e && e.__esModule) return e;
|
|
@@ -33,14 +33,15 @@ class EdgeStoreClientError extends Error {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
async function handleError(res) {
|
|
36
|
+
let json = {};
|
|
36
37
|
try {
|
|
37
|
-
|
|
38
|
-
throw new core.EdgeStoreApiClientError({
|
|
39
|
-
response: json
|
|
40
|
-
});
|
|
38
|
+
json = await res.json();
|
|
41
39
|
} catch (err) {
|
|
42
40
|
throw new EdgeStoreClientError(`Failed to parse response. Make sure the api is correctly configured at ${res.url}`);
|
|
43
41
|
}
|
|
42
|
+
throw new shared.EdgeStoreApiClientError({
|
|
43
|
+
response: json
|
|
44
|
+
});
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
function createNextProxy({ apiPath, uploadingCountRef, maxConcurrentUploads = 5 }) {
|
|
@@ -55,10 +56,11 @@ function createNextProxy({ apiPath, uploadingCountRef, maxConcurrentUploads = 5
|
|
|
55
56
|
await new Promise((resolve)=>setTimeout(resolve, 300));
|
|
56
57
|
}
|
|
57
58
|
uploadingCountRef.current++;
|
|
58
|
-
|
|
59
|
+
const test = await uploadFile(params, {
|
|
59
60
|
bucketName: bucketName,
|
|
60
61
|
apiPath
|
|
61
62
|
});
|
|
63
|
+
return test;
|
|
62
64
|
} finally{
|
|
63
65
|
uploadingCountRef.current--;
|
|
64
66
|
}
|
|
@@ -91,6 +93,7 @@ async function uploadFile({ file, input, onProgressChange, options }, { apiPath,
|
|
|
91
93
|
onProgressChange?.(0);
|
|
92
94
|
const res = await fetch(`${apiPath}/request-upload`, {
|
|
93
95
|
method: 'POST',
|
|
96
|
+
credentials: 'include',
|
|
94
97
|
body: JSON.stringify({
|
|
95
98
|
bucketName,
|
|
96
99
|
input,
|
|
@@ -145,7 +148,8 @@ async function uploadFile({ file, input, onProgressChange, options }, { apiPath,
|
|
|
145
148
|
* Since third party cookies doesn't work on localhost,
|
|
146
149
|
* we need to proxy the file through the server.
|
|
147
150
|
*/ function getUrl(url, apiPath) {
|
|
148
|
-
|
|
151
|
+
const mode = typeof process !== 'undefined' ? process.env.NODE_ENV : undefined?.DEV ? 'development' : 'production';
|
|
152
|
+
if (mode === 'development' && !url.includes('/_public/')) {
|
|
149
153
|
const proxyUrl = new URL(window.location.origin);
|
|
150
154
|
proxyUrl.pathname = `${apiPath}/proxy-file`;
|
|
151
155
|
proxyUrl.search = new URLSearchParams({
|
|
@@ -226,6 +230,7 @@ async function multipartUpload(params) {
|
|
|
226
230
|
// Complete multipart upload
|
|
227
231
|
const res = await fetch(`${apiPath}/complete-multipart-upload`, {
|
|
228
232
|
method: 'POST',
|
|
233
|
+
credentials: 'include',
|
|
229
234
|
body: JSON.stringify({
|
|
230
235
|
bucketName,
|
|
231
236
|
uploadId,
|
|
@@ -243,6 +248,7 @@ async function multipartUpload(params) {
|
|
|
243
248
|
async function confirmUpload({ url }, { apiPath, bucketName }) {
|
|
244
249
|
const res = await fetch(`${apiPath}/confirm-upload`, {
|
|
245
250
|
method: 'POST',
|
|
251
|
+
credentials: 'include',
|
|
246
252
|
body: JSON.stringify({
|
|
247
253
|
url,
|
|
248
254
|
bucketName
|
|
@@ -259,6 +265,7 @@ async function confirmUpload({ url }, { apiPath, bucketName }) {
|
|
|
259
265
|
async function deleteFile({ url }, { apiPath, bucketName }) {
|
|
260
266
|
const res = await fetch(`${apiPath}/delete-file`, {
|
|
261
267
|
method: 'POST',
|
|
268
|
+
credentials: 'include',
|
|
262
269
|
body: JSON.stringify({
|
|
263
270
|
url,
|
|
264
271
|
bucketName
|
|
@@ -310,7 +317,7 @@ async function queuedPromises({ items, fn, maxParallel, maxRetries = 0 }) {
|
|
|
310
317
|
return results;
|
|
311
318
|
}
|
|
312
319
|
|
|
313
|
-
const DEFAULT_BASE_URL = process.env.NEXT_PUBLIC_EDGE_STORE_BASE_URL ?? 'https://files.edgestore.dev';
|
|
320
|
+
const DEFAULT_BASE_URL = (typeof process !== 'undefined' ? process.env.NEXT_PUBLIC_EDGE_STORE_BASE_URL : undefined?.EDGE_STORE_BASE_URL) ?? 'https://files.edgestore.dev';
|
|
314
321
|
function createEdgeStoreProvider(opts) {
|
|
315
322
|
const EdgeStoreContext = /*#__PURE__*/ React__namespace.createContext(undefined);
|
|
316
323
|
const EdgeStoreProvider = ({ children, basePath })=>{
|
|
@@ -363,7 +370,8 @@ function EdgeStoreProviderInner({ children, context, basePath, maxConcurrentUplo
|
|
|
363
370
|
error: false
|
|
364
371
|
});
|
|
365
372
|
const res = await fetch(`${apiPath}/init`, {
|
|
366
|
-
method: 'POST'
|
|
373
|
+
method: 'POST',
|
|
374
|
+
credentials: 'include'
|
|
367
375
|
});
|
|
368
376
|
if (res.ok) {
|
|
369
377
|
const json = await res.json();
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { EdgeStoreApiClientError } from '@edgestore/
|
|
2
|
+
import { EdgeStoreApiClientError } from '@edgestore/shared';
|
|
3
3
|
|
|
4
4
|
class EdgeStoreClientError extends Error {
|
|
5
5
|
constructor(message){
|
|
@@ -9,14 +9,15 @@ class EdgeStoreClientError extends Error {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
async function handleError(res) {
|
|
12
|
+
let json = {};
|
|
12
13
|
try {
|
|
13
|
-
|
|
14
|
-
throw new EdgeStoreApiClientError({
|
|
15
|
-
response: json
|
|
16
|
-
});
|
|
14
|
+
json = await res.json();
|
|
17
15
|
} catch (err) {
|
|
18
16
|
throw new EdgeStoreClientError(`Failed to parse response. Make sure the api is correctly configured at ${res.url}`);
|
|
19
17
|
}
|
|
18
|
+
throw new EdgeStoreApiClientError({
|
|
19
|
+
response: json
|
|
20
|
+
});
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
function createNextProxy({ apiPath, uploadingCountRef, maxConcurrentUploads = 5 }) {
|
|
@@ -31,10 +32,11 @@ function createNextProxy({ apiPath, uploadingCountRef, maxConcurrentUploads = 5
|
|
|
31
32
|
await new Promise((resolve)=>setTimeout(resolve, 300));
|
|
32
33
|
}
|
|
33
34
|
uploadingCountRef.current++;
|
|
34
|
-
|
|
35
|
+
const test = await uploadFile(params, {
|
|
35
36
|
bucketName: bucketName,
|
|
36
37
|
apiPath
|
|
37
38
|
});
|
|
39
|
+
return test;
|
|
38
40
|
} finally{
|
|
39
41
|
uploadingCountRef.current--;
|
|
40
42
|
}
|
|
@@ -67,6 +69,7 @@ async function uploadFile({ file, input, onProgressChange, options }, { apiPath,
|
|
|
67
69
|
onProgressChange?.(0);
|
|
68
70
|
const res = await fetch(`${apiPath}/request-upload`, {
|
|
69
71
|
method: 'POST',
|
|
72
|
+
credentials: 'include',
|
|
70
73
|
body: JSON.stringify({
|
|
71
74
|
bucketName,
|
|
72
75
|
input,
|
|
@@ -121,7 +124,8 @@ async function uploadFile({ file, input, onProgressChange, options }, { apiPath,
|
|
|
121
124
|
* Since third party cookies doesn't work on localhost,
|
|
122
125
|
* we need to proxy the file through the server.
|
|
123
126
|
*/ function getUrl(url, apiPath) {
|
|
124
|
-
|
|
127
|
+
const mode = typeof process !== 'undefined' ? process.env.NODE_ENV : import.meta.env?.DEV ? 'development' : 'production';
|
|
128
|
+
if (mode === 'development' && !url.includes('/_public/')) {
|
|
125
129
|
const proxyUrl = new URL(window.location.origin);
|
|
126
130
|
proxyUrl.pathname = `${apiPath}/proxy-file`;
|
|
127
131
|
proxyUrl.search = new URLSearchParams({
|
|
@@ -202,6 +206,7 @@ async function multipartUpload(params) {
|
|
|
202
206
|
// Complete multipart upload
|
|
203
207
|
const res = await fetch(`${apiPath}/complete-multipart-upload`, {
|
|
204
208
|
method: 'POST',
|
|
209
|
+
credentials: 'include',
|
|
205
210
|
body: JSON.stringify({
|
|
206
211
|
bucketName,
|
|
207
212
|
uploadId,
|
|
@@ -219,6 +224,7 @@ async function multipartUpload(params) {
|
|
|
219
224
|
async function confirmUpload({ url }, { apiPath, bucketName }) {
|
|
220
225
|
const res = await fetch(`${apiPath}/confirm-upload`, {
|
|
221
226
|
method: 'POST',
|
|
227
|
+
credentials: 'include',
|
|
222
228
|
body: JSON.stringify({
|
|
223
229
|
url,
|
|
224
230
|
bucketName
|
|
@@ -235,6 +241,7 @@ async function confirmUpload({ url }, { apiPath, bucketName }) {
|
|
|
235
241
|
async function deleteFile({ url }, { apiPath, bucketName }) {
|
|
236
242
|
const res = await fetch(`${apiPath}/delete-file`, {
|
|
237
243
|
method: 'POST',
|
|
244
|
+
credentials: 'include',
|
|
238
245
|
body: JSON.stringify({
|
|
239
246
|
url,
|
|
240
247
|
bucketName
|
|
@@ -286,7 +293,7 @@ async function queuedPromises({ items, fn, maxParallel, maxRetries = 0 }) {
|
|
|
286
293
|
return results;
|
|
287
294
|
}
|
|
288
295
|
|
|
289
|
-
const DEFAULT_BASE_URL = process.env.NEXT_PUBLIC_EDGE_STORE_BASE_URL ?? 'https://files.edgestore.dev';
|
|
296
|
+
const DEFAULT_BASE_URL = (typeof process !== 'undefined' ? process.env.NEXT_PUBLIC_EDGE_STORE_BASE_URL : import.meta.env?.EDGE_STORE_BASE_URL) ?? 'https://files.edgestore.dev';
|
|
290
297
|
function createEdgeStoreProvider(opts) {
|
|
291
298
|
const EdgeStoreContext = /*#__PURE__*/ React.createContext(undefined);
|
|
292
299
|
const EdgeStoreProvider = ({ children, basePath })=>{
|
|
@@ -339,7 +346,8 @@ function EdgeStoreProviderInner({ children, context, basePath, maxConcurrentUplo
|
|
|
339
346
|
error: false
|
|
340
347
|
});
|
|
341
348
|
const res = await fetch(`${apiPath}/init`, {
|
|
342
|
-
method: 'POST'
|
|
349
|
+
method: 'POST',
|
|
350
|
+
credentials: 'include'
|
|
343
351
|
});
|
|
344
352
|
if (res.ok) {
|
|
345
353
|
const json = await res.json();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleError.d.ts","sourceRoot":"","sources":["../../../src/libs/errors/handleError.ts"],"names":[],"mappings":"AAGA,wBAAsB,WAAW,CAAC,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"handleError.d.ts","sourceRoot":"","sources":["../../../src/libs/errors/handleError.ts"],"names":[],"mappings":"AAGA,wBAAsB,WAAW,CAAC,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,CAU/D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var shared = require('@edgestore/shared');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
Object.defineProperty(exports, 'EdgeStoreApiClientError', {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () { return shared.EdgeStoreApiClientError; }
|
|
12
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { EdgeStoreApiClientError } from '@edgestore/shared';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edgestore/react",
|
|
3
|
-
"version": "0.1.5
|
|
3
|
+
"version": "0.1.5",
|
|
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",
|
|
@@ -36,6 +36,11 @@
|
|
|
36
36
|
"import": "./dist/utils/index.mjs",
|
|
37
37
|
"require": "./dist/utils/index.js",
|
|
38
38
|
"default": "./dist/utils/index.js"
|
|
39
|
+
},
|
|
40
|
+
"./shared": {
|
|
41
|
+
"import": "./dist/shared/index.mjs",
|
|
42
|
+
"require": "./dist/shared/index.js",
|
|
43
|
+
"default": "./dist/shared/index.js"
|
|
39
44
|
}
|
|
40
45
|
},
|
|
41
46
|
"files": [
|
|
@@ -44,6 +49,7 @@
|
|
|
44
49
|
"README.md",
|
|
45
50
|
"package.json",
|
|
46
51
|
"utils",
|
|
52
|
+
"shared",
|
|
47
53
|
"!**/*.test.*"
|
|
48
54
|
],
|
|
49
55
|
"private": false,
|
|
@@ -60,14 +66,15 @@
|
|
|
60
66
|
"uuid": "^9.0.0"
|
|
61
67
|
},
|
|
62
68
|
"peerDependencies": {
|
|
63
|
-
"@edgestore/
|
|
69
|
+
"@edgestore/shared": "0.1.5",
|
|
64
70
|
"next": "*",
|
|
65
71
|
"react": ">=16.8.0",
|
|
66
72
|
"react-dom": ">=16.8.0",
|
|
67
73
|
"zod": ">=3.0.0"
|
|
68
74
|
},
|
|
69
75
|
"devDependencies": {
|
|
70
|
-
"@edgestore/
|
|
76
|
+
"@edgestore/shared": "0.1.5",
|
|
77
|
+
"@swc/helpers": "0.5.3",
|
|
71
78
|
"@types/cookie": "^0.5.1",
|
|
72
79
|
"@types/node": "^18.11.18",
|
|
73
80
|
"@types/uuid": "^9.0.1",
|
|
@@ -75,7 +82,7 @@
|
|
|
75
82
|
"react": "^18.2.0",
|
|
76
83
|
"react-dom": "^18.2.0",
|
|
77
84
|
"typescript": "^5.1.6",
|
|
78
|
-
"zod": "
|
|
85
|
+
"zod": "3.21.4"
|
|
79
86
|
},
|
|
80
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "44951b90386930abadb67009cc9a5d1826b5cecb"
|
|
81
88
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/shared';
|
package/shared/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/shared');
|
package/src/contextProvider.tsx
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { type AnyRouter } from '@edgestore/
|
|
1
|
+
import { type AnyRouter } from '@edgestore/shared';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { createNextProxy, type BucketFunctions } from './createNextProxy';
|
|
4
4
|
import EdgeStoreClientError from './libs/errors/EdgeStoreClientError';
|
|
5
5
|
import { handleError } from './libs/errors/handleError';
|
|
6
6
|
|
|
7
7
|
const DEFAULT_BASE_URL =
|
|
8
|
-
process
|
|
8
|
+
(typeof process !== 'undefined'
|
|
9
|
+
? process.env.NEXT_PUBLIC_EDGE_STORE_BASE_URL
|
|
10
|
+
: // @ts-expect-error - In Vite, the env variables are available on `import.meta`.
|
|
11
|
+
import.meta.env?.EDGE_STORE_BASE_URL) ?? 'https://files.edgestore.dev';
|
|
9
12
|
|
|
10
13
|
type EdgeStoreContextValue<TRouter extends AnyRouter> = {
|
|
11
14
|
edgestore: BucketFunctions<TRouter>;
|
|
@@ -140,6 +143,7 @@ function EdgeStoreProviderInner<TRouter extends AnyRouter>({
|
|
|
140
143
|
});
|
|
141
144
|
const res = await fetch(`${apiPath}/init`, {
|
|
142
145
|
method: 'POST',
|
|
146
|
+
credentials: 'include',
|
|
143
147
|
});
|
|
144
148
|
if (res.ok) {
|
|
145
149
|
const json = await res.json();
|
package/src/createNextProxy.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { type RequestUploadRes } from '@edgestore/server/adapters';
|
|
2
1
|
import {
|
|
3
2
|
type AnyRouter,
|
|
4
3
|
type InferBucketPathObject,
|
|
5
4
|
type InferMetadataObject,
|
|
5
|
+
type SharedRequestUploadRes,
|
|
6
6
|
type UploadOptions,
|
|
7
|
-
} from '@edgestore/
|
|
7
|
+
} from '@edgestore/shared';
|
|
8
8
|
import { type z } from 'zod';
|
|
9
9
|
import EdgeStoreClientError from './libs/errors/EdgeStoreClientError';
|
|
10
10
|
import { handleError } from './libs/errors/handleError';
|
|
@@ -87,10 +87,11 @@ export function createNextProxy<TRouter extends AnyRouter>({
|
|
|
87
87
|
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
88
88
|
}
|
|
89
89
|
uploadingCountRef.current++;
|
|
90
|
-
|
|
90
|
+
const test = await uploadFile(params, {
|
|
91
91
|
bucketName: bucketName as string,
|
|
92
92
|
apiPath,
|
|
93
93
|
});
|
|
94
|
+
return test;
|
|
94
95
|
} finally {
|
|
95
96
|
uploadingCountRef.current--;
|
|
96
97
|
}
|
|
@@ -143,6 +144,7 @@ async function uploadFile(
|
|
|
143
144
|
onProgressChange?.(0);
|
|
144
145
|
const res = await fetch(`${apiPath}/request-upload`, {
|
|
145
146
|
method: 'POST',
|
|
147
|
+
credentials: 'include',
|
|
146
148
|
body: JSON.stringify({
|
|
147
149
|
bucketName,
|
|
148
150
|
input,
|
|
@@ -162,7 +164,7 @@ async function uploadFile(
|
|
|
162
164
|
if (!res.ok) {
|
|
163
165
|
await handleError(res);
|
|
164
166
|
}
|
|
165
|
-
const json = (await res.json()) as
|
|
167
|
+
const json = (await res.json()) as SharedRequestUploadRes;
|
|
166
168
|
if ('multipart' in json) {
|
|
167
169
|
await multipartUpload({
|
|
168
170
|
bucketName,
|
|
@@ -201,7 +203,14 @@ async function uploadFile(
|
|
|
201
203
|
* we need to proxy the file through the server.
|
|
202
204
|
*/
|
|
203
205
|
function getUrl(url: string, apiPath: string) {
|
|
204
|
-
|
|
206
|
+
const mode =
|
|
207
|
+
typeof process !== 'undefined'
|
|
208
|
+
? process.env.NODE_ENV
|
|
209
|
+
: // @ts-expect-error - DEV is injected by Vite
|
|
210
|
+
import.meta.env?.DEV
|
|
211
|
+
? 'development'
|
|
212
|
+
: 'production';
|
|
213
|
+
if (mode === 'development' && !url.includes('/_public/')) {
|
|
205
214
|
const proxyUrl = new URL(window.location.origin);
|
|
206
215
|
proxyUrl.pathname = `${apiPath}/proxy-file`;
|
|
207
216
|
proxyUrl.search = new URLSearchParams({
|
|
@@ -250,7 +259,10 @@ const uploadFileInner = async (
|
|
|
250
259
|
|
|
251
260
|
async function multipartUpload(params: {
|
|
252
261
|
bucketName: string;
|
|
253
|
-
multipartInfo: Extract<
|
|
262
|
+
multipartInfo: Extract<
|
|
263
|
+
SharedRequestUploadRes,
|
|
264
|
+
{ multipart: any }
|
|
265
|
+
>['multipart'];
|
|
254
266
|
onProgressChange: OnProgressChangeHandler | undefined;
|
|
255
267
|
file: File;
|
|
256
268
|
apiPath: string;
|
|
@@ -314,6 +326,7 @@ async function multipartUpload(params: {
|
|
|
314
326
|
// Complete multipart upload
|
|
315
327
|
const res = await fetch(`${apiPath}/complete-multipart-upload`, {
|
|
316
328
|
method: 'POST',
|
|
329
|
+
credentials: 'include',
|
|
317
330
|
body: JSON.stringify({
|
|
318
331
|
bucketName,
|
|
319
332
|
uploadId,
|
|
@@ -345,6 +358,7 @@ async function confirmUpload(
|
|
|
345
358
|
) {
|
|
346
359
|
const res = await fetch(`${apiPath}/confirm-upload`, {
|
|
347
360
|
method: 'POST',
|
|
361
|
+
credentials: 'include',
|
|
348
362
|
body: JSON.stringify({
|
|
349
363
|
url,
|
|
350
364
|
bucketName,
|
|
@@ -375,6 +389,7 @@ async function deleteFile(
|
|
|
375
389
|
) {
|
|
376
390
|
const res = await fetch(`${apiPath}/delete-file`, {
|
|
377
391
|
method: 'POST',
|
|
392
|
+
credentials: 'include',
|
|
378
393
|
body: JSON.stringify({
|
|
379
394
|
url,
|
|
380
395
|
bucketName,
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { EdgeStoreApiClientError } from '@edgestore/
|
|
1
|
+
import { EdgeStoreApiClientError } from '@edgestore/shared';
|
|
2
2
|
import EdgeStoreClientError from './EdgeStoreClientError';
|
|
3
3
|
|
|
4
4
|
export async function handleError(res: Response): Promise<never> {
|
|
5
|
+
let json: any = {};
|
|
5
6
|
try {
|
|
6
|
-
|
|
7
|
-
throw new EdgeStoreApiClientError({ response: json });
|
|
7
|
+
json = await res.json();
|
|
8
8
|
} catch (err) {
|
|
9
9
|
throw new EdgeStoreClientError(
|
|
10
10
|
`Failed to parse response. Make sure the api is correctly configured at ${res.url}`,
|
|
11
11
|
);
|
|
12
12
|
}
|
|
13
|
+
throw new EdgeStoreApiClientError({ response: json });
|
|
13
14
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { EdgeStoreApiClientError } from '@edgestore/shared';
|