@edgestore/server 0.8.0 → 1.0.0-next.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/adapters/astro/index.d.ts +1 -1
- package/adapters/astro/index.js +1 -1
- package/adapters/express/index.d.ts +1 -1
- package/adapters/express/index.js +1 -1
- package/adapters/fastify/index.d.ts +1 -1
- package/adapters/fastify/index.js +1 -1
- package/adapters/hono/index.d.ts +1 -1
- package/adapters/hono/index.js +1 -1
- package/adapters/next/app/index.d.ts +1 -1
- package/adapters/next/app/index.js +1 -1
- package/adapters/next/pages/index.d.ts +1 -1
- package/adapters/next/pages/index.js +1 -1
- package/adapters/remix/index.d.ts +1 -1
- package/adapters/remix/index.js +1 -1
- package/adapters/start/index.d.ts +1 -1
- package/adapters/start/index.js +1 -1
- package/core/index.d.ts +1 -1
- package/core/index.js +1 -1
- package/dist/adapters/astro/index.d.ts +2 -2
- package/dist/adapters/astro/index.js +28 -30
- package/dist/adapters/express/index.d.ts +2 -2
- package/dist/adapters/express/index.js +28 -30
- package/dist/adapters/fastify/index.d.ts +2 -2
- package/dist/adapters/fastify/index.js +28 -30
- package/dist/adapters/hono/index.d.ts +2 -2
- package/dist/adapters/hono/index.js +28 -30
- package/dist/adapters/imageTypes.js +1 -3
- package/dist/adapters/next/app/index.d.ts +2 -2
- package/dist/adapters/next/app/index.js +29 -31
- package/dist/adapters/next/pages/index.d.ts +2 -2
- package/dist/adapters/next/pages/index.js +29 -31
- package/dist/adapters/remix/index.d.ts +2 -2
- package/dist/adapters/remix/index.js +28 -30
- package/dist/adapters/shared.d.ts.map +1 -1
- package/dist/adapters/shared.js +44 -50
- package/dist/adapters/start/index.d.ts +2 -2
- package/dist/adapters/start/index.js +28 -30
- package/dist/core/client/index.d.ts.map +1 -1
- package/dist/core/client/index.js +7 -9
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +2 -10
- package/dist/core/sdk/index.d.ts.map +1 -1
- package/dist/core/sdk/index.js +10 -13
- package/dist/index.js +1 -10
- package/dist/libs/errors/EdgeStoreCredentialsError.js +1 -3
- package/dist/libs/logger.js +5 -9
- package/dist/libs/utils.js +1 -3
- package/dist/providers/aws/index.d.ts.map +1 -1
- package/dist/providers/aws/index.js +12 -15
- package/dist/providers/azure/index.d.ts.map +1 -1
- package/dist/providers/azure/index.js +6 -9
- package/dist/providers/edgestore/index.js +12 -14
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +2 -5
- package/package.json +51 -50
- package/providers/aws/index.d.ts +1 -1
- package/providers/aws/index.js +1 -1
- package/providers/azure/index.d.ts +1 -1
- package/providers/azure/index.js +1 -1
- package/providers/edgestore/index.d.ts +1 -1
- package/providers/edgestore/index.js +1 -1
- package/src/adapters/shared.ts +12 -13
- package/src/core/client/index.ts +0 -1
- package/src/core/sdk/index.ts +1 -8
- package/src/providers/aws/index.ts +1 -2
- package/src/providers/azure/index.ts +1 -2
- package/src/version.ts +1 -1
- package/dist/adapters/astro/index.mjs +0 -172
- package/dist/adapters/express/index.mjs +0 -108
- package/dist/adapters/fastify/index.mjs +0 -135
- package/dist/adapters/hono/index.mjs +0 -131
- package/dist/adapters/imageTypes.mjs +0 -12
- package/dist/adapters/next/app/index.mjs +0 -163
- package/dist/adapters/next/pages/index.mjs +0 -112
- package/dist/adapters/remix/index.mjs +0 -148
- package/dist/adapters/shared.mjs +0 -471
- package/dist/adapters/start/index.mjs +0 -181
- package/dist/core/client/index.mjs +0 -221
- package/dist/core/index.mjs +0 -2
- package/dist/core/sdk/index.mjs +0 -253
- package/dist/index.mjs +0 -1
- package/dist/libs/errors/EdgeStoreCredentialsError.mjs +0 -10
- package/dist/libs/logger.mjs +0 -53
- package/dist/libs/utils.mjs +0 -10
- package/dist/providers/aws/index.mjs +0 -103
- package/dist/providers/azure/index.mjs +0 -85
- package/dist/providers/edgestore/index.mjs +0 -164
- package/dist/version.mjs +0 -4
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { EdgeStoreError, EDGE_STORE_ERROR_CODES } from '@edgestore/shared';
|
|
2
|
-
import Logger from '../../../libs/logger.mjs';
|
|
3
|
-
import { matchPath } from '../../../libs/utils.mjs';
|
|
4
|
-
import { EdgeStoreProvider } from '../../../providers/edgestore/index.mjs';
|
|
5
|
-
import { getCookieConfig, init, requestUpload, requestUploadParts, completeMultipartUpload, confirmUpload, deleteFile, fetchProxyFile } from '../../shared.mjs';
|
|
6
|
-
|
|
7
|
-
function createEdgeStoreNextHandler(config) {
|
|
8
|
-
const { provider = EdgeStoreProvider(), cookieConfig } = config;
|
|
9
|
-
const log = new Logger(config.logLevel);
|
|
10
|
-
globalThis._EDGE_STORE_LOGGER = log;
|
|
11
|
-
log.debug('Creating EdgeStore Next handler (app adapter)');
|
|
12
|
-
const resolvedCookieConfig = getCookieConfig(cookieConfig);
|
|
13
|
-
return async (req)=>{
|
|
14
|
-
try {
|
|
15
|
-
if (!('nextUrl' in req)) throw new EdgeStoreError({
|
|
16
|
-
message: 'Error running the app adapter. Make sure you are importing the correct adapter in your router configuration',
|
|
17
|
-
code: 'SERVER_ERROR'
|
|
18
|
-
});
|
|
19
|
-
const pathname = req.nextUrl.pathname;
|
|
20
|
-
if (matchPath(pathname, '/health')) {
|
|
21
|
-
return new Response('OK', {
|
|
22
|
-
status: 200
|
|
23
|
-
});
|
|
24
|
-
} else if (matchPath(pathname, '/init')) {
|
|
25
|
-
let ctx = {};
|
|
26
|
-
try {
|
|
27
|
-
ctx = 'createContext' in config ? await config.createContext({
|
|
28
|
-
req
|
|
29
|
-
}) : {};
|
|
30
|
-
} catch (err) {
|
|
31
|
-
throw new EdgeStoreError({
|
|
32
|
-
message: 'Error creating context',
|
|
33
|
-
code: 'CREATE_CONTEXT_ERROR',
|
|
34
|
-
cause: err instanceof Error ? err : undefined
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
const { newCookies, ...body } = await init({
|
|
38
|
-
ctx,
|
|
39
|
-
provider,
|
|
40
|
-
router: config.router,
|
|
41
|
-
cookieConfig
|
|
42
|
-
});
|
|
43
|
-
const res = new Response(JSON.stringify(body), {
|
|
44
|
-
status: 200,
|
|
45
|
-
headers: {
|
|
46
|
-
'Content-Type': 'application/json'
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
for (const cookie of newCookies){
|
|
50
|
-
res.headers.append('Set-Cookie', cookie);
|
|
51
|
-
}
|
|
52
|
-
return res;
|
|
53
|
-
} else if (matchPath(pathname, '/request-upload')) {
|
|
54
|
-
const res = await requestUpload({
|
|
55
|
-
provider,
|
|
56
|
-
router: config.router,
|
|
57
|
-
body: await req.json(),
|
|
58
|
-
ctxToken: req.cookies.get(resolvedCookieConfig.ctx.name)?.value
|
|
59
|
-
});
|
|
60
|
-
return new Response(JSON.stringify(res), {
|
|
61
|
-
status: 200,
|
|
62
|
-
headers: {
|
|
63
|
-
'Content-Type': 'application/json'
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
} else if (matchPath(pathname, '/request-upload-parts')) {
|
|
67
|
-
const res = await requestUploadParts({
|
|
68
|
-
provider,
|
|
69
|
-
router: config.router,
|
|
70
|
-
body: await req.json(),
|
|
71
|
-
ctxToken: req.cookies.get(resolvedCookieConfig.ctx.name)?.value
|
|
72
|
-
});
|
|
73
|
-
return new Response(JSON.stringify(res), {
|
|
74
|
-
status: 200,
|
|
75
|
-
headers: {
|
|
76
|
-
'Content-Type': 'application/json'
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
} else if (matchPath(pathname, '/complete-multipart-upload')) {
|
|
80
|
-
await completeMultipartUpload({
|
|
81
|
-
provider,
|
|
82
|
-
router: config.router,
|
|
83
|
-
body: await req.json(),
|
|
84
|
-
ctxToken: req.cookies.get(resolvedCookieConfig.ctx.name)?.value
|
|
85
|
-
});
|
|
86
|
-
return new Response(null, {
|
|
87
|
-
status: 200
|
|
88
|
-
});
|
|
89
|
-
} else if (matchPath(pathname, '/confirm-upload')) {
|
|
90
|
-
const res = await confirmUpload({
|
|
91
|
-
provider,
|
|
92
|
-
router: config.router,
|
|
93
|
-
body: await req.json(),
|
|
94
|
-
ctxToken: req.cookies.get(resolvedCookieConfig.ctx.name)?.value
|
|
95
|
-
});
|
|
96
|
-
return new Response(JSON.stringify(res), {
|
|
97
|
-
status: 200,
|
|
98
|
-
headers: {
|
|
99
|
-
'Content-Type': 'application/json'
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
} else if (matchPath(pathname, '/delete-file')) {
|
|
103
|
-
const res = await deleteFile({
|
|
104
|
-
provider,
|
|
105
|
-
router: config.router,
|
|
106
|
-
body: await req.json(),
|
|
107
|
-
ctxToken: req.cookies.get(resolvedCookieConfig.ctx.name)?.value
|
|
108
|
-
});
|
|
109
|
-
return new Response(JSON.stringify(res), {
|
|
110
|
-
status: 200,
|
|
111
|
-
headers: {
|
|
112
|
-
'Content-Type': 'application/json'
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
} else if (matchPath(pathname, '/proxy-file')) {
|
|
116
|
-
const url = req.nextUrl.searchParams.get('url');
|
|
117
|
-
if (typeof url === 'string') {
|
|
118
|
-
const proxyRes = await fetchProxyFile({
|
|
119
|
-
cookieHeader: req.cookies.toString(),
|
|
120
|
-
url
|
|
121
|
-
});
|
|
122
|
-
return new Response(proxyRes.body, {
|
|
123
|
-
status: proxyRes.status,
|
|
124
|
-
headers: {
|
|
125
|
-
'Content-Type': proxyRes.contentType
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
} else {
|
|
129
|
-
return new Response(null, {
|
|
130
|
-
status: 400
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
} else {
|
|
134
|
-
return new Response(null, {
|
|
135
|
-
status: 404
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
} catch (err) {
|
|
139
|
-
if (err instanceof EdgeStoreError) {
|
|
140
|
-
log[err.level](err.formattedMessage());
|
|
141
|
-
if (err.cause) log[err.level](err.cause);
|
|
142
|
-
return new Response(JSON.stringify(err.formattedJson()), {
|
|
143
|
-
status: EDGE_STORE_ERROR_CODES[err.code],
|
|
144
|
-
headers: {
|
|
145
|
-
'Content-Type': 'application/json'
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
log.error(err);
|
|
150
|
-
return new Response(JSON.stringify(new EdgeStoreError({
|
|
151
|
-
message: 'Internal server error',
|
|
152
|
-
code: 'SERVER_ERROR'
|
|
153
|
-
}).formattedJson()), {
|
|
154
|
-
status: 500,
|
|
155
|
-
headers: {
|
|
156
|
-
'Content-Type': 'application/json'
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export { createEdgeStoreNextHandler };
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { EdgeStoreError, EDGE_STORE_ERROR_CODES } from '@edgestore/shared';
|
|
2
|
-
import Logger from '../../../libs/logger.mjs';
|
|
3
|
-
import { matchPath } from '../../../libs/utils.mjs';
|
|
4
|
-
import { EdgeStoreProvider } from '../../../providers/edgestore/index.mjs';
|
|
5
|
-
import { getCookieConfig, init, requestUpload, requestUploadParts, completeMultipartUpload, confirmUpload, deleteFile, fetchProxyFile } from '../../shared.mjs';
|
|
6
|
-
|
|
7
|
-
function createEdgeStoreNextHandler(config) {
|
|
8
|
-
const { provider = EdgeStoreProvider(), cookieConfig } = config;
|
|
9
|
-
const log = new Logger(config.logLevel);
|
|
10
|
-
globalThis._EDGE_STORE_LOGGER = log;
|
|
11
|
-
log.debug('Creating EdgeStore Next handler (pages adapter)');
|
|
12
|
-
const resolvedCookieConfig = getCookieConfig(cookieConfig);
|
|
13
|
-
return async (req, res)=>{
|
|
14
|
-
try {
|
|
15
|
-
if (!('json' in res)) throw new EdgeStoreError({
|
|
16
|
-
message: 'Error running the pages adapter. Make sure you are importing the correct adapter in your router configuration',
|
|
17
|
-
code: 'SERVER_ERROR'
|
|
18
|
-
});
|
|
19
|
-
const pathname = req.url ?? '';
|
|
20
|
-
if (matchPath(pathname, '/health')) {
|
|
21
|
-
res.send('OK');
|
|
22
|
-
} else if (matchPath(pathname, '/init')) {
|
|
23
|
-
let ctx = {};
|
|
24
|
-
try {
|
|
25
|
-
ctx = 'createContext' in config ? await config.createContext({
|
|
26
|
-
req,
|
|
27
|
-
res
|
|
28
|
-
}) : {};
|
|
29
|
-
} catch (err) {
|
|
30
|
-
throw new EdgeStoreError({
|
|
31
|
-
message: 'Error creating context',
|
|
32
|
-
code: 'CREATE_CONTEXT_ERROR',
|
|
33
|
-
cause: err instanceof Error ? err : undefined
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
const { newCookies, ...body } = await init({
|
|
37
|
-
ctx,
|
|
38
|
-
provider,
|
|
39
|
-
router: config.router,
|
|
40
|
-
cookieConfig
|
|
41
|
-
});
|
|
42
|
-
res.setHeader('Set-Cookie', newCookies);
|
|
43
|
-
res.json(body);
|
|
44
|
-
} else if (matchPath(pathname, '/request-upload')) {
|
|
45
|
-
res.json(await requestUpload({
|
|
46
|
-
provider,
|
|
47
|
-
router: config.router,
|
|
48
|
-
body: req.body,
|
|
49
|
-
ctxToken: req.cookies[resolvedCookieConfig.ctx.name]
|
|
50
|
-
}));
|
|
51
|
-
} else if (matchPath(pathname, '/request-upload-parts')) {
|
|
52
|
-
res.json(await requestUploadParts({
|
|
53
|
-
provider,
|
|
54
|
-
router: config.router,
|
|
55
|
-
body: req.body,
|
|
56
|
-
ctxToken: req.cookies[resolvedCookieConfig.ctx.name]
|
|
57
|
-
}));
|
|
58
|
-
} else if (matchPath(pathname, '/complete-multipart-upload')) {
|
|
59
|
-
await completeMultipartUpload({
|
|
60
|
-
provider,
|
|
61
|
-
router: config.router,
|
|
62
|
-
body: req.body,
|
|
63
|
-
ctxToken: req.cookies[resolvedCookieConfig.ctx.name]
|
|
64
|
-
});
|
|
65
|
-
res.status(200).end();
|
|
66
|
-
} else if (matchPath(pathname, '/confirm-upload')) {
|
|
67
|
-
res.json(await confirmUpload({
|
|
68
|
-
provider,
|
|
69
|
-
router: config.router,
|
|
70
|
-
body: req.body,
|
|
71
|
-
ctxToken: req.cookies[resolvedCookieConfig.ctx.name]
|
|
72
|
-
}));
|
|
73
|
-
} else if (matchPath(pathname, '/delete-file')) {
|
|
74
|
-
res.json(await deleteFile({
|
|
75
|
-
provider,
|
|
76
|
-
router: config.router,
|
|
77
|
-
body: req.body,
|
|
78
|
-
ctxToken: req.cookies[resolvedCookieConfig.ctx.name]
|
|
79
|
-
}));
|
|
80
|
-
} else if (matchPath(pathname, '/proxy-file')) {
|
|
81
|
-
const { url } = req.query;
|
|
82
|
-
if (typeof url === 'string') {
|
|
83
|
-
const proxyRes = await fetchProxyFile({
|
|
84
|
-
cookieHeader: req.headers.cookie,
|
|
85
|
-
url
|
|
86
|
-
});
|
|
87
|
-
res.setHeader('Content-Type', proxyRes.contentType);
|
|
88
|
-
res.status(proxyRes.status);
|
|
89
|
-
res.end(proxyRes.body === null ? undefined : Buffer.from(proxyRes.body));
|
|
90
|
-
} else {
|
|
91
|
-
res.status(400).end();
|
|
92
|
-
}
|
|
93
|
-
} else {
|
|
94
|
-
res.status(404).end();
|
|
95
|
-
}
|
|
96
|
-
} catch (err) {
|
|
97
|
-
if (err instanceof EdgeStoreError) {
|
|
98
|
-
log[err.level](err.formattedMessage());
|
|
99
|
-
if (err.cause) log[err.level](err.cause);
|
|
100
|
-
res.status(EDGE_STORE_ERROR_CODES[err.code]).json(err.formattedJson());
|
|
101
|
-
} else {
|
|
102
|
-
log.error(err);
|
|
103
|
-
res.status(500).send(new EdgeStoreError({
|
|
104
|
-
message: 'Internal Server Error',
|
|
105
|
-
code: 'SERVER_ERROR'
|
|
106
|
-
}).formattedJson());
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export { createEdgeStoreNextHandler };
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { EdgeStoreError, EDGE_STORE_ERROR_CODES } from '@edgestore/shared';
|
|
2
|
-
import Logger from '../../libs/logger.mjs';
|
|
3
|
-
import { matchPath } from '../../libs/utils.mjs';
|
|
4
|
-
import { EdgeStoreProvider } from '../../providers/edgestore/index.mjs';
|
|
5
|
-
import { getCookieConfig, init, requestUpload, requestUploadParts, completeMultipartUpload, confirmUpload, deleteFile, fetchProxyFile } from '../shared.mjs';
|
|
6
|
-
|
|
7
|
-
// Helper to safely get cookies from Remix request
|
|
8
|
-
function getCookie(req, name) {
|
|
9
|
-
const cookieHeader = req.headers.get('cookie');
|
|
10
|
-
if (!cookieHeader) return undefined;
|
|
11
|
-
const cookies = cookieHeader.split(';').reduce((acc, cookie)=>{
|
|
12
|
-
const [key, value] = cookie.trim().split('=');
|
|
13
|
-
if (key && value) acc[key] = value;
|
|
14
|
-
return acc;
|
|
15
|
-
}, {});
|
|
16
|
-
return cookies[name];
|
|
17
|
-
}
|
|
18
|
-
function createEdgeStoreRemixHandler(config) {
|
|
19
|
-
const { provider = EdgeStoreProvider(), cookieConfig } = config;
|
|
20
|
-
const log = new Logger(config.logLevel);
|
|
21
|
-
globalThis._EDGE_STORE_LOGGER = log;
|
|
22
|
-
log.debug('Creating EdgeStore Remix handler');
|
|
23
|
-
const resolvedCookieConfig = getCookieConfig(cookieConfig);
|
|
24
|
-
return async ({ request: req })=>{
|
|
25
|
-
try {
|
|
26
|
-
const url = new URL(req.url);
|
|
27
|
-
const pathname = url.pathname;
|
|
28
|
-
if (matchPath(pathname, '/health')) {
|
|
29
|
-
return new Response('OK');
|
|
30
|
-
} else if (matchPath(pathname, '/init')) {
|
|
31
|
-
let ctx = {};
|
|
32
|
-
try {
|
|
33
|
-
ctx = 'createContext' in config ? await config.createContext({
|
|
34
|
-
req
|
|
35
|
-
}) : {};
|
|
36
|
-
} catch (err) {
|
|
37
|
-
throw new EdgeStoreError({
|
|
38
|
-
message: 'Error creating context',
|
|
39
|
-
code: 'CREATE_CONTEXT_ERROR',
|
|
40
|
-
cause: err instanceof Error ? err : undefined
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
const { newCookies, ...body } = await init({
|
|
44
|
-
ctx,
|
|
45
|
-
provider,
|
|
46
|
-
router: config.router,
|
|
47
|
-
cookieConfig
|
|
48
|
-
});
|
|
49
|
-
// Create response with cookies and token
|
|
50
|
-
const responseHeaders = new Headers();
|
|
51
|
-
if (Array.isArray(newCookies)) {
|
|
52
|
-
for (const cookie of newCookies){
|
|
53
|
-
responseHeaders.append('Set-Cookie', cookie);
|
|
54
|
-
}
|
|
55
|
-
} else if (newCookies) {
|
|
56
|
-
responseHeaders.append('Set-Cookie', newCookies);
|
|
57
|
-
}
|
|
58
|
-
return new Response(JSON.stringify(body), {
|
|
59
|
-
headers: responseHeaders,
|
|
60
|
-
status: 200
|
|
61
|
-
});
|
|
62
|
-
} else if (matchPath(pathname, '/request-upload')) {
|
|
63
|
-
const body = await req.json();
|
|
64
|
-
return Response.json(await requestUpload({
|
|
65
|
-
provider,
|
|
66
|
-
router: config.router,
|
|
67
|
-
body,
|
|
68
|
-
ctxToken: getCookie(req, resolvedCookieConfig.ctx.name)
|
|
69
|
-
}));
|
|
70
|
-
} else if (matchPath(pathname, '/request-upload-parts')) {
|
|
71
|
-
const body = await req.json();
|
|
72
|
-
return Response.json(await requestUploadParts({
|
|
73
|
-
provider,
|
|
74
|
-
router: config.router,
|
|
75
|
-
body,
|
|
76
|
-
ctxToken: getCookie(req, resolvedCookieConfig.ctx.name)
|
|
77
|
-
}));
|
|
78
|
-
} else if (matchPath(pathname, '/complete-multipart-upload')) {
|
|
79
|
-
const body = await req.json();
|
|
80
|
-
await completeMultipartUpload({
|
|
81
|
-
provider,
|
|
82
|
-
router: config.router,
|
|
83
|
-
body,
|
|
84
|
-
ctxToken: getCookie(req, resolvedCookieConfig.ctx.name)
|
|
85
|
-
});
|
|
86
|
-
return new Response(null, {
|
|
87
|
-
status: 200
|
|
88
|
-
});
|
|
89
|
-
} else if (matchPath(pathname, '/confirm-upload')) {
|
|
90
|
-
const body = await req.json();
|
|
91
|
-
return Response.json(await confirmUpload({
|
|
92
|
-
provider,
|
|
93
|
-
router: config.router,
|
|
94
|
-
body,
|
|
95
|
-
ctxToken: getCookie(req, resolvedCookieConfig.ctx.name)
|
|
96
|
-
}));
|
|
97
|
-
} else if (matchPath(pathname, '/delete-file')) {
|
|
98
|
-
const body = await req.json();
|
|
99
|
-
return Response.json(await deleteFile({
|
|
100
|
-
provider,
|
|
101
|
-
router: config.router,
|
|
102
|
-
body,
|
|
103
|
-
ctxToken: getCookie(req, resolvedCookieConfig.ctx.name)
|
|
104
|
-
}));
|
|
105
|
-
} else if (matchPath(pathname, '/proxy-file')) {
|
|
106
|
-
const url = new URL(req.url).searchParams.get('url');
|
|
107
|
-
if (typeof url === 'string') {
|
|
108
|
-
const proxyRes = await fetchProxyFile({
|
|
109
|
-
cookieHeader: req.headers.get('cookie') ?? undefined,
|
|
110
|
-
url
|
|
111
|
-
});
|
|
112
|
-
const headers = new Headers();
|
|
113
|
-
headers.set('Content-Type', proxyRes.contentType);
|
|
114
|
-
return new Response(proxyRes.body, {
|
|
115
|
-
headers,
|
|
116
|
-
status: proxyRes.status
|
|
117
|
-
});
|
|
118
|
-
} else {
|
|
119
|
-
return new Response(null, {
|
|
120
|
-
status: 400
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
} else {
|
|
124
|
-
return new Response(null, {
|
|
125
|
-
status: 404
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
} catch (err) {
|
|
129
|
-
if (err instanceof EdgeStoreError) {
|
|
130
|
-
log[err.level](err.formattedMessage());
|
|
131
|
-
if (err.cause) log[err.level](err.cause);
|
|
132
|
-
return Response.json(err.formattedJson(), {
|
|
133
|
-
status: EDGE_STORE_ERROR_CODES[err.code]
|
|
134
|
-
});
|
|
135
|
-
} else {
|
|
136
|
-
log.error(err);
|
|
137
|
-
return Response.json(new EdgeStoreError({
|
|
138
|
-
message: 'Internal Server Error',
|
|
139
|
-
code: 'SERVER_ERROR'
|
|
140
|
-
}).formattedJson(), {
|
|
141
|
-
status: 500
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export { createEdgeStoreRemixHandler };
|