@edgestore/server 0.1.3 → 0.1.5-alpha.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/dist/adapters/next/app/index.d.ts.map +1 -1
- package/dist/adapters/next/app/index.js +7 -7
- package/dist/adapters/next/app/index.mjs +7 -7
- package/dist/adapters/next/pages/index.js +7 -7
- package/dist/adapters/next/pages/index.mjs +7 -7
- package/dist/providers/aws/index.d.ts +7 -0
- package/dist/providers/aws/index.d.ts.map +1 -1
- package/dist/providers/aws/index.js +5 -4
- package/dist/providers/aws/index.mjs +5 -4
- package/package.json +17 -4
- package/src/adapters/next/app/index.ts +7 -11
- package/src/adapters/next/pages/index.ts +7 -7
- package/src/providers/aws/index.ts +14 -4
- package/adapters/next/index.d.ts +0 -1
- package/adapters/next/index.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/adapters/next/app/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAK7E,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAenD,MAAM,MAAM,oBAAoB,GAAG;IACjC,GAAG,EAAE,WAAW,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,MAAM,CAAC,IAAI,IAAI,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GACzD;IACE,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC;CAC/B,GACD;IACE,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC;IAC9B,aAAa,EAAE,CAAC,IAAI,EAAE,oBAAoB,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC;CACnE,CAAC;AAEN,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,SAEhD,WAAW,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/adapters/next/app/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAK7E,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAenD,MAAM,MAAM,oBAAoB,GAAG;IACjC,GAAG,EAAE,WAAW,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,MAAM,CAAC,IAAI,IAAI,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GACzD;IACE,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC;CAC/B,GACD;IACE,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC;IAC9B,aAAa,EAAE,CAAC,IAAI,EAAE,oBAAoB,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC;CACnE,CAAC;AAEN,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,SAEhD,WAAW,uBAqI/B"}
|
|
@@ -15,7 +15,7 @@ function createEdgeStoreNextHandler(config) {
|
|
|
15
15
|
const { provider = providers_edgestore_index.EdgeStoreProvider() } = config;
|
|
16
16
|
return async (req)=>{
|
|
17
17
|
try {
|
|
18
|
-
if (req.nextUrl.pathname
|
|
18
|
+
if (req.nextUrl.pathname.endsWith('/init')) {
|
|
19
19
|
const ctx = 'createContext' in config ? await config.createContext({
|
|
20
20
|
req
|
|
21
21
|
}) : {};
|
|
@@ -37,7 +37,7 @@ function createEdgeStoreNextHandler(config) {
|
|
|
37
37
|
res.headers.append('Set-Cookie', cookie);
|
|
38
38
|
}
|
|
39
39
|
return res;
|
|
40
|
-
} else if (req.nextUrl.pathname
|
|
40
|
+
} else if (req.nextUrl.pathname.endsWith('/request-upload')) {
|
|
41
41
|
const res = await shared.requestUpload({
|
|
42
42
|
provider,
|
|
43
43
|
router: config.router,
|
|
@@ -50,7 +50,7 @@ function createEdgeStoreNextHandler(config) {
|
|
|
50
50
|
'Content-Type': 'application/json'
|
|
51
51
|
}
|
|
52
52
|
});
|
|
53
|
-
} else if (req.nextUrl.pathname
|
|
53
|
+
} else if (req.nextUrl.pathname.endsWith('/request-upload-parts')) {
|
|
54
54
|
const res = await shared.requestUploadParts({
|
|
55
55
|
provider,
|
|
56
56
|
router: config.router,
|
|
@@ -63,7 +63,7 @@ function createEdgeStoreNextHandler(config) {
|
|
|
63
63
|
'Content-Type': 'application/json'
|
|
64
64
|
}
|
|
65
65
|
});
|
|
66
|
-
} else if (req.nextUrl.pathname
|
|
66
|
+
} else if (req.nextUrl.pathname.endsWith('/complete-multipart-upload')) {
|
|
67
67
|
await shared.completeMultipartUpload({
|
|
68
68
|
provider,
|
|
69
69
|
router: config.router,
|
|
@@ -73,7 +73,7 @@ function createEdgeStoreNextHandler(config) {
|
|
|
73
73
|
return new Response(null, {
|
|
74
74
|
status: 200
|
|
75
75
|
});
|
|
76
|
-
} else if (req.nextUrl.pathname
|
|
76
|
+
} else if (req.nextUrl.pathname.endsWith('/confirm-upload')) {
|
|
77
77
|
const res = await shared.confirmUpload({
|
|
78
78
|
provider,
|
|
79
79
|
router: config.router,
|
|
@@ -86,7 +86,7 @@ function createEdgeStoreNextHandler(config) {
|
|
|
86
86
|
'Content-Type': 'application/json'
|
|
87
87
|
}
|
|
88
88
|
});
|
|
89
|
-
} else if (req.nextUrl.pathname
|
|
89
|
+
} else if (req.nextUrl.pathname.endsWith('/delete-file')) {
|
|
90
90
|
const res = await shared.deleteFile({
|
|
91
91
|
provider,
|
|
92
92
|
router: config.router,
|
|
@@ -99,7 +99,7 @@ function createEdgeStoreNextHandler(config) {
|
|
|
99
99
|
'Content-Type': 'application/json'
|
|
100
100
|
}
|
|
101
101
|
});
|
|
102
|
-
} else if (req.nextUrl.pathname
|
|
102
|
+
} else if (req.nextUrl.pathname.endsWith('/proxy-file')) {
|
|
103
103
|
const url = req.nextUrl.searchParams.get('url');
|
|
104
104
|
if (typeof url === 'string') {
|
|
105
105
|
const proxyRes = await fetch(url, {
|
|
@@ -11,7 +11,7 @@ function createEdgeStoreNextHandler(config) {
|
|
|
11
11
|
const { provider = EdgeStoreProvider() } = config;
|
|
12
12
|
return async (req)=>{
|
|
13
13
|
try {
|
|
14
|
-
if (req.nextUrl.pathname
|
|
14
|
+
if (req.nextUrl.pathname.endsWith('/init')) {
|
|
15
15
|
const ctx = 'createContext' in config ? await config.createContext({
|
|
16
16
|
req
|
|
17
17
|
}) : {};
|
|
@@ -33,7 +33,7 @@ function createEdgeStoreNextHandler(config) {
|
|
|
33
33
|
res.headers.append('Set-Cookie', cookie);
|
|
34
34
|
}
|
|
35
35
|
return res;
|
|
36
|
-
} else if (req.nextUrl.pathname
|
|
36
|
+
} else if (req.nextUrl.pathname.endsWith('/request-upload')) {
|
|
37
37
|
const res = await requestUpload({
|
|
38
38
|
provider,
|
|
39
39
|
router: config.router,
|
|
@@ -46,7 +46,7 @@ function createEdgeStoreNextHandler(config) {
|
|
|
46
46
|
'Content-Type': 'application/json'
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
|
-
} else if (req.nextUrl.pathname
|
|
49
|
+
} else if (req.nextUrl.pathname.endsWith('/request-upload-parts')) {
|
|
50
50
|
const res = await requestUploadParts({
|
|
51
51
|
provider,
|
|
52
52
|
router: config.router,
|
|
@@ -59,7 +59,7 @@ function createEdgeStoreNextHandler(config) {
|
|
|
59
59
|
'Content-Type': 'application/json'
|
|
60
60
|
}
|
|
61
61
|
});
|
|
62
|
-
} else if (req.nextUrl.pathname
|
|
62
|
+
} else if (req.nextUrl.pathname.endsWith('/complete-multipart-upload')) {
|
|
63
63
|
await completeMultipartUpload({
|
|
64
64
|
provider,
|
|
65
65
|
router: config.router,
|
|
@@ -69,7 +69,7 @@ function createEdgeStoreNextHandler(config) {
|
|
|
69
69
|
return new Response(null, {
|
|
70
70
|
status: 200
|
|
71
71
|
});
|
|
72
|
-
} else if (req.nextUrl.pathname
|
|
72
|
+
} else if (req.nextUrl.pathname.endsWith('/confirm-upload')) {
|
|
73
73
|
const res = await confirmUpload({
|
|
74
74
|
provider,
|
|
75
75
|
router: config.router,
|
|
@@ -82,7 +82,7 @@ function createEdgeStoreNextHandler(config) {
|
|
|
82
82
|
'Content-Type': 'application/json'
|
|
83
83
|
}
|
|
84
84
|
});
|
|
85
|
-
} else if (req.nextUrl.pathname
|
|
85
|
+
} else if (req.nextUrl.pathname.endsWith('/delete-file')) {
|
|
86
86
|
const res = await deleteFile({
|
|
87
87
|
provider,
|
|
88
88
|
router: config.router,
|
|
@@ -95,7 +95,7 @@ function createEdgeStoreNextHandler(config) {
|
|
|
95
95
|
'Content-Type': 'application/json'
|
|
96
96
|
}
|
|
97
97
|
});
|
|
98
|
-
} else if (req.nextUrl.pathname
|
|
98
|
+
} else if (req.nextUrl.pathname.endsWith('/proxy-file')) {
|
|
99
99
|
const url = req.nextUrl.searchParams.get('url');
|
|
100
100
|
if (typeof url === 'string') {
|
|
101
101
|
const proxyRes = await fetch(url, {
|
|
@@ -15,7 +15,7 @@ function createEdgeStoreNextHandler(config) {
|
|
|
15
15
|
const { provider = providers_edgestore_index.EdgeStoreProvider() } = config;
|
|
16
16
|
return async (req, res)=>{
|
|
17
17
|
try {
|
|
18
|
-
if (req.url
|
|
18
|
+
if (req.url?.includes?.('/init')) {
|
|
19
19
|
const ctx = 'createContext' in config ? await config.createContext({
|
|
20
20
|
req,
|
|
21
21
|
res
|
|
@@ -30,21 +30,21 @@ function createEdgeStoreNextHandler(config) {
|
|
|
30
30
|
token,
|
|
31
31
|
baseUrl
|
|
32
32
|
});
|
|
33
|
-
} else if (req.url
|
|
33
|
+
} else if (req.url?.includes?.('/request-upload')) {
|
|
34
34
|
res.json(await shared.requestUpload({
|
|
35
35
|
provider,
|
|
36
36
|
router: config.router,
|
|
37
37
|
body: req.body,
|
|
38
38
|
ctxToken: req.cookies['edgestore-ctx']
|
|
39
39
|
}));
|
|
40
|
-
} else if (req.url
|
|
40
|
+
} else if (req.url?.includes?.('/request-upload-parts')) {
|
|
41
41
|
res.json(await shared.requestUploadParts({
|
|
42
42
|
provider,
|
|
43
43
|
router: config.router,
|
|
44
44
|
body: req.body,
|
|
45
45
|
ctxToken: req.cookies['edgestore-ctx']
|
|
46
46
|
}));
|
|
47
|
-
} else if (req.url
|
|
47
|
+
} else if (req.url?.includes?.('/complete-multipart-upload')) {
|
|
48
48
|
await shared.completeMultipartUpload({
|
|
49
49
|
provider,
|
|
50
50
|
router: config.router,
|
|
@@ -52,21 +52,21 @@ function createEdgeStoreNextHandler(config) {
|
|
|
52
52
|
ctxToken: req.cookies['edgestore-ctx']
|
|
53
53
|
});
|
|
54
54
|
res.status(200).end();
|
|
55
|
-
} else if (req.url
|
|
55
|
+
} else if (req.url?.includes?.('/confirm-upload')) {
|
|
56
56
|
res.json(await shared.confirmUpload({
|
|
57
57
|
provider,
|
|
58
58
|
router: config.router,
|
|
59
59
|
body: req.body,
|
|
60
60
|
ctxToken: req.cookies['edgestore-ctx']
|
|
61
61
|
}));
|
|
62
|
-
} else if (req.url
|
|
62
|
+
} else if (req.url?.includes?.('/delete-file')) {
|
|
63
63
|
res.json(await shared.deleteFile({
|
|
64
64
|
provider,
|
|
65
65
|
router: config.router,
|
|
66
66
|
body: req.body,
|
|
67
67
|
ctxToken: req.cookies['edgestore-ctx']
|
|
68
68
|
}));
|
|
69
|
-
} else if (req.url?.
|
|
69
|
+
} else if (req.url?.includes?.('/proxy-file')) {
|
|
70
70
|
const { url } = req.query;
|
|
71
71
|
if (typeof url === 'string') {
|
|
72
72
|
const proxyRes = await fetch(url, {
|
|
@@ -11,7 +11,7 @@ function createEdgeStoreNextHandler(config) {
|
|
|
11
11
|
const { provider = EdgeStoreProvider() } = config;
|
|
12
12
|
return async (req, res)=>{
|
|
13
13
|
try {
|
|
14
|
-
if (req.url
|
|
14
|
+
if (req.url?.includes?.('/init')) {
|
|
15
15
|
const ctx = 'createContext' in config ? await config.createContext({
|
|
16
16
|
req,
|
|
17
17
|
res
|
|
@@ -26,21 +26,21 @@ function createEdgeStoreNextHandler(config) {
|
|
|
26
26
|
token,
|
|
27
27
|
baseUrl
|
|
28
28
|
});
|
|
29
|
-
} else if (req.url
|
|
29
|
+
} else if (req.url?.includes?.('/request-upload')) {
|
|
30
30
|
res.json(await requestUpload({
|
|
31
31
|
provider,
|
|
32
32
|
router: config.router,
|
|
33
33
|
body: req.body,
|
|
34
34
|
ctxToken: req.cookies['edgestore-ctx']
|
|
35
35
|
}));
|
|
36
|
-
} else if (req.url
|
|
36
|
+
} else if (req.url?.includes?.('/request-upload-parts')) {
|
|
37
37
|
res.json(await requestUploadParts({
|
|
38
38
|
provider,
|
|
39
39
|
router: config.router,
|
|
40
40
|
body: req.body,
|
|
41
41
|
ctxToken: req.cookies['edgestore-ctx']
|
|
42
42
|
}));
|
|
43
|
-
} else if (req.url
|
|
43
|
+
} else if (req.url?.includes?.('/complete-multipart-upload')) {
|
|
44
44
|
await completeMultipartUpload({
|
|
45
45
|
provider,
|
|
46
46
|
router: config.router,
|
|
@@ -48,21 +48,21 @@ function createEdgeStoreNextHandler(config) {
|
|
|
48
48
|
ctxToken: req.cookies['edgestore-ctx']
|
|
49
49
|
});
|
|
50
50
|
res.status(200).end();
|
|
51
|
-
} else if (req.url
|
|
51
|
+
} else if (req.url?.includes?.('/confirm-upload')) {
|
|
52
52
|
res.json(await confirmUpload({
|
|
53
53
|
provider,
|
|
54
54
|
router: config.router,
|
|
55
55
|
body: req.body,
|
|
56
56
|
ctxToken: req.cookies['edgestore-ctx']
|
|
57
57
|
}));
|
|
58
|
-
} else if (req.url
|
|
58
|
+
} else if (req.url?.includes?.('/delete-file')) {
|
|
59
59
|
res.json(await deleteFile({
|
|
60
60
|
provider,
|
|
61
61
|
router: config.router,
|
|
62
62
|
body: req.body,
|
|
63
63
|
ctxToken: req.cookies['edgestore-ctx']
|
|
64
64
|
}));
|
|
65
|
-
} else if (req.url?.
|
|
65
|
+
} else if (req.url?.includes?.('/proxy-file')) {
|
|
66
66
|
const { url } = req.query;
|
|
67
67
|
if (typeof url === 'string') {
|
|
68
68
|
const proxyRes = await fetch(url, {
|
|
@@ -31,6 +31,13 @@ export type AWSProviderOptions = {
|
|
|
31
31
|
* Can also be set via the `EDGE_STORE_BASE_URL` environment variable.
|
|
32
32
|
*/
|
|
33
33
|
baseUrl?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Secret to use for encrypting JWT tokens.
|
|
36
|
+
* Can be generated with `openssl rand -base64 32`.
|
|
37
|
+
*
|
|
38
|
+
* Can also be set via the `EDGE_STORE_JWT_SECRET` environment variable.
|
|
39
|
+
*/
|
|
40
|
+
jwtSecret?: string;
|
|
34
41
|
};
|
|
35
42
|
export declare function AWSProvider(options?: AWSProviderOptions): Provider;
|
|
36
43
|
//# 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,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;
|
|
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;IACjB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,QAAQ,CAqGlE"}
|
|
@@ -41,22 +41,23 @@ function AWSProvider(options) {
|
|
|
41
41
|
uploadedAt: LastModified
|
|
42
42
|
};
|
|
43
43
|
},
|
|
44
|
-
async requestUpload ({ bucketName, fileInfo }) {
|
|
45
|
-
const pathPrefix = `${
|
|
44
|
+
async requestUpload ({ bucketName: esBucketName, fileInfo }) {
|
|
45
|
+
const pathPrefix = `${esBucketName}${fileInfo.isPublic ? '/_public' : ''}`;
|
|
46
46
|
const nameId = uuid.v4();
|
|
47
47
|
const extension = fileInfo.extension ? `.${fileInfo.extension.replace('.', '')}` : '';
|
|
48
48
|
const fileName = `${nameId}${extension}`;
|
|
49
49
|
const filePath = fileInfo.path.reduce((acc, item)=>{
|
|
50
50
|
return `${acc}/${item.value}`;
|
|
51
51
|
}, '');
|
|
52
|
+
const accessPath = `${pathPrefix}${filePath}/${fileName}`;
|
|
52
53
|
const command = new clientS3.PutObjectCommand({
|
|
53
54
|
Bucket: bucketName,
|
|
54
|
-
Key:
|
|
55
|
+
Key: accessPath
|
|
55
56
|
});
|
|
56
57
|
const signedUrl = await s3RequestPresigner.getSignedUrl(s3Client, command, {
|
|
57
58
|
expiresIn: 60 * 60
|
|
58
59
|
});
|
|
59
|
-
const url = `${baseUrl}/${
|
|
60
|
+
const url = `${baseUrl}/${accessPath}`;
|
|
60
61
|
return {
|
|
61
62
|
uploadUrl: signedUrl,
|
|
62
63
|
accessUrl: url
|
|
@@ -37,22 +37,23 @@ function AWSProvider(options) {
|
|
|
37
37
|
uploadedAt: LastModified
|
|
38
38
|
};
|
|
39
39
|
},
|
|
40
|
-
async requestUpload ({ bucketName, fileInfo }) {
|
|
41
|
-
const pathPrefix = `${
|
|
40
|
+
async requestUpload ({ bucketName: esBucketName, fileInfo }) {
|
|
41
|
+
const pathPrefix = `${esBucketName}${fileInfo.isPublic ? '/_public' : ''}`;
|
|
42
42
|
const nameId = v4();
|
|
43
43
|
const extension = fileInfo.extension ? `.${fileInfo.extension.replace('.', '')}` : '';
|
|
44
44
|
const fileName = `${nameId}${extension}`;
|
|
45
45
|
const filePath = fileInfo.path.reduce((acc, item)=>{
|
|
46
46
|
return `${acc}/${item.value}`;
|
|
47
47
|
}, '');
|
|
48
|
+
const accessPath = `${pathPrefix}${filePath}/${fileName}`;
|
|
48
49
|
const command = new PutObjectCommand({
|
|
49
50
|
Bucket: bucketName,
|
|
50
|
-
Key:
|
|
51
|
+
Key: accessPath
|
|
51
52
|
});
|
|
52
53
|
const signedUrl = await getSignedUrl(s3Client, command, {
|
|
53
54
|
expiresIn: 60 * 60
|
|
54
55
|
});
|
|
55
|
-
const url = `${baseUrl}/${
|
|
56
|
+
const url = `${baseUrl}/${accessPath}`;
|
|
56
57
|
return {
|
|
57
58
|
uploadUrl: signedUrl,
|
|
58
59
|
accessUrl: url
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edgestore/server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5-alpha.0",
|
|
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",
|
|
@@ -84,17 +84,30 @@
|
|
|
84
84
|
},
|
|
85
85
|
"license": "MIT",
|
|
86
86
|
"dependencies": {
|
|
87
|
-
"@aws-sdk/client-s3": "^3.294.0",
|
|
88
|
-
"@aws-sdk/s3-request-presigner": "^3.294.0",
|
|
89
87
|
"@panva/hkdf": "^1.0.4",
|
|
90
88
|
"cookie": "^0.5.0",
|
|
91
89
|
"jose": "^4.13.1",
|
|
92
90
|
"uuid": "^9.0.0"
|
|
93
91
|
},
|
|
94
92
|
"peerDependencies": {
|
|
93
|
+
"@aws-sdk/client-s3": ">=3.0.0",
|
|
94
|
+
"@aws-sdk/s3-request-presigner": ">=3.0.0",
|
|
95
95
|
"zod": ">=3.0.0"
|
|
96
96
|
},
|
|
97
|
+
"peerDependenciesMeta": {
|
|
98
|
+
"zod": {
|
|
99
|
+
"optional": true
|
|
100
|
+
},
|
|
101
|
+
"@aws-sdk/client-s3": {
|
|
102
|
+
"optional": true
|
|
103
|
+
},
|
|
104
|
+
"@aws-sdk/s3-request-presigner": {
|
|
105
|
+
"optional": true
|
|
106
|
+
}
|
|
107
|
+
},
|
|
97
108
|
"devDependencies": {
|
|
109
|
+
"@aws-sdk/client-s3": "^3.420.0",
|
|
110
|
+
"@aws-sdk/s3-request-presigner": "^3.420.0",
|
|
98
111
|
"@types/cookie": "^0.5.1",
|
|
99
112
|
"@types/node": "^18.11.18",
|
|
100
113
|
"@types/uuid": "^9.0.1",
|
|
@@ -104,5 +117,5 @@
|
|
|
104
117
|
"typescript": "^5.1.6",
|
|
105
118
|
"zod": "^3.21.4"
|
|
106
119
|
},
|
|
107
|
-
"gitHead": "
|
|
120
|
+
"gitHead": "bea31f57147499993eaf25c86f24c211dc86dd91"
|
|
108
121
|
}
|
|
@@ -39,7 +39,7 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
39
39
|
const { provider = EdgeStoreProvider() } = config;
|
|
40
40
|
return async (req: NextRequest) => {
|
|
41
41
|
try {
|
|
42
|
-
if (req.nextUrl.pathname
|
|
42
|
+
if (req.nextUrl.pathname.endsWith('/init')) {
|
|
43
43
|
const ctx =
|
|
44
44
|
'createContext' in config
|
|
45
45
|
? await config.createContext({ req })
|
|
@@ -65,7 +65,7 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
65
65
|
res.headers.append('Set-Cookie', cookie);
|
|
66
66
|
}
|
|
67
67
|
return res;
|
|
68
|
-
} else if (req.nextUrl.pathname
|
|
68
|
+
} else if (req.nextUrl.pathname.endsWith('/request-upload')) {
|
|
69
69
|
const res = await requestUpload({
|
|
70
70
|
provider,
|
|
71
71
|
router: config.router,
|
|
@@ -78,9 +78,7 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
78
78
|
'Content-Type': 'application/json',
|
|
79
79
|
},
|
|
80
80
|
});
|
|
81
|
-
} else if (
|
|
82
|
-
req.nextUrl.pathname === '/api/edgestore/request-upload-parts'
|
|
83
|
-
) {
|
|
81
|
+
} else if (req.nextUrl.pathname.endsWith('/request-upload-parts')) {
|
|
84
82
|
const res = await requestUploadParts({
|
|
85
83
|
provider,
|
|
86
84
|
router: config.router,
|
|
@@ -93,9 +91,7 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
93
91
|
'Content-Type': 'application/json',
|
|
94
92
|
},
|
|
95
93
|
});
|
|
96
|
-
} else if (
|
|
97
|
-
req.nextUrl.pathname === '/api/edgestore/complete-multipart-upload'
|
|
98
|
-
) {
|
|
94
|
+
} else if (req.nextUrl.pathname.endsWith('/complete-multipart-upload')) {
|
|
99
95
|
await completeMultipartUpload({
|
|
100
96
|
provider,
|
|
101
97
|
router: config.router,
|
|
@@ -105,7 +101,7 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
105
101
|
return new Response(null, {
|
|
106
102
|
status: 200,
|
|
107
103
|
});
|
|
108
|
-
} else if (req.nextUrl.pathname
|
|
104
|
+
} else if (req.nextUrl.pathname.endsWith('/confirm-upload')) {
|
|
109
105
|
const res = await confirmUpload({
|
|
110
106
|
provider,
|
|
111
107
|
router: config.router,
|
|
@@ -118,7 +114,7 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
118
114
|
'Content-Type': 'application/json',
|
|
119
115
|
},
|
|
120
116
|
});
|
|
121
|
-
} else if (req.nextUrl.pathname
|
|
117
|
+
} else if (req.nextUrl.pathname.endsWith('/delete-file')) {
|
|
122
118
|
const res = await deleteFile({
|
|
123
119
|
provider,
|
|
124
120
|
router: config.router,
|
|
@@ -131,7 +127,7 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
131
127
|
'Content-Type': 'application/json',
|
|
132
128
|
},
|
|
133
129
|
});
|
|
134
|
-
} else if (req.nextUrl.pathname
|
|
130
|
+
} else if (req.nextUrl.pathname.endsWith('/proxy-file')) {
|
|
135
131
|
const url = req.nextUrl.searchParams.get('url');
|
|
136
132
|
if (typeof url === 'string') {
|
|
137
133
|
const proxyRes = await fetch(url, {
|
|
@@ -40,7 +40,7 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
40
40
|
const { provider = EdgeStoreProvider() } = config;
|
|
41
41
|
return async (req: NextApiRequest, res: NextApiResponse) => {
|
|
42
42
|
try {
|
|
43
|
-
if (req.url
|
|
43
|
+
if (req.url?.includes?.('/init')) {
|
|
44
44
|
const ctx =
|
|
45
45
|
'createContext' in config
|
|
46
46
|
? await config.createContext({ req, res })
|
|
@@ -55,7 +55,7 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
55
55
|
token,
|
|
56
56
|
baseUrl,
|
|
57
57
|
});
|
|
58
|
-
} else if (req.url
|
|
58
|
+
} else if (req.url?.includes?.('/request-upload')) {
|
|
59
59
|
res.json(
|
|
60
60
|
await requestUpload({
|
|
61
61
|
provider,
|
|
@@ -64,7 +64,7 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
64
64
|
ctxToken: req.cookies['edgestore-ctx'],
|
|
65
65
|
}),
|
|
66
66
|
);
|
|
67
|
-
} else if (req.url
|
|
67
|
+
} else if (req.url?.includes?.('/request-upload-parts')) {
|
|
68
68
|
res.json(
|
|
69
69
|
await requestUploadParts({
|
|
70
70
|
provider,
|
|
@@ -73,7 +73,7 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
73
73
|
ctxToken: req.cookies['edgestore-ctx'],
|
|
74
74
|
}),
|
|
75
75
|
);
|
|
76
|
-
} else if (req.url
|
|
76
|
+
} else if (req.url?.includes?.('/complete-multipart-upload')) {
|
|
77
77
|
await completeMultipartUpload({
|
|
78
78
|
provider,
|
|
79
79
|
router: config.router,
|
|
@@ -81,7 +81,7 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
81
81
|
ctxToken: req.cookies['edgestore-ctx'],
|
|
82
82
|
});
|
|
83
83
|
res.status(200).end();
|
|
84
|
-
} else if (req.url
|
|
84
|
+
} else if (req.url?.includes?.('/confirm-upload')) {
|
|
85
85
|
res.json(
|
|
86
86
|
await confirmUpload({
|
|
87
87
|
provider,
|
|
@@ -90,7 +90,7 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
90
90
|
ctxToken: req.cookies['edgestore-ctx'],
|
|
91
91
|
}),
|
|
92
92
|
);
|
|
93
|
-
} else if (req.url
|
|
93
|
+
} else if (req.url?.includes?.('/delete-file')) {
|
|
94
94
|
res.json(
|
|
95
95
|
await deleteFile({
|
|
96
96
|
provider,
|
|
@@ -99,7 +99,7 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
99
99
|
ctxToken: req.cookies['edgestore-ctx'],
|
|
100
100
|
}),
|
|
101
101
|
);
|
|
102
|
-
} else if (req.url?.
|
|
102
|
+
} else if (req.url?.includes?.('/proxy-file')) {
|
|
103
103
|
const { url } = req.query;
|
|
104
104
|
if (typeof url === 'string') {
|
|
105
105
|
const proxyRes = await fetch(url, {
|
|
@@ -40,6 +40,13 @@ export type AWSProviderOptions = {
|
|
|
40
40
|
* Can also be set via the `EDGE_STORE_BASE_URL` environment variable.
|
|
41
41
|
*/
|
|
42
42
|
baseUrl?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Secret to use for encrypting JWT tokens.
|
|
45
|
+
* Can be generated with `openssl rand -base64 32`.
|
|
46
|
+
*
|
|
47
|
+
* Can also be set via the `EDGE_STORE_JWT_SECRET` environment variable.
|
|
48
|
+
*/
|
|
49
|
+
jwtSecret?: string;
|
|
43
50
|
};
|
|
44
51
|
|
|
45
52
|
export function AWSProvider(options?: AWSProviderOptions): Provider {
|
|
@@ -92,8 +99,10 @@ export function AWSProvider(options?: AWSProviderOptions): Provider {
|
|
|
92
99
|
uploadedAt: LastModified,
|
|
93
100
|
};
|
|
94
101
|
},
|
|
95
|
-
async requestUpload({ bucketName, fileInfo }) {
|
|
96
|
-
const pathPrefix = `${
|
|
102
|
+
async requestUpload({ bucketName: esBucketName, fileInfo }) {
|
|
103
|
+
const pathPrefix = `${esBucketName}${
|
|
104
|
+
fileInfo.isPublic ? '/_public' : ''
|
|
105
|
+
}`;
|
|
97
106
|
const nameId = uuidv4();
|
|
98
107
|
const extension = fileInfo.extension
|
|
99
108
|
? `.${fileInfo.extension.replace('.', '')}`
|
|
@@ -102,17 +111,18 @@ export function AWSProvider(options?: AWSProviderOptions): Provider {
|
|
|
102
111
|
const filePath = fileInfo.path.reduce((acc, item) => {
|
|
103
112
|
return `${acc}/${item.value}`;
|
|
104
113
|
}, '');
|
|
114
|
+
const accessPath = `${pathPrefix}${filePath}/${fileName}`;
|
|
105
115
|
|
|
106
116
|
const command = new PutObjectCommand({
|
|
107
117
|
Bucket: bucketName,
|
|
108
|
-
Key:
|
|
118
|
+
Key: accessPath,
|
|
109
119
|
});
|
|
110
120
|
|
|
111
121
|
const signedUrl = await getSignedUrl(s3Client, command, {
|
|
112
122
|
expiresIn: 60 * 60, // 1 hour
|
|
113
123
|
});
|
|
114
124
|
|
|
115
|
-
const url = `${baseUrl}/${
|
|
125
|
+
const url = `${baseUrl}/${accessPath}`;
|
|
116
126
|
return {
|
|
117
127
|
uploadUrl: signedUrl,
|
|
118
128
|
accessUrl: url,
|
package/adapters/next/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '../../dist/adapters/next';
|
package/adapters/next/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('../../dist/adapters/next');
|