@edgestore/server 0.1.0 → 0.1.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/README.md +6 -6
- package/adapters/index.d.ts +1 -0
- package/adapters/index.js +1 -0
- package/dist/adapters/index.d.ts +2 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +2 -0
- package/dist/adapters/index.mjs +1 -0
- package/dist/adapters/next/app/index.d.ts +4 -4
- package/dist/adapters/next/app/index.d.ts.map +1 -1
- package/dist/adapters/next/app/index.js +22 -2
- package/dist/adapters/next/app/index.mjs +22 -2
- package/dist/adapters/next/pages/index.d.ts +4 -4
- package/dist/adapters/next/pages/index.d.ts.map +1 -1
- package/dist/adapters/next/pages/index.js +18 -2
- package/dist/adapters/next/pages/index.mjs +18 -2
- package/dist/adapters/shared.d.ts +35 -2
- package/dist/adapters/shared.d.ts.map +1 -1
- package/dist/core/client/index.d.ts +11 -3
- package/dist/core/client/index.d.ts.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +5 -4
- package/dist/core/index.mjs +6 -5
- package/dist/core/internals/bucketBuilder.d.ts +2 -1
- package/dist/core/internals/bucketBuilder.d.ts.map +1 -1
- package/dist/core/sdk/index.d.ts +43 -2
- package/dist/core/sdk/index.d.ts.map +1 -1
- package/dist/{index-579b8015.mjs → index-30a3741e.mjs} +43 -2
- package/dist/{index-62d969e5.js → index-50ab9e08.js} +43 -2
- package/dist/{index-0a168903.js → index-f33a00fb.js} +41 -0
- package/dist/providers/aws/index.d.ts +28 -1
- package/dist/providers/aws/index.d.ts.map +1 -1
- package/dist/providers/aws/index.js +7 -1
- package/dist/providers/aws/index.mjs +7 -1
- package/dist/providers/edgestore/index.d.ts +13 -1
- package/dist/providers/edgestore/index.d.ts.map +1 -1
- package/dist/providers/edgestore/index.js +24 -10
- package/dist/providers/edgestore/index.mjs +24 -10
- package/dist/providers/index.d.ts +1 -2
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +2 -0
- package/dist/providers/index.mjs +1 -0
- package/dist/providers/types.d.ts +26 -2
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/{shared-2a9c8307.mjs → shared-7fc08e14.mjs} +40 -2
- package/dist/{shared-ae739a04.js → shared-a5b84d0b.js} +41 -1
- package/dist/{shared-fac1b0a0.js → shared-a86ccc68.js} +39 -1
- package/package.json +13 -3
- package/providers/index.d.ts +1 -0
- package/providers/index.js +1 -0
- package/src/adapters/index.ts +6 -0
- package/src/adapters/next/app/index.ts +33 -7
- package/src/adapters/next/pages/index.ts +27 -7
- package/src/adapters/shared.ts +90 -2
- package/src/core/client/index.ts +15 -9
- package/src/core/index.ts +1 -1
- package/src/core/internals/bucketBuilder.ts +6 -1
- package/src/core/sdk/index.ts +83 -2
- package/src/providers/aws/index.ts +39 -5
- package/src/providers/edgestore/index.ts +34 -9
- package/src/providers/index.ts +1 -2
- package/src/providers/types.ts +34 -4
|
@@ -80,13 +80,16 @@ const edgeStoreRawSdk = {
|
|
|
80
80
|
mimeType: fileInfo.type,
|
|
81
81
|
metadata: fileInfo.metadata,
|
|
82
82
|
fileName: fileInfo.fileName,
|
|
83
|
-
replaceTargetUrl: fileInfo.replaceTargetUrl
|
|
83
|
+
replaceTargetUrl: fileInfo.replaceTargetUrl,
|
|
84
|
+
isTemporary: fileInfo.temporary
|
|
84
85
|
}
|
|
85
86
|
});
|
|
86
87
|
return {
|
|
87
88
|
multipart: res.multipart,
|
|
88
89
|
signedUrl: res.signedUrl,
|
|
89
|
-
accessUrl: res.url
|
|
90
|
+
accessUrl: res.url,
|
|
91
|
+
path: res.path,
|
|
92
|
+
thumbnailUrl: res.thumbnailUrl
|
|
90
93
|
};
|
|
91
94
|
},
|
|
92
95
|
async requestUploadParts ({ accessKey, secretKey, key, multipart }) {
|
|
@@ -103,6 +106,28 @@ const edgeStoreRawSdk = {
|
|
|
103
106
|
multipart: res.multipart
|
|
104
107
|
};
|
|
105
108
|
},
|
|
109
|
+
async completeMultipartUpload ({ accessKey, secretKey, uploadId, key, parts }) {
|
|
110
|
+
return await makeRequest({
|
|
111
|
+
path: '/complete-multipart-upload',
|
|
112
|
+
accessKey,
|
|
113
|
+
secretKey,
|
|
114
|
+
body: {
|
|
115
|
+
uploadId,
|
|
116
|
+
key,
|
|
117
|
+
parts
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
async confirmUpload ({ accessKey, secretKey, url }) {
|
|
122
|
+
return await makeRequest({
|
|
123
|
+
path: '/confirm-upload',
|
|
124
|
+
accessKey,
|
|
125
|
+
secretKey,
|
|
126
|
+
body: {
|
|
127
|
+
url
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
},
|
|
106
131
|
async deleteFile ({ accessKey, secretKey, url }) {
|
|
107
132
|
return await makeRequest({
|
|
108
133
|
path: '/delete-file',
|
|
@@ -165,6 +190,22 @@ function initEdgeStoreSdk(params) {
|
|
|
165
190
|
multipart
|
|
166
191
|
});
|
|
167
192
|
},
|
|
193
|
+
async completeMultipartUpload ({ uploadId, key, parts }) {
|
|
194
|
+
return await edgeStoreRawSdk.completeMultipartUpload({
|
|
195
|
+
accessKey,
|
|
196
|
+
secretKey,
|
|
197
|
+
uploadId,
|
|
198
|
+
key,
|
|
199
|
+
parts
|
|
200
|
+
});
|
|
201
|
+
},
|
|
202
|
+
async confirmUpload ({ url }) {
|
|
203
|
+
return await edgeStoreRawSdk.confirmUpload({
|
|
204
|
+
accessKey,
|
|
205
|
+
secretKey,
|
|
206
|
+
url
|
|
207
|
+
});
|
|
208
|
+
},
|
|
168
209
|
async deleteFile ({ url }) {
|
|
169
210
|
return await edgeStoreRawSdk.deleteFile({
|
|
170
211
|
accessKey,
|
|
@@ -82,13 +82,16 @@ const edgeStoreRawSdk = {
|
|
|
82
82
|
mimeType: fileInfo.type,
|
|
83
83
|
metadata: fileInfo.metadata,
|
|
84
84
|
fileName: fileInfo.fileName,
|
|
85
|
-
replaceTargetUrl: fileInfo.replaceTargetUrl
|
|
85
|
+
replaceTargetUrl: fileInfo.replaceTargetUrl,
|
|
86
|
+
isTemporary: fileInfo.temporary
|
|
86
87
|
}
|
|
87
88
|
});
|
|
88
89
|
return {
|
|
89
90
|
multipart: res.multipart,
|
|
90
91
|
signedUrl: res.signedUrl,
|
|
91
|
-
accessUrl: res.url
|
|
92
|
+
accessUrl: res.url,
|
|
93
|
+
path: res.path,
|
|
94
|
+
thumbnailUrl: res.thumbnailUrl
|
|
92
95
|
};
|
|
93
96
|
},
|
|
94
97
|
async requestUploadParts ({ accessKey, secretKey, key, multipart }) {
|
|
@@ -105,6 +108,28 @@ const edgeStoreRawSdk = {
|
|
|
105
108
|
multipart: res.multipart
|
|
106
109
|
};
|
|
107
110
|
},
|
|
111
|
+
async completeMultipartUpload ({ accessKey, secretKey, uploadId, key, parts }) {
|
|
112
|
+
return await makeRequest({
|
|
113
|
+
path: '/complete-multipart-upload',
|
|
114
|
+
accessKey,
|
|
115
|
+
secretKey,
|
|
116
|
+
body: {
|
|
117
|
+
uploadId,
|
|
118
|
+
key,
|
|
119
|
+
parts
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
},
|
|
123
|
+
async confirmUpload ({ accessKey, secretKey, url }) {
|
|
124
|
+
return await makeRequest({
|
|
125
|
+
path: '/confirm-upload',
|
|
126
|
+
accessKey,
|
|
127
|
+
secretKey,
|
|
128
|
+
body: {
|
|
129
|
+
url
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
},
|
|
108
133
|
async deleteFile ({ accessKey, secretKey, url }) {
|
|
109
134
|
return await makeRequest({
|
|
110
135
|
path: '/delete-file',
|
|
@@ -167,6 +192,22 @@ function initEdgeStoreSdk(params) {
|
|
|
167
192
|
multipart
|
|
168
193
|
});
|
|
169
194
|
},
|
|
195
|
+
async completeMultipartUpload ({ uploadId, key, parts }) {
|
|
196
|
+
return await edgeStoreRawSdk.completeMultipartUpload({
|
|
197
|
+
accessKey,
|
|
198
|
+
secretKey,
|
|
199
|
+
uploadId,
|
|
200
|
+
key,
|
|
201
|
+
parts
|
|
202
|
+
});
|
|
203
|
+
},
|
|
204
|
+
async confirmUpload ({ url }) {
|
|
205
|
+
return await edgeStoreRawSdk.confirmUpload({
|
|
206
|
+
accessKey,
|
|
207
|
+
secretKey,
|
|
208
|
+
url
|
|
209
|
+
});
|
|
210
|
+
},
|
|
170
211
|
async deleteFile ({ url }) {
|
|
171
212
|
return await edgeStoreRawSdk.deleteFile({
|
|
172
213
|
accessKey,
|
|
@@ -81,12 +81,15 @@ const edgeStoreRawSdk = {
|
|
|
81
81
|
metadata: fileInfo.metadata,
|
|
82
82
|
fileName: fileInfo.fileName,
|
|
83
83
|
replaceTargetUrl: fileInfo.replaceTargetUrl,
|
|
84
|
+
isTemporary: fileInfo.temporary,
|
|
84
85
|
},
|
|
85
86
|
});
|
|
86
87
|
return {
|
|
87
88
|
multipart: res.multipart,
|
|
88
89
|
signedUrl: res.signedUrl,
|
|
89
90
|
accessUrl: res.url,
|
|
91
|
+
path: res.path,
|
|
92
|
+
thumbnailUrl: res.thumbnailUrl,
|
|
90
93
|
};
|
|
91
94
|
},
|
|
92
95
|
async requestUploadParts({ accessKey, secretKey, key, multipart, }) {
|
|
@@ -103,6 +106,28 @@ const edgeStoreRawSdk = {
|
|
|
103
106
|
multipart: res.multipart,
|
|
104
107
|
};
|
|
105
108
|
},
|
|
109
|
+
async completeMultipartUpload({ accessKey, secretKey, uploadId, key, parts, }) {
|
|
110
|
+
return await makeRequest({
|
|
111
|
+
path: '/complete-multipart-upload',
|
|
112
|
+
accessKey,
|
|
113
|
+
secretKey,
|
|
114
|
+
body: {
|
|
115
|
+
uploadId,
|
|
116
|
+
key,
|
|
117
|
+
parts,
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
async confirmUpload({ accessKey, secretKey, url, }) {
|
|
122
|
+
return await makeRequest({
|
|
123
|
+
path: '/confirm-upload',
|
|
124
|
+
accessKey,
|
|
125
|
+
secretKey,
|
|
126
|
+
body: {
|
|
127
|
+
url,
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
},
|
|
106
131
|
async deleteFile({ accessKey, secretKey, url, }) {
|
|
107
132
|
return await makeRequest({
|
|
108
133
|
path: '/delete-file',
|
|
@@ -165,6 +190,22 @@ function initEdgeStoreSdk(params) {
|
|
|
165
190
|
multipart,
|
|
166
191
|
});
|
|
167
192
|
},
|
|
193
|
+
async completeMultipartUpload({ uploadId, key, parts, }) {
|
|
194
|
+
return await edgeStoreRawSdk.completeMultipartUpload({
|
|
195
|
+
accessKey,
|
|
196
|
+
secretKey,
|
|
197
|
+
uploadId,
|
|
198
|
+
key,
|
|
199
|
+
parts,
|
|
200
|
+
});
|
|
201
|
+
},
|
|
202
|
+
async confirmUpload({ url }) {
|
|
203
|
+
return await edgeStoreRawSdk.confirmUpload({
|
|
204
|
+
accessKey,
|
|
205
|
+
secretKey,
|
|
206
|
+
url,
|
|
207
|
+
});
|
|
208
|
+
},
|
|
168
209
|
async deleteFile({ url }) {
|
|
169
210
|
return await edgeStoreRawSdk.deleteFile({
|
|
170
211
|
accessKey,
|
|
@@ -1,9 +1,36 @@
|
|
|
1
|
-
import { Provider } from '../types';
|
|
1
|
+
import { type Provider } from '../types';
|
|
2
2
|
export type AWSProviderOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* Access key for AWS credentials.
|
|
5
|
+
* Can also be set via the `ES_AWS_ACCESS_KEY_ID` environment variable.
|
|
6
|
+
*
|
|
7
|
+
* If unset, the SDK will attempt to use the default credentials provider chain.
|
|
8
|
+
*/
|
|
3
9
|
accessKeyId?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Secret access key for AWS credentials.
|
|
12
|
+
* Can also be set via the `ES_AWS_SECRET_ACCESS_KEY` environment variable.
|
|
13
|
+
*
|
|
14
|
+
* If unset, the SDK will attempt to use the default credentials provider chain.
|
|
15
|
+
*/
|
|
4
16
|
secretAccessKey?: string;
|
|
17
|
+
/**
|
|
18
|
+
* AWS region to use.
|
|
19
|
+
* Can also be set via the `ES_AWS_REGION` environment variable.
|
|
20
|
+
*/
|
|
5
21
|
region?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Name of the S3 bucket to use.
|
|
24
|
+
* Can also be set via the `ES_AWS_BUCKET_NAME` environment variable.
|
|
25
|
+
*/
|
|
6
26
|
bucketName?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Base URL to use for accessing files.
|
|
29
|
+
* Only needed if you are using a custom domain or cloudfront.
|
|
30
|
+
*
|
|
31
|
+
* Can also be set via the `EDGE_STORE_BASE_URL` environment variable.
|
|
32
|
+
*/
|
|
33
|
+
baseUrl?: string;
|
|
7
34
|
};
|
|
8
35
|
export declare function AWSProvider(options?: AWSProviderOptions): Provider;
|
|
9
36
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/aws/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/aws/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;OAKG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,QAAQ,CAkGlE"}
|
|
@@ -8,6 +8,7 @@ var uuid = require('uuid');
|
|
|
8
8
|
|
|
9
9
|
function AWSProvider(options) {
|
|
10
10
|
const { accessKeyId = process.env.ES_AWS_ACCESS_KEY_ID, secretAccessKey = process.env.ES_AWS_SECRET_ACCESS_KEY, region = process.env.ES_AWS_REGION, bucketName = process.env.ES_AWS_BUCKET_NAME } = options ?? {};
|
|
11
|
+
const baseUrl = options?.baseUrl ?? process.env.EDGE_STORE_BASE_URL ?? `https://${bucketName}.s3.${region}.amazonaws.com`;
|
|
11
12
|
const credentials = accessKeyId && secretAccessKey ? {
|
|
12
13
|
accessKeyId,
|
|
13
14
|
secretAccessKey
|
|
@@ -16,7 +17,6 @@ function AWSProvider(options) {
|
|
|
16
17
|
region,
|
|
17
18
|
credentials
|
|
18
19
|
});
|
|
19
|
-
const baseUrl = process.env.EDGE_STORE_BASE_URL ?? `https://${bucketName}.s3.${region}.amazonaws.com`;
|
|
20
20
|
return {
|
|
21
21
|
async init () {
|
|
22
22
|
return {};
|
|
@@ -65,6 +65,12 @@ function AWSProvider(options) {
|
|
|
65
65
|
async requestUploadParts () {
|
|
66
66
|
throw new Error('Not implemented');
|
|
67
67
|
},
|
|
68
|
+
async completeMultipartUpload () {
|
|
69
|
+
throw new Error('Not implemented');
|
|
70
|
+
},
|
|
71
|
+
async confirmUpload () {
|
|
72
|
+
throw new Error('Not implemented');
|
|
73
|
+
},
|
|
68
74
|
async deleteFile ({ url }) {
|
|
69
75
|
const path = url.replace(`${baseUrl}/`, '');
|
|
70
76
|
await s3Client.send(new clientS3.DeleteObjectCommand({
|
|
@@ -4,6 +4,7 @@ import { v4 } from 'uuid';
|
|
|
4
4
|
|
|
5
5
|
function AWSProvider(options) {
|
|
6
6
|
const { accessKeyId = process.env.ES_AWS_ACCESS_KEY_ID, secretAccessKey = process.env.ES_AWS_SECRET_ACCESS_KEY, region = process.env.ES_AWS_REGION, bucketName = process.env.ES_AWS_BUCKET_NAME } = options ?? {};
|
|
7
|
+
const baseUrl = options?.baseUrl ?? process.env.EDGE_STORE_BASE_URL ?? `https://${bucketName}.s3.${region}.amazonaws.com`;
|
|
7
8
|
const credentials = accessKeyId && secretAccessKey ? {
|
|
8
9
|
accessKeyId,
|
|
9
10
|
secretAccessKey
|
|
@@ -12,7 +13,6 @@ function AWSProvider(options) {
|
|
|
12
13
|
region,
|
|
13
14
|
credentials
|
|
14
15
|
});
|
|
15
|
-
const baseUrl = process.env.EDGE_STORE_BASE_URL ?? `https://${bucketName}.s3.${region}.amazonaws.com`;
|
|
16
16
|
return {
|
|
17
17
|
async init () {
|
|
18
18
|
return {};
|
|
@@ -61,6 +61,12 @@ function AWSProvider(options) {
|
|
|
61
61
|
async requestUploadParts () {
|
|
62
62
|
throw new Error('Not implemented');
|
|
63
63
|
},
|
|
64
|
+
async completeMultipartUpload () {
|
|
65
|
+
throw new Error('Not implemented');
|
|
66
|
+
},
|
|
67
|
+
async confirmUpload () {
|
|
68
|
+
throw new Error('Not implemented');
|
|
69
|
+
},
|
|
64
70
|
async deleteFile ({ url }) {
|
|
65
71
|
const path = url.replace(`${baseUrl}/`, '');
|
|
66
72
|
await s3Client.send(new DeleteObjectCommand({
|
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
import { Provider } from '../types';
|
|
1
|
+
import { type Provider } from '../types';
|
|
2
2
|
export type EdgeStoreProviderOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* Access key for your EdgeStore project.
|
|
5
|
+
* Can be found in the EdgeStore dashboard.
|
|
6
|
+
*
|
|
7
|
+
* This can be omitted if the `EDGE_STORE_ACCESS_KEY` environment variable is set.
|
|
8
|
+
*/
|
|
3
9
|
accessKey?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Secret key for your EdgeStore project.
|
|
12
|
+
* Can be found in the EdgeStore dashboard.
|
|
13
|
+
*
|
|
14
|
+
* This can be omitted if the `EDGE_STORE_SECRET_KEY` environment variable is set.
|
|
15
|
+
*/
|
|
4
16
|
secretKey?: string;
|
|
5
17
|
};
|
|
6
18
|
export declare function EdgeStoreProvider(options?: EdgeStoreProviderOptions): Provider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/edgestore/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/edgestore/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,QAAQ,EAAyB,MAAM,UAAU,CAAC;AAIhE,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,OAAO,CAAC,EAAE,wBAAwB,GACjC,QAAQ,CA0IV"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('../../index-
|
|
5
|
+
var index = require('../../index-50ab9e08.js');
|
|
6
6
|
|
|
7
7
|
const DEFAULT_BASE_URL = 'https://files.edgestore.dev';
|
|
8
8
|
function EdgeStoreProvider(options) {
|
|
@@ -38,29 +38,28 @@ function EdgeStoreProvider(options) {
|
|
|
38
38
|
};
|
|
39
39
|
},
|
|
40
40
|
async requestUpload ({ bucketName, bucketType, fileInfo }) {
|
|
41
|
-
//
|
|
41
|
+
// multipart upload if file is bigger than a certain size
|
|
42
42
|
const MULTIPART_THRESHOLD = 10 * 1024 * 1024; // 10MB
|
|
43
|
-
const CONCURRENCY = 3;
|
|
44
43
|
let partSize = 5 * 1024 * 1024; // 5MB
|
|
45
44
|
if (fileInfo.size > MULTIPART_THRESHOLD) {
|
|
46
45
|
let totalParts = Math.ceil(fileInfo.size / partSize);
|
|
47
|
-
if (totalParts >
|
|
48
|
-
// the maximum number of parts is
|
|
49
|
-
totalParts =
|
|
46
|
+
if (totalParts > 1000) {
|
|
47
|
+
// the maximum number of parts is 1000
|
|
48
|
+
totalParts = 1000;
|
|
50
49
|
partSize = Math.ceil(fileInfo.size / totalParts);
|
|
51
50
|
}
|
|
52
|
-
const requestParts = totalParts > CONCURRENCY ? CONCURRENCY : totalParts;
|
|
53
51
|
const res = await edgeStoreSdk.requestUpload({
|
|
54
52
|
bucketName,
|
|
55
53
|
bucketType,
|
|
56
54
|
fileInfo,
|
|
57
55
|
multipart: {
|
|
58
56
|
parts: Array.from({
|
|
59
|
-
length:
|
|
57
|
+
length: totalParts
|
|
60
58
|
}).map((_, index)=>index + 1)
|
|
61
59
|
}
|
|
62
60
|
});
|
|
63
61
|
const multipart = res.multipart ? {
|
|
62
|
+
key: res.multipart.key,
|
|
64
63
|
uploadId: res.multipart.uploadId,
|
|
65
64
|
parts: res.multipart.parts.map((part)=>({
|
|
66
65
|
partNumber: part.partNumber,
|
|
@@ -72,12 +71,14 @@ function EdgeStoreProvider(options) {
|
|
|
72
71
|
if (multipart) {
|
|
73
72
|
return {
|
|
74
73
|
accessUrl: res.accessUrl,
|
|
74
|
+
thumbnailUrl: res.thumbnailUrl,
|
|
75
75
|
multipart
|
|
76
76
|
};
|
|
77
77
|
} else if (res.signedUrl) {
|
|
78
78
|
return {
|
|
79
79
|
accessUrl: res.accessUrl,
|
|
80
|
-
uploadUrl: res.signedUrl
|
|
80
|
+
uploadUrl: res.signedUrl,
|
|
81
|
+
thumbnailUrl: res.thumbnailUrl
|
|
81
82
|
};
|
|
82
83
|
} else {
|
|
83
84
|
throw new Error('Could not get upload url');
|
|
@@ -91,7 +92,8 @@ function EdgeStoreProvider(options) {
|
|
|
91
92
|
if (res.signedUrl) {
|
|
92
93
|
return {
|
|
93
94
|
accessUrl: res.accessUrl,
|
|
94
|
-
uploadUrl: res.signedUrl
|
|
95
|
+
uploadUrl: res.signedUrl,
|
|
96
|
+
thumbnailUrl: res.thumbnailUrl
|
|
95
97
|
};
|
|
96
98
|
}
|
|
97
99
|
throw new Error('Could not get upload url');
|
|
@@ -111,6 +113,18 @@ function EdgeStoreProvider(options) {
|
|
|
111
113
|
}
|
|
112
114
|
};
|
|
113
115
|
},
|
|
116
|
+
completeMultipartUpload: async ({ uploadId, key, parts })=>{
|
|
117
|
+
return await edgeStoreSdk.completeMultipartUpload({
|
|
118
|
+
uploadId,
|
|
119
|
+
key,
|
|
120
|
+
parts
|
|
121
|
+
});
|
|
122
|
+
},
|
|
123
|
+
confirmUpload: async ({ url })=>{
|
|
124
|
+
return await edgeStoreSdk.confirmUpload({
|
|
125
|
+
url
|
|
126
|
+
});
|
|
127
|
+
},
|
|
114
128
|
deleteFile: async ({ url })=>{
|
|
115
129
|
return await edgeStoreSdk.deleteFile({
|
|
116
130
|
url
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E as EdgeStoreCredentialsError, i as initEdgeStoreSdk } from '../../index-
|
|
1
|
+
import { E as EdgeStoreCredentialsError, i as initEdgeStoreSdk } from '../../index-30a3741e.mjs';
|
|
2
2
|
|
|
3
3
|
const DEFAULT_BASE_URL = 'https://files.edgestore.dev';
|
|
4
4
|
function EdgeStoreProvider(options) {
|
|
@@ -34,29 +34,28 @@ function EdgeStoreProvider(options) {
|
|
|
34
34
|
};
|
|
35
35
|
},
|
|
36
36
|
async requestUpload ({ bucketName, bucketType, fileInfo }) {
|
|
37
|
-
//
|
|
37
|
+
// multipart upload if file is bigger than a certain size
|
|
38
38
|
const MULTIPART_THRESHOLD = 10 * 1024 * 1024; // 10MB
|
|
39
|
-
const CONCURRENCY = 3;
|
|
40
39
|
let partSize = 5 * 1024 * 1024; // 5MB
|
|
41
40
|
if (fileInfo.size > MULTIPART_THRESHOLD) {
|
|
42
41
|
let totalParts = Math.ceil(fileInfo.size / partSize);
|
|
43
|
-
if (totalParts >
|
|
44
|
-
// the maximum number of parts is
|
|
45
|
-
totalParts =
|
|
42
|
+
if (totalParts > 1000) {
|
|
43
|
+
// the maximum number of parts is 1000
|
|
44
|
+
totalParts = 1000;
|
|
46
45
|
partSize = Math.ceil(fileInfo.size / totalParts);
|
|
47
46
|
}
|
|
48
|
-
const requestParts = totalParts > CONCURRENCY ? CONCURRENCY : totalParts;
|
|
49
47
|
const res = await edgeStoreSdk.requestUpload({
|
|
50
48
|
bucketName,
|
|
51
49
|
bucketType,
|
|
52
50
|
fileInfo,
|
|
53
51
|
multipart: {
|
|
54
52
|
parts: Array.from({
|
|
55
|
-
length:
|
|
53
|
+
length: totalParts
|
|
56
54
|
}).map((_, index)=>index + 1)
|
|
57
55
|
}
|
|
58
56
|
});
|
|
59
57
|
const multipart = res.multipart ? {
|
|
58
|
+
key: res.multipart.key,
|
|
60
59
|
uploadId: res.multipart.uploadId,
|
|
61
60
|
parts: res.multipart.parts.map((part)=>({
|
|
62
61
|
partNumber: part.partNumber,
|
|
@@ -68,12 +67,14 @@ function EdgeStoreProvider(options) {
|
|
|
68
67
|
if (multipart) {
|
|
69
68
|
return {
|
|
70
69
|
accessUrl: res.accessUrl,
|
|
70
|
+
thumbnailUrl: res.thumbnailUrl,
|
|
71
71
|
multipart
|
|
72
72
|
};
|
|
73
73
|
} else if (res.signedUrl) {
|
|
74
74
|
return {
|
|
75
75
|
accessUrl: res.accessUrl,
|
|
76
|
-
uploadUrl: res.signedUrl
|
|
76
|
+
uploadUrl: res.signedUrl,
|
|
77
|
+
thumbnailUrl: res.thumbnailUrl
|
|
77
78
|
};
|
|
78
79
|
} else {
|
|
79
80
|
throw new Error('Could not get upload url');
|
|
@@ -87,7 +88,8 @@ function EdgeStoreProvider(options) {
|
|
|
87
88
|
if (res.signedUrl) {
|
|
88
89
|
return {
|
|
89
90
|
accessUrl: res.accessUrl,
|
|
90
|
-
uploadUrl: res.signedUrl
|
|
91
|
+
uploadUrl: res.signedUrl,
|
|
92
|
+
thumbnailUrl: res.thumbnailUrl
|
|
91
93
|
};
|
|
92
94
|
}
|
|
93
95
|
throw new Error('Could not get upload url');
|
|
@@ -107,6 +109,18 @@ function EdgeStoreProvider(options) {
|
|
|
107
109
|
}
|
|
108
110
|
};
|
|
109
111
|
},
|
|
112
|
+
completeMultipartUpload: async ({ uploadId, key, parts })=>{
|
|
113
|
+
return await edgeStoreSdk.completeMultipartUpload({
|
|
114
|
+
uploadId,
|
|
115
|
+
key,
|
|
116
|
+
parts
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
confirmUpload: async ({ url })=>{
|
|
120
|
+
return await edgeStoreSdk.confirmUpload({
|
|
121
|
+
url
|
|
122
|
+
});
|
|
123
|
+
},
|
|
110
124
|
deleteFile: async ({ url })=>{
|
|
111
125
|
return await edgeStoreSdk.deleteFile({
|
|
112
126
|
url
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AnyBuilder, AnyMetadata, EdgeStoreRouter } from '../core/internals/bucketBuilder';
|
|
2
|
-
import { MaybePromise } from '../types';
|
|
1
|
+
import { type AnyBuilder, type AnyMetadata, type EdgeStoreRouter } from '../core/internals/bucketBuilder';
|
|
2
|
+
import { type MaybePromise } from '../types';
|
|
3
3
|
export type InitParams = {
|
|
4
4
|
ctx: any;
|
|
5
5
|
router: EdgeStoreRouter<any>;
|
|
@@ -38,6 +38,7 @@ export type RequestUploadParams = {
|
|
|
38
38
|
}[];
|
|
39
39
|
metadata: AnyMetadata;
|
|
40
40
|
replaceTargetUrl?: string;
|
|
41
|
+
temporary: boolean;
|
|
41
42
|
};
|
|
42
43
|
};
|
|
43
44
|
export type RequestUploadPartsParams = {
|
|
@@ -56,11 +57,24 @@ export type RequestUploadPartsRes = {
|
|
|
56
57
|
}[];
|
|
57
58
|
};
|
|
58
59
|
};
|
|
60
|
+
export type CompleteMultipartUploadParams = {
|
|
61
|
+
uploadId: string;
|
|
62
|
+
key: string;
|
|
63
|
+
parts: {
|
|
64
|
+
partNumber: number;
|
|
65
|
+
eTag: string;
|
|
66
|
+
}[];
|
|
67
|
+
};
|
|
68
|
+
export type CompleteMultipartUploadRes = {
|
|
69
|
+
success: boolean;
|
|
70
|
+
};
|
|
59
71
|
export type RequestUploadRes = {
|
|
60
72
|
uploadUrl: string;
|
|
61
73
|
accessUrl: string;
|
|
74
|
+
thumbnailUrl?: string | null;
|
|
62
75
|
} | {
|
|
63
76
|
multipart: {
|
|
77
|
+
key: string;
|
|
64
78
|
uploadId: string;
|
|
65
79
|
partSize: number;
|
|
66
80
|
totalParts: number;
|
|
@@ -70,6 +84,14 @@ export type RequestUploadRes = {
|
|
|
70
84
|
}[];
|
|
71
85
|
};
|
|
72
86
|
accessUrl: string;
|
|
87
|
+
thumbnailUrl?: string | null;
|
|
88
|
+
};
|
|
89
|
+
export type ConfirmUpload = {
|
|
90
|
+
bucket: AnyBuilder;
|
|
91
|
+
url: string;
|
|
92
|
+
};
|
|
93
|
+
export type ConfirmUploadRes = {
|
|
94
|
+
success: boolean;
|
|
73
95
|
};
|
|
74
96
|
export type DeleteFileParams = {
|
|
75
97
|
bucket: AnyBuilder;
|
|
@@ -84,6 +106,8 @@ export type Provider = {
|
|
|
84
106
|
getFile: (params: GetFileParams) => MaybePromise<GetFileRes>;
|
|
85
107
|
requestUpload: (params: RequestUploadParams) => MaybePromise<RequestUploadRes>;
|
|
86
108
|
requestUploadParts: (params: RequestUploadPartsParams) => MaybePromise<RequestUploadPartsRes>;
|
|
109
|
+
completeMultipartUpload: (params: CompleteMultipartUploadParams) => MaybePromise<CompleteMultipartUploadRes>;
|
|
110
|
+
confirmUpload: (params: ConfirmUpload) => MaybePromise<ConfirmUploadRes>;
|
|
87
111
|
deleteFile: (params: DeleteFileParams) => MaybePromise<DeleteFileRes>;
|
|
88
112
|
};
|
|
89
113
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/providers/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/providers/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,eAAe,EACrB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,MAAM,MAAM,UAAU,GAAG;IACvB,GAAG,EAAE,GAAG,CAAC;IACT,MAAM,EAAE,eAAe,CAAC,GAAG,CAAC,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,IAAI,CAAC;IACjB,IAAI,EAAE;QACJ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;KACvB,CAAC;IACF,QAAQ,EAAE;QACR,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;KACvB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,SAAS,CAAC,EAAE;QACV,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,KAAK,EAAE,MAAM,EAAE,CAAC;KACjB,CAAC;IACF,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QAC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load(params) {
|
|
|
80
80
|
type: fileInfo.type,
|
|
81
81
|
fileName: fileInfo.fileName,
|
|
82
82
|
extension: fileInfo.extension,
|
|
83
|
-
replaceTargetUrl: fileInfo.replaceTargetUrl
|
|
83
|
+
replaceTargetUrl: fileInfo.replaceTargetUrl,
|
|
84
|
+
temporary: fileInfo.temporary
|
|
84
85
|
}
|
|
85
86
|
});
|
|
86
87
|
if (!canUpload) {
|
|
@@ -174,6 +175,43 @@ async function requestUploadParts(params) {
|
|
|
174
175
|
path
|
|
175
176
|
});
|
|
176
177
|
}
|
|
178
|
+
async function completeMultipartUpload(params) {
|
|
179
|
+
const { provider, router, ctxToken, body: { bucketName, uploadId, key, parts } } = params;
|
|
180
|
+
if (!ctxToken) {
|
|
181
|
+
throw new EdgeStoreError({
|
|
182
|
+
message: 'Missing edgestore-ctx cookie',
|
|
183
|
+
code: 'UNAUTHORIZED'
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
await getContext(ctxToken); // just to check if the token is valid
|
|
187
|
+
const bucket = router.buckets[bucketName];
|
|
188
|
+
if (!bucket) {
|
|
189
|
+
throw new Error(`Bucket ${bucketName} not found`);
|
|
190
|
+
}
|
|
191
|
+
return await provider.completeMultipartUpload({
|
|
192
|
+
uploadId,
|
|
193
|
+
key,
|
|
194
|
+
parts
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
async function confirmUpload(params) {
|
|
198
|
+
const { provider, router, ctxToken, body: { bucketName, url } } = params;
|
|
199
|
+
if (!ctxToken) {
|
|
200
|
+
throw new EdgeStoreError({
|
|
201
|
+
message: 'Missing edgestore-ctx cookie',
|
|
202
|
+
code: 'UNAUTHORIZED'
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
await getContext(ctxToken); // just to check if the token is valid
|
|
206
|
+
const bucket = router.buckets[bucketName];
|
|
207
|
+
if (!bucket) {
|
|
208
|
+
throw new Error(`Bucket ${bucketName} not found`);
|
|
209
|
+
}
|
|
210
|
+
await provider.confirmUpload({
|
|
211
|
+
bucket,
|
|
212
|
+
url
|
|
213
|
+
});
|
|
214
|
+
}
|
|
177
215
|
async function deleteFile(params) {
|
|
178
216
|
const { provider, router, ctxToken, body: { bucketName, url } } = params;
|
|
179
217
|
if (!ctxToken) {
|
|
@@ -260,4 +298,4 @@ async function getContext(token) {
|
|
|
260
298
|
return await decryptJWT(token);
|
|
261
299
|
}
|
|
262
300
|
|
|
263
|
-
export { EdgeStoreError as E, requestUploadParts as a,
|
|
301
|
+
export { EdgeStoreError as E, requestUploadParts as a, confirmUpload as b, completeMultipartUpload as c, deleteFile as d, EDGE_STORE_ERROR_CODES as e, init as i, requestUpload as r };
|