@edgestore/server 0.1.7 → 0.2.1
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 +2 -2
- package/dist/adapters/express/index.d.ts.map +1 -1
- package/dist/adapters/express/index.js +11 -10
- package/dist/adapters/express/index.mjs +10 -9
- package/dist/adapters/next/app/index.d.ts.map +1 -1
- package/dist/adapters/next/app/index.js +11 -10
- package/dist/adapters/next/app/index.mjs +10 -9
- package/dist/adapters/next/pages/index.d.ts.map +1 -1
- package/dist/adapters/next/pages/index.js +11 -10
- package/dist/adapters/next/pages/index.mjs +10 -9
- package/dist/core/client/index.d.ts +2 -2
- package/dist/core/index.js +1 -1
- package/dist/core/index.mjs +1 -1
- package/dist/libs/utils.d.ts +5 -0
- package/dist/libs/utils.d.ts.map +1 -0
- package/dist/providers/aws/index.d.ts +2 -2
- package/dist/{logger-e0066db9.js → utils-461a2e3b.js} +11 -1
- package/dist/{logger-dcb682ae.js → utils-5819d5e1.js} +10 -0
- package/dist/{logger-09f43a75.mjs → utils-f6f56d38.mjs} +10 -1
- package/package.json +3 -3
- package/src/adapters/express/index.ts +10 -8
- package/src/adapters/next/app/index.ts +12 -8
- package/src/adapters/next/pages/index.ts +10 -8
- package/src/core/client/index.ts +3 -3
- package/src/libs/utils.ts +9 -0
- package/src/providers/aws/index.ts +2 -2
package/README.md
CHANGED
|
@@ -98,7 +98,7 @@ export default function RootLayout({
|
|
|
98
98
|
|
|
99
99
|
### Upload file
|
|
100
100
|
|
|
101
|
-
You can use the `useEdgeStore` hook to access typesafe frontend client and use it to upload files.
|
|
101
|
+
You can use the `useEdgeStore` hook to access a typesafe frontend client and use it to upload files.
|
|
102
102
|
|
|
103
103
|
```tsx {1, 6, 19-28}
|
|
104
104
|
import * as React from 'react';
|
|
@@ -144,7 +144,7 @@ export default function Page() {
|
|
|
144
144
|
By passing the `replaceTargetUrl` option, you can replace an existing file with a new one.
|
|
145
145
|
It will automatically delete the old file after the upload is complete.
|
|
146
146
|
|
|
147
|
-
You can also
|
|
147
|
+
You can also upload the file using the same file name, but in that case, you might still see the old file for a while because of the CDN cache.
|
|
148
148
|
|
|
149
149
|
```tsx
|
|
150
150
|
const res = await edgestore.publicFiles.upload({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/express/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,QAAQ,EACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AACtD,OAAe,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/express/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,QAAQ,EACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AACtD,OAAe,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAiB1D,MAAM,MAAM,oBAAoB,GAAG;IACjC,GAAG,EAAE,OAAO,CAAC;IACb,GAAG,EAAE,QAAQ,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,MAAM,CAAC,IAAI,IAAI;IACzB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC;IAC9B,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,GAAG,CAAC,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GACnC,MAAM,GACN;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,CAAC;AAMP,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,SAMnD,OAAO,OAAO,QAAQ,mBAiH1C"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var shared = require('@edgestore/shared');
|
|
6
|
-
var
|
|
6
|
+
var utils = require('../../utils-5819d5e1.js');
|
|
7
7
|
var providers_edgestore_index = require('../../providers/edgestore/index.js');
|
|
8
8
|
var shared$1 = require('../../shared-7c700083.js');
|
|
9
9
|
require('../../index-4491caf0.js');
|
|
@@ -14,14 +14,15 @@ require('uuid');
|
|
|
14
14
|
|
|
15
15
|
function createEdgeStoreExpressHandler(config) {
|
|
16
16
|
const { provider = providers_edgestore_index.EdgeStoreProvider() } = config;
|
|
17
|
-
const log = new
|
|
17
|
+
const log = new utils.Logger(config.logLevel);
|
|
18
18
|
globalThis._EDGE_STORE_LOGGER = log;
|
|
19
19
|
log.debug('Creating Edge Store Express handler');
|
|
20
20
|
return async (req, res)=>{
|
|
21
21
|
try {
|
|
22
|
-
|
|
22
|
+
const pathname = req.url ?? '';
|
|
23
|
+
if (utils.matchPath(pathname, '/health')) {
|
|
23
24
|
res.send('OK');
|
|
24
|
-
} else if (
|
|
25
|
+
} else if (utils.matchPath(pathname, '/init')) {
|
|
25
26
|
let ctx = {};
|
|
26
27
|
try {
|
|
27
28
|
ctx = 'createContext' in config ? await config.createContext({
|
|
@@ -45,21 +46,21 @@ function createEdgeStoreExpressHandler(config) {
|
|
|
45
46
|
token,
|
|
46
47
|
baseUrl
|
|
47
48
|
});
|
|
48
|
-
} else if (
|
|
49
|
+
} else if (utils.matchPath(pathname, '/request-upload')) {
|
|
49
50
|
res.json(await shared$1.requestUpload({
|
|
50
51
|
provider,
|
|
51
52
|
router: config.router,
|
|
52
53
|
body: req.body,
|
|
53
54
|
ctxToken: req.cookies['edgestore-ctx']
|
|
54
55
|
}));
|
|
55
|
-
} else if (
|
|
56
|
+
} else if (utils.matchPath(pathname, '/request-upload-parts')) {
|
|
56
57
|
res.json(await shared$1.requestUploadParts({
|
|
57
58
|
provider,
|
|
58
59
|
router: config.router,
|
|
59
60
|
body: req.body,
|
|
60
61
|
ctxToken: req.cookies['edgestore-ctx']
|
|
61
62
|
}));
|
|
62
|
-
} else if (
|
|
63
|
+
} else if (utils.matchPath(pathname, '/complete-multipart-upload')) {
|
|
63
64
|
await shared$1.completeMultipartUpload({
|
|
64
65
|
provider,
|
|
65
66
|
router: config.router,
|
|
@@ -67,21 +68,21 @@ function createEdgeStoreExpressHandler(config) {
|
|
|
67
68
|
ctxToken: req.cookies['edgestore-ctx']
|
|
68
69
|
});
|
|
69
70
|
res.status(200).end();
|
|
70
|
-
} else if (
|
|
71
|
+
} else if (utils.matchPath(pathname, '/confirm-upload')) {
|
|
71
72
|
res.json(await shared$1.confirmUpload({
|
|
72
73
|
provider,
|
|
73
74
|
router: config.router,
|
|
74
75
|
body: req.body,
|
|
75
76
|
ctxToken: req.cookies['edgestore-ctx']
|
|
76
77
|
}));
|
|
77
|
-
} else if (
|
|
78
|
+
} else if (utils.matchPath(pathname, '/delete-file')) {
|
|
78
79
|
res.json(await shared$1.deleteFile({
|
|
79
80
|
provider,
|
|
80
81
|
router: config.router,
|
|
81
82
|
body: req.body,
|
|
82
83
|
ctxToken: req.cookies['edgestore-ctx']
|
|
83
84
|
}));
|
|
84
|
-
} else if (
|
|
85
|
+
} else if (utils.matchPath(pathname, '/proxy-file')) {
|
|
85
86
|
const { url } = req.query;
|
|
86
87
|
if (typeof url === 'string') {
|
|
87
88
|
const proxyRes = await fetch(url, {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EdgeStoreError, EDGE_STORE_ERROR_CODES } from '@edgestore/shared';
|
|
2
|
-
import { L as Logger } from '../../
|
|
2
|
+
import { L as Logger, m as matchPath } from '../../utils-f6f56d38.mjs';
|
|
3
3
|
import { EdgeStoreProvider } from '../../providers/edgestore/index.mjs';
|
|
4
4
|
import { i as init, r as requestUpload, a as requestUploadParts, c as completeMultipartUpload, d as confirmUpload, e as deleteFile } from '../../shared-039276af.mjs';
|
|
5
5
|
import '../../index-28efdacf.mjs';
|
|
@@ -15,9 +15,10 @@ function createEdgeStoreExpressHandler(config) {
|
|
|
15
15
|
log.debug('Creating Edge Store Express handler');
|
|
16
16
|
return async (req, res)=>{
|
|
17
17
|
try {
|
|
18
|
-
|
|
18
|
+
const pathname = req.url ?? '';
|
|
19
|
+
if (matchPath(pathname, '/health')) {
|
|
19
20
|
res.send('OK');
|
|
20
|
-
} else if (
|
|
21
|
+
} else if (matchPath(pathname, '/init')) {
|
|
21
22
|
let ctx = {};
|
|
22
23
|
try {
|
|
23
24
|
ctx = 'createContext' in config ? await config.createContext({
|
|
@@ -41,21 +42,21 @@ function createEdgeStoreExpressHandler(config) {
|
|
|
41
42
|
token,
|
|
42
43
|
baseUrl
|
|
43
44
|
});
|
|
44
|
-
} else if (
|
|
45
|
+
} else if (matchPath(pathname, '/request-upload')) {
|
|
45
46
|
res.json(await requestUpload({
|
|
46
47
|
provider,
|
|
47
48
|
router: config.router,
|
|
48
49
|
body: req.body,
|
|
49
50
|
ctxToken: req.cookies['edgestore-ctx']
|
|
50
51
|
}));
|
|
51
|
-
} else if (
|
|
52
|
+
} else if (matchPath(pathname, '/request-upload-parts')) {
|
|
52
53
|
res.json(await requestUploadParts({
|
|
53
54
|
provider,
|
|
54
55
|
router: config.router,
|
|
55
56
|
body: req.body,
|
|
56
57
|
ctxToken: req.cookies['edgestore-ctx']
|
|
57
58
|
}));
|
|
58
|
-
} else if (
|
|
59
|
+
} else if (matchPath(pathname, '/complete-multipart-upload')) {
|
|
59
60
|
await completeMultipartUpload({
|
|
60
61
|
provider,
|
|
61
62
|
router: config.router,
|
|
@@ -63,21 +64,21 @@ function createEdgeStoreExpressHandler(config) {
|
|
|
63
64
|
ctxToken: req.cookies['edgestore-ctx']
|
|
64
65
|
});
|
|
65
66
|
res.status(200).end();
|
|
66
|
-
} else if (
|
|
67
|
+
} else if (matchPath(pathname, '/confirm-upload')) {
|
|
67
68
|
res.json(await confirmUpload({
|
|
68
69
|
provider,
|
|
69
70
|
router: config.router,
|
|
70
71
|
body: req.body,
|
|
71
72
|
ctxToken: req.cookies['edgestore-ctx']
|
|
72
73
|
}));
|
|
73
|
-
} else if (
|
|
74
|
+
} else if (matchPath(pathname, '/delete-file')) {
|
|
74
75
|
res.json(await deleteFile({
|
|
75
76
|
provider,
|
|
76
77
|
router: config.router,
|
|
77
78
|
body: req.body,
|
|
78
79
|
ctxToken: req.cookies['edgestore-ctx']
|
|
79
80
|
}));
|
|
80
|
-
} else if (
|
|
81
|
+
} else if (matchPath(pathname, '/proxy-file')) {
|
|
81
82
|
const { url } = req.query;
|
|
82
83
|
if (typeof url === 'string') {
|
|
83
84
|
const proxyRes = await fetch(url, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/adapters/next/app/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,QAAQ,EACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAe,EAAE,KAAK,QAAQ,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/adapters/next/app/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,QAAQ,EACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAe,EAAE,KAAK,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAiB7D,MAAM,MAAM,oBAAoB,GAAG;IACjC,GAAG,EAAE,WAAW,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,MAAM,CAAC,IAAI,IAAI;IACzB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC;IAC9B,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,GAAG,CAAC,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GACnC,MAAM,GACN;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,CAAC;AAMP,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,SAMhD,WAAW,uBAwK/B"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var shared = require('@edgestore/shared');
|
|
6
|
-
var
|
|
6
|
+
var utils = require('../../../utils-5819d5e1.js');
|
|
7
7
|
var providers_edgestore_index = require('../../../providers/edgestore/index.js');
|
|
8
8
|
var shared$1 = require('../../../shared-7c700083.js');
|
|
9
9
|
require('../../../index-4491caf0.js');
|
|
@@ -14,7 +14,7 @@ require('uuid');
|
|
|
14
14
|
|
|
15
15
|
function createEdgeStoreNextHandler(config) {
|
|
16
16
|
const { provider = providers_edgestore_index.EdgeStoreProvider() } = config;
|
|
17
|
-
const log = new
|
|
17
|
+
const log = new utils.Logger(config.logLevel);
|
|
18
18
|
globalThis._EDGE_STORE_LOGGER = log;
|
|
19
19
|
log.debug('Creating Edge Store Next handler (app adapter)');
|
|
20
20
|
return async (req)=>{
|
|
@@ -23,11 +23,12 @@ function createEdgeStoreNextHandler(config) {
|
|
|
23
23
|
message: 'Error running the app adapter. Make sure you are importing the correct adapter in your router configuration',
|
|
24
24
|
code: 'SERVER_ERROR'
|
|
25
25
|
});
|
|
26
|
-
|
|
26
|
+
const pathname = req.nextUrl.pathname;
|
|
27
|
+
if (utils.matchPath(pathname, '/health')) {
|
|
27
28
|
return new Response('OK', {
|
|
28
29
|
status: 200
|
|
29
30
|
});
|
|
30
|
-
} else if (
|
|
31
|
+
} else if (utils.matchPath(pathname, '/init')) {
|
|
31
32
|
let ctx = {};
|
|
32
33
|
try {
|
|
33
34
|
ctx = 'createContext' in config ? await config.createContext({
|
|
@@ -58,7 +59,7 @@ function createEdgeStoreNextHandler(config) {
|
|
|
58
59
|
res.headers.append('Set-Cookie', cookie);
|
|
59
60
|
}
|
|
60
61
|
return res;
|
|
61
|
-
} else if (
|
|
62
|
+
} else if (utils.matchPath(pathname, '/request-upload')) {
|
|
62
63
|
const res = await shared$1.requestUpload({
|
|
63
64
|
provider,
|
|
64
65
|
router: config.router,
|
|
@@ -71,7 +72,7 @@ function createEdgeStoreNextHandler(config) {
|
|
|
71
72
|
'Content-Type': 'application/json'
|
|
72
73
|
}
|
|
73
74
|
});
|
|
74
|
-
} else if (
|
|
75
|
+
} else if (utils.matchPath(pathname, '/request-upload-parts')) {
|
|
75
76
|
const res = await shared$1.requestUploadParts({
|
|
76
77
|
provider,
|
|
77
78
|
router: config.router,
|
|
@@ -84,7 +85,7 @@ function createEdgeStoreNextHandler(config) {
|
|
|
84
85
|
'Content-Type': 'application/json'
|
|
85
86
|
}
|
|
86
87
|
});
|
|
87
|
-
} else if (
|
|
88
|
+
} else if (utils.matchPath(pathname, '/complete-multipart-upload')) {
|
|
88
89
|
await shared$1.completeMultipartUpload({
|
|
89
90
|
provider,
|
|
90
91
|
router: config.router,
|
|
@@ -94,7 +95,7 @@ function createEdgeStoreNextHandler(config) {
|
|
|
94
95
|
return new Response(null, {
|
|
95
96
|
status: 200
|
|
96
97
|
});
|
|
97
|
-
} else if (
|
|
98
|
+
} else if (utils.matchPath(pathname, '/confirm-upload')) {
|
|
98
99
|
const res = await shared$1.confirmUpload({
|
|
99
100
|
provider,
|
|
100
101
|
router: config.router,
|
|
@@ -107,7 +108,7 @@ function createEdgeStoreNextHandler(config) {
|
|
|
107
108
|
'Content-Type': 'application/json'
|
|
108
109
|
}
|
|
109
110
|
});
|
|
110
|
-
} else if (
|
|
111
|
+
} else if (utils.matchPath(pathname, '/delete-file')) {
|
|
111
112
|
const res = await shared$1.deleteFile({
|
|
112
113
|
provider,
|
|
113
114
|
router: config.router,
|
|
@@ -120,7 +121,7 @@ function createEdgeStoreNextHandler(config) {
|
|
|
120
121
|
'Content-Type': 'application/json'
|
|
121
122
|
}
|
|
122
123
|
});
|
|
123
|
-
} else if (
|
|
124
|
+
} else if (utils.matchPath(pathname, '/proxy-file')) {
|
|
124
125
|
const url = req.nextUrl.searchParams.get('url');
|
|
125
126
|
if (typeof url === 'string') {
|
|
126
127
|
const proxyRes = await fetch(url, {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EdgeStoreError, EDGE_STORE_ERROR_CODES } from '@edgestore/shared';
|
|
2
|
-
import { L as Logger } from '../../../
|
|
2
|
+
import { L as Logger, m as matchPath } from '../../../utils-f6f56d38.mjs';
|
|
3
3
|
import { EdgeStoreProvider } from '../../../providers/edgestore/index.mjs';
|
|
4
4
|
import { i as init, r as requestUpload, a as requestUploadParts, c as completeMultipartUpload, d as confirmUpload, e as deleteFile } from '../../../shared-039276af.mjs';
|
|
5
5
|
import '../../../index-28efdacf.mjs';
|
|
@@ -19,11 +19,12 @@ function createEdgeStoreNextHandler(config) {
|
|
|
19
19
|
message: 'Error running the app adapter. Make sure you are importing the correct adapter in your router configuration',
|
|
20
20
|
code: 'SERVER_ERROR'
|
|
21
21
|
});
|
|
22
|
-
|
|
22
|
+
const pathname = req.nextUrl.pathname;
|
|
23
|
+
if (matchPath(pathname, '/health')) {
|
|
23
24
|
return new Response('OK', {
|
|
24
25
|
status: 200
|
|
25
26
|
});
|
|
26
|
-
} else if (
|
|
27
|
+
} else if (matchPath(pathname, '/init')) {
|
|
27
28
|
let ctx = {};
|
|
28
29
|
try {
|
|
29
30
|
ctx = 'createContext' in config ? await config.createContext({
|
|
@@ -54,7 +55,7 @@ function createEdgeStoreNextHandler(config) {
|
|
|
54
55
|
res.headers.append('Set-Cookie', cookie);
|
|
55
56
|
}
|
|
56
57
|
return res;
|
|
57
|
-
} else if (
|
|
58
|
+
} else if (matchPath(pathname, '/request-upload')) {
|
|
58
59
|
const res = await requestUpload({
|
|
59
60
|
provider,
|
|
60
61
|
router: config.router,
|
|
@@ -67,7 +68,7 @@ function createEdgeStoreNextHandler(config) {
|
|
|
67
68
|
'Content-Type': 'application/json'
|
|
68
69
|
}
|
|
69
70
|
});
|
|
70
|
-
} else if (
|
|
71
|
+
} else if (matchPath(pathname, '/request-upload-parts')) {
|
|
71
72
|
const res = await requestUploadParts({
|
|
72
73
|
provider,
|
|
73
74
|
router: config.router,
|
|
@@ -80,7 +81,7 @@ function createEdgeStoreNextHandler(config) {
|
|
|
80
81
|
'Content-Type': 'application/json'
|
|
81
82
|
}
|
|
82
83
|
});
|
|
83
|
-
} else if (
|
|
84
|
+
} else if (matchPath(pathname, '/complete-multipart-upload')) {
|
|
84
85
|
await completeMultipartUpload({
|
|
85
86
|
provider,
|
|
86
87
|
router: config.router,
|
|
@@ -90,7 +91,7 @@ function createEdgeStoreNextHandler(config) {
|
|
|
90
91
|
return new Response(null, {
|
|
91
92
|
status: 200
|
|
92
93
|
});
|
|
93
|
-
} else if (
|
|
94
|
+
} else if (matchPath(pathname, '/confirm-upload')) {
|
|
94
95
|
const res = await confirmUpload({
|
|
95
96
|
provider,
|
|
96
97
|
router: config.router,
|
|
@@ -103,7 +104,7 @@ function createEdgeStoreNextHandler(config) {
|
|
|
103
104
|
'Content-Type': 'application/json'
|
|
104
105
|
}
|
|
105
106
|
});
|
|
106
|
-
} else if (
|
|
107
|
+
} else if (matchPath(pathname, '/delete-file')) {
|
|
107
108
|
const res = await deleteFile({
|
|
108
109
|
provider,
|
|
109
110
|
router: config.router,
|
|
@@ -116,7 +117,7 @@ function createEdgeStoreNextHandler(config) {
|
|
|
116
117
|
'Content-Type': 'application/json'
|
|
117
118
|
}
|
|
118
119
|
});
|
|
119
|
-
} else if (
|
|
120
|
+
} else if (matchPath(pathname, '/proxy-file')) {
|
|
120
121
|
const url = req.nextUrl.searchParams.get('url');
|
|
121
122
|
if (typeof url === 'string') {
|
|
122
123
|
const proxyRes = await fetch(url, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/adapters/next/pages/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,QAAQ,EACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AACvE,OAAe,EAAE,KAAK,QAAQ,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/adapters/next/pages/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,QAAQ,EACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AACvE,OAAe,EAAE,KAAK,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAiB7D,MAAM,MAAM,oBAAoB,GAAG;IACjC,GAAG,EAAE,cAAc,CAAC;IACpB,GAAG,EAAE,eAAe,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,MAAM,CAAC,IAAI,IAAI;IACzB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC;IAC9B,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,GAAG,CAAC,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GACnC,MAAM,GACN;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,CAAC;AAMP,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,SAMhD,cAAc,OAAO,eAAe,mBAuHxD"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var shared = require('@edgestore/shared');
|
|
6
|
-
var
|
|
6
|
+
var utils = require('../../../utils-5819d5e1.js');
|
|
7
7
|
var providers_edgestore_index = require('../../../providers/edgestore/index.js');
|
|
8
8
|
var shared$1 = require('../../../shared-7c700083.js');
|
|
9
9
|
require('../../../index-4491caf0.js');
|
|
@@ -14,7 +14,7 @@ require('uuid');
|
|
|
14
14
|
|
|
15
15
|
function createEdgeStoreNextHandler(config) {
|
|
16
16
|
const { provider = providers_edgestore_index.EdgeStoreProvider() } = config;
|
|
17
|
-
const log = new
|
|
17
|
+
const log = new utils.Logger(config.logLevel);
|
|
18
18
|
globalThis._EDGE_STORE_LOGGER = log;
|
|
19
19
|
log.debug('Creating Edge Store Next handler (pages adapter)');
|
|
20
20
|
return async (req, res)=>{
|
|
@@ -23,9 +23,10 @@ function createEdgeStoreNextHandler(config) {
|
|
|
23
23
|
message: 'Error running the pages adapter. Make sure you are importing the correct adapter in your router configuration',
|
|
24
24
|
code: 'SERVER_ERROR'
|
|
25
25
|
});
|
|
26
|
-
|
|
26
|
+
const pathname = req.url ?? '';
|
|
27
|
+
if (utils.matchPath(pathname, '/health')) {
|
|
27
28
|
res.send('OK');
|
|
28
|
-
} else if (
|
|
29
|
+
} else if (utils.matchPath(pathname, '/init')) {
|
|
29
30
|
let ctx = {};
|
|
30
31
|
try {
|
|
31
32
|
ctx = 'createContext' in config ? await config.createContext({
|
|
@@ -49,21 +50,21 @@ function createEdgeStoreNextHandler(config) {
|
|
|
49
50
|
token,
|
|
50
51
|
baseUrl
|
|
51
52
|
});
|
|
52
|
-
} else if (
|
|
53
|
+
} else if (utils.matchPath(pathname, '/request-upload')) {
|
|
53
54
|
res.json(await shared$1.requestUpload({
|
|
54
55
|
provider,
|
|
55
56
|
router: config.router,
|
|
56
57
|
body: req.body,
|
|
57
58
|
ctxToken: req.cookies['edgestore-ctx']
|
|
58
59
|
}));
|
|
59
|
-
} else if (
|
|
60
|
+
} else if (utils.matchPath(pathname, '/request-upload-parts')) {
|
|
60
61
|
res.json(await shared$1.requestUploadParts({
|
|
61
62
|
provider,
|
|
62
63
|
router: config.router,
|
|
63
64
|
body: req.body,
|
|
64
65
|
ctxToken: req.cookies['edgestore-ctx']
|
|
65
66
|
}));
|
|
66
|
-
} else if (
|
|
67
|
+
} else if (utils.matchPath(pathname, '/complete-multipart-upload')) {
|
|
67
68
|
await shared$1.completeMultipartUpload({
|
|
68
69
|
provider,
|
|
69
70
|
router: config.router,
|
|
@@ -71,21 +72,21 @@ function createEdgeStoreNextHandler(config) {
|
|
|
71
72
|
ctxToken: req.cookies['edgestore-ctx']
|
|
72
73
|
});
|
|
73
74
|
res.status(200).end();
|
|
74
|
-
} else if (
|
|
75
|
+
} else if (utils.matchPath(pathname, '/confirm-upload')) {
|
|
75
76
|
res.json(await shared$1.confirmUpload({
|
|
76
77
|
provider,
|
|
77
78
|
router: config.router,
|
|
78
79
|
body: req.body,
|
|
79
80
|
ctxToken: req.cookies['edgestore-ctx']
|
|
80
81
|
}));
|
|
81
|
-
} else if (
|
|
82
|
+
} else if (utils.matchPath(pathname, '/delete-file')) {
|
|
82
83
|
res.json(await shared$1.deleteFile({
|
|
83
84
|
provider,
|
|
84
85
|
router: config.router,
|
|
85
86
|
body: req.body,
|
|
86
87
|
ctxToken: req.cookies['edgestore-ctx']
|
|
87
88
|
}));
|
|
88
|
-
} else if (
|
|
89
|
+
} else if (utils.matchPath(pathname, '/proxy-file')) {
|
|
89
90
|
const { url } = req.query;
|
|
90
91
|
if (typeof url === 'string') {
|
|
91
92
|
const proxyRes = await fetch(url, {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EdgeStoreError, EDGE_STORE_ERROR_CODES } from '@edgestore/shared';
|
|
2
|
-
import { L as Logger } from '../../../
|
|
2
|
+
import { L as Logger, m as matchPath } from '../../../utils-f6f56d38.mjs';
|
|
3
3
|
import { EdgeStoreProvider } from '../../../providers/edgestore/index.mjs';
|
|
4
4
|
import { i as init, r as requestUpload, a as requestUploadParts, c as completeMultipartUpload, d as confirmUpload, e as deleteFile } from '../../../shared-039276af.mjs';
|
|
5
5
|
import '../../../index-28efdacf.mjs';
|
|
@@ -19,9 +19,10 @@ function createEdgeStoreNextHandler(config) {
|
|
|
19
19
|
message: 'Error running the pages adapter. Make sure you are importing the correct adapter in your router configuration',
|
|
20
20
|
code: 'SERVER_ERROR'
|
|
21
21
|
});
|
|
22
|
-
|
|
22
|
+
const pathname = req.url ?? '';
|
|
23
|
+
if (matchPath(pathname, '/health')) {
|
|
23
24
|
res.send('OK');
|
|
24
|
-
} else if (
|
|
25
|
+
} else if (matchPath(pathname, '/init')) {
|
|
25
26
|
let ctx = {};
|
|
26
27
|
try {
|
|
27
28
|
ctx = 'createContext' in config ? await config.createContext({
|
|
@@ -45,21 +46,21 @@ function createEdgeStoreNextHandler(config) {
|
|
|
45
46
|
token,
|
|
46
47
|
baseUrl
|
|
47
48
|
});
|
|
48
|
-
} else if (
|
|
49
|
+
} else if (matchPath(pathname, '/request-upload')) {
|
|
49
50
|
res.json(await requestUpload({
|
|
50
51
|
provider,
|
|
51
52
|
router: config.router,
|
|
52
53
|
body: req.body,
|
|
53
54
|
ctxToken: req.cookies['edgestore-ctx']
|
|
54
55
|
}));
|
|
55
|
-
} else if (
|
|
56
|
+
} else if (matchPath(pathname, '/request-upload-parts')) {
|
|
56
57
|
res.json(await requestUploadParts({
|
|
57
58
|
provider,
|
|
58
59
|
router: config.router,
|
|
59
60
|
body: req.body,
|
|
60
61
|
ctxToken: req.cookies['edgestore-ctx']
|
|
61
62
|
}));
|
|
62
|
-
} else if (
|
|
63
|
+
} else if (matchPath(pathname, '/complete-multipart-upload')) {
|
|
63
64
|
await completeMultipartUpload({
|
|
64
65
|
provider,
|
|
65
66
|
router: config.router,
|
|
@@ -67,21 +68,21 @@ function createEdgeStoreNextHandler(config) {
|
|
|
67
68
|
ctxToken: req.cookies['edgestore-ctx']
|
|
68
69
|
});
|
|
69
70
|
res.status(200).end();
|
|
70
|
-
} else if (
|
|
71
|
+
} else if (matchPath(pathname, '/confirm-upload')) {
|
|
71
72
|
res.json(await confirmUpload({
|
|
72
73
|
provider,
|
|
73
74
|
router: config.router,
|
|
74
75
|
body: req.body,
|
|
75
76
|
ctxToken: req.cookies['edgestore-ctx']
|
|
76
77
|
}));
|
|
77
|
-
} else if (
|
|
78
|
+
} else if (matchPath(pathname, '/delete-file')) {
|
|
78
79
|
res.json(await deleteFile({
|
|
79
80
|
provider,
|
|
80
81
|
router: config.router,
|
|
81
82
|
body: req.body,
|
|
82
83
|
ctxToken: req.cookies['edgestore-ctx']
|
|
83
84
|
}));
|
|
84
|
-
} else if (
|
|
85
|
+
} else if (matchPath(pathname, '/proxy-file')) {
|
|
85
86
|
const { url } = req.query;
|
|
86
87
|
if (typeof url === 'string') {
|
|
87
88
|
const proxyRes = await fetch(url, {
|
|
@@ -18,7 +18,7 @@ export type UploadOptions = {
|
|
|
18
18
|
* But it might take some time for the CDN cache to be cleared.
|
|
19
19
|
* So maybe you will keep seeing the old file for a while.
|
|
20
20
|
*
|
|
21
|
-
* If you want to replace an existing file immediately leave the `manualFileName` option empty and use the `replaceTargetUrl` option.
|
|
21
|
+
* If you want to replace an existing file, immediately leave the `manualFileName` option empty and use the `replaceTargetUrl` option.
|
|
22
22
|
*/
|
|
23
23
|
manualFileName?: string;
|
|
24
24
|
/**
|
|
@@ -202,7 +202,7 @@ export declare function initEdgeStoreClient<TRouter extends AnyRouter>(config: {
|
|
|
202
202
|
/**
|
|
203
203
|
* The base URL of your application.
|
|
204
204
|
*
|
|
205
|
-
* This is only needed for getting protected files
|
|
205
|
+
* This is only needed for getting protected files in a development environment.
|
|
206
206
|
*
|
|
207
207
|
* @example http://localhost:3000/api/edgestore
|
|
208
208
|
*/
|
package/dist/core/index.js
CHANGED
|
@@ -157,7 +157,7 @@ function initEdgeStoreClient(config) {
|
|
|
157
157
|
}
|
|
158
158
|
/**
|
|
159
159
|
* Protected files need third-party cookies to work.
|
|
160
|
-
* Since third party cookies
|
|
160
|
+
* Since third party cookies don't work on localhost,
|
|
161
161
|
* we need to proxy the file through the server.
|
|
162
162
|
*/ function getUrl(url, baseUrl) {
|
|
163
163
|
if (process.env.NODE_ENV === 'development' && !url.includes('/_public/')) {
|
package/dist/core/index.mjs
CHANGED
|
@@ -154,7 +154,7 @@ function initEdgeStoreClient(config) {
|
|
|
154
154
|
}
|
|
155
155
|
/**
|
|
156
156
|
* Protected files need third-party cookies to work.
|
|
157
|
-
* Since third party cookies
|
|
157
|
+
* Since third party cookies don't work on localhost,
|
|
158
158
|
* we need to proxy the file through the server.
|
|
159
159
|
*/ function getUrl(url, baseUrl) {
|
|
160
160
|
if (process.env.NODE_ENV === 'development' && !url.includes('/_public/')) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/libs/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,WAKxD"}
|
|
@@ -28,14 +28,14 @@ export type AWSProviderOptions = {
|
|
|
28
28
|
* Base URL to use for accessing files.
|
|
29
29
|
* Only needed if you are using a custom domain or cloudfront.
|
|
30
30
|
*
|
|
31
|
-
*
|
|
31
|
+
* It can also be set via the `EDGE_STORE_BASE_URL` environment variable.
|
|
32
32
|
*/
|
|
33
33
|
baseUrl?: string;
|
|
34
34
|
/**
|
|
35
35
|
* Secret to use for encrypting JWT tokens.
|
|
36
36
|
* Can be generated with `openssl rand -base64 32`.
|
|
37
37
|
*
|
|
38
|
-
*
|
|
38
|
+
* It can also be set via the `EDGE_STORE_JWT_SECRET` environment variable.
|
|
39
39
|
*/
|
|
40
40
|
jwtSecret?: string;
|
|
41
41
|
};
|
|
@@ -30,4 +30,14 @@ class Logger {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Check if a route matches the current path.
|
|
35
|
+
*/
|
|
36
|
+
function matchPath(pathname, route) {
|
|
37
|
+
// Allow trailing slash
|
|
38
|
+
// Allow query string
|
|
39
|
+
const regex = new RegExp(`${route}/?(\\?.*)?$`);
|
|
40
|
+
return regex.test(pathname);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { Logger as L, matchPath as m };
|
|
@@ -50,4 +50,14 @@ class Logger {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Check if a route matches the current path.
|
|
55
|
+
*/ function matchPath(pathname, route) {
|
|
56
|
+
// Allow trailing slash
|
|
57
|
+
// Allow query string
|
|
58
|
+
const regex = new RegExp(`${route}/?(\\?.*)?$`);
|
|
59
|
+
return regex.test(pathname);
|
|
60
|
+
}
|
|
61
|
+
|
|
53
62
|
exports.Logger = Logger;
|
|
63
|
+
exports.matchPath = matchPath;
|
|
@@ -48,4 +48,13 @@ class Logger {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Check if a route matches the current path.
|
|
53
|
+
*/ function matchPath(pathname, route) {
|
|
54
|
+
// Allow trailing slash
|
|
55
|
+
// Allow query string
|
|
56
|
+
const regex = new RegExp(`${route}/?(\\?.*)?$`);
|
|
57
|
+
return regex.test(pathname);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { Logger as L, matchPath as m };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edgestore/server",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
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,7 +84,7 @@
|
|
|
84
84
|
},
|
|
85
85
|
"license": "MIT",
|
|
86
86
|
"dependencies": {
|
|
87
|
-
"@edgestore/shared": "0.1
|
|
87
|
+
"@edgestore/shared": "0.2.1",
|
|
88
88
|
"@panva/hkdf": "^1.0.4",
|
|
89
89
|
"cookie": "^0.5.0",
|
|
90
90
|
"jose": "^4.13.1",
|
|
@@ -123,5 +123,5 @@
|
|
|
123
123
|
"typescript": "^5.1.6",
|
|
124
124
|
"zod": "3.21.4"
|
|
125
125
|
},
|
|
126
|
-
"gitHead": "
|
|
126
|
+
"gitHead": "821e2f3e366a83a75aa7b84d4750e6d3e32c992d"
|
|
127
127
|
}
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from '@edgestore/shared';
|
|
9
9
|
import { type Request, type Response } from 'express';
|
|
10
10
|
import Logger, { type LogLevel } from '../../libs/logger';
|
|
11
|
+
import { matchPath } from '../../libs/utils';
|
|
11
12
|
import { EdgeStoreProvider } from '../../providers/edgestore';
|
|
12
13
|
import {
|
|
13
14
|
completeMultipartUpload,
|
|
@@ -52,9 +53,10 @@ export function createEdgeStoreExpressHandler<TCtx>(config: Config<TCtx>) {
|
|
|
52
53
|
|
|
53
54
|
return async (req: Request, res: Response) => {
|
|
54
55
|
try {
|
|
55
|
-
|
|
56
|
+
const pathname = req.url ?? '';
|
|
57
|
+
if (matchPath(pathname, '/health')) {
|
|
56
58
|
res.send('OK');
|
|
57
|
-
} else if (
|
|
59
|
+
} else if (matchPath(pathname, '/init')) {
|
|
58
60
|
let ctx = {} as TCtx;
|
|
59
61
|
try {
|
|
60
62
|
ctx =
|
|
@@ -78,7 +80,7 @@ export function createEdgeStoreExpressHandler<TCtx>(config: Config<TCtx>) {
|
|
|
78
80
|
token,
|
|
79
81
|
baseUrl,
|
|
80
82
|
});
|
|
81
|
-
} else if (
|
|
83
|
+
} else if (matchPath(pathname, '/request-upload')) {
|
|
82
84
|
res.json(
|
|
83
85
|
await requestUpload({
|
|
84
86
|
provider,
|
|
@@ -87,7 +89,7 @@ export function createEdgeStoreExpressHandler<TCtx>(config: Config<TCtx>) {
|
|
|
87
89
|
ctxToken: req.cookies['edgestore-ctx'],
|
|
88
90
|
}),
|
|
89
91
|
);
|
|
90
|
-
} else if (
|
|
92
|
+
} else if (matchPath(pathname, '/request-upload-parts')) {
|
|
91
93
|
res.json(
|
|
92
94
|
await requestUploadParts({
|
|
93
95
|
provider,
|
|
@@ -96,7 +98,7 @@ export function createEdgeStoreExpressHandler<TCtx>(config: Config<TCtx>) {
|
|
|
96
98
|
ctxToken: req.cookies['edgestore-ctx'],
|
|
97
99
|
}),
|
|
98
100
|
);
|
|
99
|
-
} else if (
|
|
101
|
+
} else if (matchPath(pathname, '/complete-multipart-upload')) {
|
|
100
102
|
await completeMultipartUpload({
|
|
101
103
|
provider,
|
|
102
104
|
router: config.router,
|
|
@@ -104,7 +106,7 @@ export function createEdgeStoreExpressHandler<TCtx>(config: Config<TCtx>) {
|
|
|
104
106
|
ctxToken: req.cookies['edgestore-ctx'],
|
|
105
107
|
});
|
|
106
108
|
res.status(200).end();
|
|
107
|
-
} else if (
|
|
109
|
+
} else if (matchPath(pathname, '/confirm-upload')) {
|
|
108
110
|
res.json(
|
|
109
111
|
await confirmUpload({
|
|
110
112
|
provider,
|
|
@@ -113,7 +115,7 @@ export function createEdgeStoreExpressHandler<TCtx>(config: Config<TCtx>) {
|
|
|
113
115
|
ctxToken: req.cookies['edgestore-ctx'],
|
|
114
116
|
}),
|
|
115
117
|
);
|
|
116
|
-
} else if (
|
|
118
|
+
} else if (matchPath(pathname, '/delete-file')) {
|
|
117
119
|
res.json(
|
|
118
120
|
await deleteFile({
|
|
119
121
|
provider,
|
|
@@ -122,7 +124,7 @@ export function createEdgeStoreExpressHandler<TCtx>(config: Config<TCtx>) {
|
|
|
122
124
|
ctxToken: req.cookies['edgestore-ctx'],
|
|
123
125
|
}),
|
|
124
126
|
);
|
|
125
|
-
} else if (
|
|
127
|
+
} else if (matchPath(pathname, '/proxy-file')) {
|
|
126
128
|
const { url } = req.query;
|
|
127
129
|
if (typeof url === 'string') {
|
|
128
130
|
const proxyRes = await fetch(url, {
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from '@edgestore/shared';
|
|
9
9
|
import { type NextRequest } from 'next/server';
|
|
10
10
|
import Logger, { type LogLevel } from '../../../libs/logger';
|
|
11
|
+
import { matchPath } from '../../../libs/utils';
|
|
11
12
|
import { EdgeStoreProvider } from '../../../providers/edgestore';
|
|
12
13
|
import {
|
|
13
14
|
completeMultipartUpload,
|
|
@@ -57,11 +58,14 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
57
58
|
'Error running the app adapter. Make sure you are importing the correct adapter in your router configuration',
|
|
58
59
|
code: 'SERVER_ERROR',
|
|
59
60
|
});
|
|
60
|
-
|
|
61
|
+
|
|
62
|
+
const pathname = req.nextUrl.pathname;
|
|
63
|
+
|
|
64
|
+
if (matchPath(pathname, '/health')) {
|
|
61
65
|
return new Response('OK', {
|
|
62
66
|
status: 200,
|
|
63
67
|
});
|
|
64
|
-
} else if (
|
|
68
|
+
} else if (matchPath(pathname, '/init')) {
|
|
65
69
|
let ctx = {} as TCtx;
|
|
66
70
|
try {
|
|
67
71
|
ctx =
|
|
@@ -96,7 +100,7 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
96
100
|
res.headers.append('Set-Cookie', cookie);
|
|
97
101
|
}
|
|
98
102
|
return res;
|
|
99
|
-
} else if (
|
|
103
|
+
} else if (matchPath(pathname, '/request-upload')) {
|
|
100
104
|
const res = await requestUpload({
|
|
101
105
|
provider,
|
|
102
106
|
router: config.router,
|
|
@@ -109,7 +113,7 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
109
113
|
'Content-Type': 'application/json',
|
|
110
114
|
},
|
|
111
115
|
});
|
|
112
|
-
} else if (
|
|
116
|
+
} else if (matchPath(pathname, '/request-upload-parts')) {
|
|
113
117
|
const res = await requestUploadParts({
|
|
114
118
|
provider,
|
|
115
119
|
router: config.router,
|
|
@@ -122,7 +126,7 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
122
126
|
'Content-Type': 'application/json',
|
|
123
127
|
},
|
|
124
128
|
});
|
|
125
|
-
} else if (
|
|
129
|
+
} else if (matchPath(pathname, '/complete-multipart-upload')) {
|
|
126
130
|
await completeMultipartUpload({
|
|
127
131
|
provider,
|
|
128
132
|
router: config.router,
|
|
@@ -132,7 +136,7 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
132
136
|
return new Response(null, {
|
|
133
137
|
status: 200,
|
|
134
138
|
});
|
|
135
|
-
} else if (
|
|
139
|
+
} else if (matchPath(pathname, '/confirm-upload')) {
|
|
136
140
|
const res = await confirmUpload({
|
|
137
141
|
provider,
|
|
138
142
|
router: config.router,
|
|
@@ -145,7 +149,7 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
145
149
|
'Content-Type': 'application/json',
|
|
146
150
|
},
|
|
147
151
|
});
|
|
148
|
-
} else if (
|
|
152
|
+
} else if (matchPath(pathname, '/delete-file')) {
|
|
149
153
|
const res = await deleteFile({
|
|
150
154
|
provider,
|
|
151
155
|
router: config.router,
|
|
@@ -158,7 +162,7 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
158
162
|
'Content-Type': 'application/json',
|
|
159
163
|
},
|
|
160
164
|
});
|
|
161
|
-
} else if (
|
|
165
|
+
} else if (matchPath(pathname, '/proxy-file')) {
|
|
162
166
|
const url = req.nextUrl.searchParams.get('url');
|
|
163
167
|
if (typeof url === 'string') {
|
|
164
168
|
const proxyRes = await fetch(url, {
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from '@edgestore/shared';
|
|
9
9
|
import { type NextApiRequest, type NextApiResponse } from 'next/types';
|
|
10
10
|
import Logger, { type LogLevel } from '../../../libs/logger';
|
|
11
|
+
import { matchPath } from '../../../libs/utils';
|
|
11
12
|
import { EdgeStoreProvider } from '../../../providers/edgestore';
|
|
12
13
|
import {
|
|
13
14
|
completeMultipartUpload,
|
|
@@ -58,9 +59,10 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
58
59
|
'Error running the pages adapter. Make sure you are importing the correct adapter in your router configuration',
|
|
59
60
|
code: 'SERVER_ERROR',
|
|
60
61
|
});
|
|
61
|
-
|
|
62
|
+
const pathname = req.url ?? '';
|
|
63
|
+
if (matchPath(pathname, '/health')) {
|
|
62
64
|
res.send('OK');
|
|
63
|
-
} else if (
|
|
65
|
+
} else if (matchPath(pathname, '/init')) {
|
|
64
66
|
let ctx = {} as TCtx;
|
|
65
67
|
try {
|
|
66
68
|
ctx =
|
|
@@ -84,7 +86,7 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
84
86
|
token,
|
|
85
87
|
baseUrl,
|
|
86
88
|
});
|
|
87
|
-
} else if (
|
|
89
|
+
} else if (matchPath(pathname, '/request-upload')) {
|
|
88
90
|
res.json(
|
|
89
91
|
await requestUpload({
|
|
90
92
|
provider,
|
|
@@ -93,7 +95,7 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
93
95
|
ctxToken: req.cookies['edgestore-ctx'],
|
|
94
96
|
}),
|
|
95
97
|
);
|
|
96
|
-
} else if (
|
|
98
|
+
} else if (matchPath(pathname, '/request-upload-parts')) {
|
|
97
99
|
res.json(
|
|
98
100
|
await requestUploadParts({
|
|
99
101
|
provider,
|
|
@@ -102,7 +104,7 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
102
104
|
ctxToken: req.cookies['edgestore-ctx'],
|
|
103
105
|
}),
|
|
104
106
|
);
|
|
105
|
-
} else if (
|
|
107
|
+
} else if (matchPath(pathname, '/complete-multipart-upload')) {
|
|
106
108
|
await completeMultipartUpload({
|
|
107
109
|
provider,
|
|
108
110
|
router: config.router,
|
|
@@ -110,7 +112,7 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
110
112
|
ctxToken: req.cookies['edgestore-ctx'],
|
|
111
113
|
});
|
|
112
114
|
res.status(200).end();
|
|
113
|
-
} else if (
|
|
115
|
+
} else if (matchPath(pathname, '/confirm-upload')) {
|
|
114
116
|
res.json(
|
|
115
117
|
await confirmUpload({
|
|
116
118
|
provider,
|
|
@@ -119,7 +121,7 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
119
121
|
ctxToken: req.cookies['edgestore-ctx'],
|
|
120
122
|
}),
|
|
121
123
|
);
|
|
122
|
-
} else if (
|
|
124
|
+
} else if (matchPath(pathname, '/delete-file')) {
|
|
123
125
|
res.json(
|
|
124
126
|
await deleteFile({
|
|
125
127
|
provider,
|
|
@@ -128,7 +130,7 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
128
130
|
ctxToken: req.cookies['edgestore-ctx'],
|
|
129
131
|
}),
|
|
130
132
|
);
|
|
131
|
-
} else if (
|
|
133
|
+
} else if (matchPath(pathname, '/proxy-file')) {
|
|
132
134
|
const { url } = req.query;
|
|
133
135
|
if (typeof url === 'string') {
|
|
134
136
|
const proxyRes = await fetch(url, {
|
package/src/core/client/index.ts
CHANGED
|
@@ -31,7 +31,7 @@ export type UploadOptions = {
|
|
|
31
31
|
* But it might take some time for the CDN cache to be cleared.
|
|
32
32
|
* So maybe you will keep seeing the old file for a while.
|
|
33
33
|
*
|
|
34
|
-
* If you want to replace an existing file immediately leave the `manualFileName` option empty and use the `replaceTargetUrl` option.
|
|
34
|
+
* If you want to replace an existing file, immediately leave the `manualFileName` option empty and use the `replaceTargetUrl` option.
|
|
35
35
|
*/
|
|
36
36
|
manualFileName?: string;
|
|
37
37
|
/**
|
|
@@ -245,7 +245,7 @@ export function initEdgeStoreClient<TRouter extends AnyRouter>(config: {
|
|
|
245
245
|
/**
|
|
246
246
|
* The base URL of your application.
|
|
247
247
|
*
|
|
248
|
-
* This is only needed for getting protected files
|
|
248
|
+
* This is only needed for getting protected files in a development environment.
|
|
249
249
|
*
|
|
250
250
|
* @example http://localhost:3000/api/edgestore
|
|
251
251
|
*/
|
|
@@ -404,7 +404,7 @@ export function initEdgeStoreClient<TRouter extends AnyRouter>(config: {
|
|
|
404
404
|
|
|
405
405
|
/**
|
|
406
406
|
* Protected files need third-party cookies to work.
|
|
407
|
-
* Since third party cookies
|
|
407
|
+
* Since third party cookies don't work on localhost,
|
|
408
408
|
* we need to proxy the file through the server.
|
|
409
409
|
*/
|
|
410
410
|
function getUrl(url: string, baseUrl?: string) {
|
|
@@ -37,14 +37,14 @@ export type AWSProviderOptions = {
|
|
|
37
37
|
* Base URL to use for accessing files.
|
|
38
38
|
* Only needed if you are using a custom domain or cloudfront.
|
|
39
39
|
*
|
|
40
|
-
*
|
|
40
|
+
* It can also be set via the `EDGE_STORE_BASE_URL` environment variable.
|
|
41
41
|
*/
|
|
42
42
|
baseUrl?: string;
|
|
43
43
|
/**
|
|
44
44
|
* Secret to use for encrypting JWT tokens.
|
|
45
45
|
* Can be generated with `openssl rand -base64 32`.
|
|
46
46
|
*
|
|
47
|
-
*
|
|
47
|
+
* It can also be set via the `EDGE_STORE_JWT_SECRET` environment variable.
|
|
48
48
|
*/
|
|
49
49
|
jwtSecret?: string;
|
|
50
50
|
};
|