@edgestore/server 1.0.0-next.0 → 1.0.0-next.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 +10 -4
- package/dist/adapters/astro/index.d.ts +7 -12
- package/dist/adapters/astro/index.d.ts.map +1 -1
- package/dist/adapters/astro/index.js +14 -161
- package/dist/adapters/dispatcher.d.ts +30 -0
- package/dist/adapters/dispatcher.d.ts.map +1 -0
- package/dist/adapters/dispatcher.js +172 -0
- package/dist/adapters/express/index.d.ts +7 -12
- package/dist/adapters/express/index.d.ts.map +1 -1
- package/dist/adapters/express/index.js +24 -94
- package/dist/adapters/fastify/index.d.ts +7 -12
- package/dist/adapters/fastify/index.d.ts.map +1 -1
- package/dist/adapters/fastify/index.js +23 -121
- package/dist/adapters/hono/index.d.ts +7 -12
- package/dist/adapters/hono/index.d.ts.map +1 -1
- package/dist/adapters/hono/index.js +14 -121
- package/dist/adapters/next/app/index.d.ts +7 -12
- package/dist/adapters/next/app/index.d.ts.map +1 -1
- package/dist/adapters/next/app/index.js +21 -148
- package/dist/adapters/next/pages/index.d.ts +7 -12
- package/dist/adapters/next/pages/index.d.ts.map +1 -1
- package/dist/adapters/next/pages/index.js +34 -95
- package/dist/adapters/remix/index.d.ts +7 -12
- package/dist/adapters/remix/index.d.ts.map +1 -1
- package/dist/adapters/remix/index.js +14 -136
- package/dist/adapters/shared.d.ts +140 -55
- package/dist/adapters/shared.d.ts.map +1 -1
- package/dist/adapters/shared.js +188 -179
- package/dist/adapters/start/index.d.ts +7 -12
- package/dist/adapters/start/index.d.ts.map +1 -1
- package/dist/adapters/start/index.js +14 -169
- package/dist/core/client/bucketClient.d.ts +7 -0
- package/dist/core/client/bucketClient.d.ts.map +1 -0
- package/dist/core/client/bucketClient.js +312 -0
- package/dist/core/client/index.d.ts +119 -140
- package/dist/core/client/index.d.ts.map +1 -1
- package/dist/core/client/index.js +13 -218
- package/dist/core/index.d.ts +20 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +14 -2
- package/dist/core/provider.d.ts +15 -0
- package/dist/core/provider.d.ts.map +1 -0
- package/dist/core/provider.js +25 -0
- package/dist/core/routerRules.d.ts +21 -0
- package/dist/core/routerRules.d.ts.map +1 -0
- package/dist/core/routerRules.js +54 -0
- package/dist/core/validateFile.d.ts +9 -0
- package/dist/core/validateFile.d.ts.map +1 -0
- package/dist/core/validateFile.js +43 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/libs/env.d.ts +3 -0
- package/dist/libs/env.d.ts.map +1 -0
- package/dist/libs/env.js +14 -0
- package/dist/libs/logger.d.ts +2 -1
- package/dist/libs/logger.d.ts.map +1 -1
- package/dist/libs/logger.js +1 -1
- package/dist/providers/azure-blob/index.d.ts +119 -0
- package/dist/providers/azure-blob/index.d.ts.map +1 -0
- package/dist/providers/azure-blob/index.js +166 -0
- package/dist/providers/edgestore/index.d.ts +171 -3
- package/dist/providers/edgestore/index.d.ts.map +1 -1
- package/dist/providers/edgestore/index.js +304 -136
- package/dist/providers/{aws → s3}/index.d.ts +68 -11
- package/dist/providers/s3/index.d.ts.map +1 -0
- package/dist/providers/s3/index.js +146 -0
- package/dist/test-utils/edgestoreSmoke.d.ts +0 -2
- package/dist/test-utils/edgestoreSmoke.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +13 -12
- package/providers/azure-blob/index.d.ts +1 -0
- package/providers/azure-blob/index.js +1 -0
- package/providers/s3/index.d.ts +1 -0
- package/providers/s3/index.js +1 -0
- package/src/adapters/astro/index.ts +27 -211
- package/src/adapters/dispatcher.ts +261 -0
- package/src/adapters/express/index.ts +43 -149
- package/src/adapters/fastify/index.ts +43 -191
- package/src/adapters/hono/index.ts +28 -183
- package/src/adapters/next/app/index.ts +37 -201
- package/src/adapters/next/pages/index.ts +55 -156
- package/src/adapters/remix/index.ts +27 -190
- package/src/adapters/shared.ts +237 -261
- package/src/adapters/start/index.ts +28 -200
- package/src/core/client/bucketClient.ts +480 -0
- package/src/core/client/index.ts +300 -427
- package/src/core/index.ts +42 -1
- package/src/core/provider.ts +80 -0
- package/src/core/routerRules.ts +75 -0
- package/src/core/validateFile.ts +50 -0
- package/src/index.ts +10 -0
- package/src/libs/env.ts +16 -0
- package/src/libs/logger.ts +4 -2
- package/src/providers/azure-blob/index.ts +265 -0
- package/src/providers/edgestore/index.ts +426 -154
- package/src/providers/s3/index.ts +289 -0
- package/src/test-utils/edgestoreSmoke.ts +0 -11
- package/src/version.ts +1 -1
- package/dist/core/sdk/index.d.ts +0 -282
- package/dist/core/sdk/index.d.ts.map +0 -1
- package/dist/core/sdk/index.js +0 -253
- package/dist/providers/aws/index.d.ts.map +0 -1
- package/dist/providers/aws/index.js +0 -102
- package/dist/providers/azure/index.d.ts +0 -39
- package/dist/providers/azure/index.d.ts.map +0 -1
- package/dist/providers/azure/index.js +0 -84
- package/dist/version.js +0 -4
- package/providers/aws/index.d.ts +0 -1
- package/providers/aws/index.js +0 -1
- package/providers/azure/index.d.ts +0 -1
- package/providers/azure/index.js +0 -1
- package/src/core/sdk/index.ts +0 -542
- package/src/providers/aws/index.ts +0 -239
- package/src/providers/azure/index.ts +0 -141
|
@@ -1,211 +1,63 @@
|
|
|
1
|
-
import {
|
|
2
|
-
EDGE_STORE_ERROR_CODES,
|
|
3
|
-
EdgeStoreError,
|
|
4
|
-
type EdgeStoreErrorCodeKey,
|
|
5
|
-
type EdgeStoreRouter,
|
|
6
|
-
type MaybePromise,
|
|
7
|
-
type Provider,
|
|
8
|
-
} from '@edgestore/shared';
|
|
1
|
+
import { type AnyContext } from '@edgestore/shared';
|
|
9
2
|
import { type FastifyReply, type FastifyRequest } from 'fastify';
|
|
10
3
|
import Logger, { type LogLevel } from '../../libs/logger';
|
|
11
|
-
import { matchPath } from '../../libs/utils';
|
|
12
|
-
import { EdgeStoreProvider } from '../../providers/edgestore';
|
|
13
4
|
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
requestUpload,
|
|
21
|
-
requestUploadParts,
|
|
22
|
-
type CompleteMultipartUploadBody,
|
|
23
|
-
type ConfirmUploadBody,
|
|
24
|
-
type CookieConfig,
|
|
25
|
-
type DeleteFileBody,
|
|
26
|
-
type RequestUploadBody,
|
|
27
|
-
type RequestUploadPartsParams,
|
|
28
|
-
} from '../shared';
|
|
5
|
+
dispatchEdgeStoreRequest,
|
|
6
|
+
resolveContext,
|
|
7
|
+
toNodeDispatchResponse,
|
|
8
|
+
type CreateContextConfig,
|
|
9
|
+
} from '../dispatcher';
|
|
10
|
+
import type { CookieConfig, HandlerEdgeStore } from '../shared';
|
|
29
11
|
|
|
30
12
|
export type CreateContextOptions = {
|
|
31
13
|
req: FastifyRequest;
|
|
32
14
|
reply: FastifyReply;
|
|
33
15
|
};
|
|
34
16
|
|
|
35
|
-
export type Config<TCtx> = {
|
|
36
|
-
|
|
37
|
-
router: EdgeStoreRouter<TCtx>;
|
|
17
|
+
export type Config<TCtx extends AnyContext> = {
|
|
18
|
+
edgestore: HandlerEdgeStore<TCtx>;
|
|
38
19
|
logLevel?: LogLevel;
|
|
39
20
|
cookieConfig?: CookieConfig;
|
|
40
|
-
} &
|
|
41
|
-
? object
|
|
42
|
-
: {
|
|
43
|
-
provider?: Provider;
|
|
44
|
-
router: EdgeStoreRouter<TCtx>;
|
|
45
|
-
createContext: (opts: CreateContextOptions) => MaybePromise<TCtx>;
|
|
46
|
-
cookieConfig?: CookieConfig;
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
declare const globalThis: {
|
|
50
|
-
_EDGE_STORE_LOGGER: Logger;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
// Helper to safely get cookies from Fastify request
|
|
54
|
-
function getCookie(req: FastifyRequest, name: string): string | undefined {
|
|
55
|
-
// Check if cookies plugin is available
|
|
56
|
-
if ('cookies' in req) {
|
|
57
|
-
// Type assertion for TypeScript
|
|
58
|
-
return (req as any).cookies[name];
|
|
59
|
-
}
|
|
21
|
+
} & CreateContextConfig<TCtx, CreateContextOptions>;
|
|
60
22
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const cookies = cookieHeader
|
|
66
|
-
.split(';')
|
|
67
|
-
.reduce<Record<string, string>>((acc, cookie) => {
|
|
68
|
-
const [key, value] = cookie.trim().split('=');
|
|
69
|
-
if (key && value) acc[key] = value;
|
|
70
|
-
return acc;
|
|
71
|
-
}, {});
|
|
72
|
-
|
|
73
|
-
return cookies[name];
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function createEdgeStoreFastifyHandler<TCtx>(config: Config<TCtx>) {
|
|
77
|
-
const { provider = EdgeStoreProvider(), cookieConfig } = config;
|
|
23
|
+
export function createEdgeStoreFastifyHandler<TCtx extends AnyContext>(
|
|
24
|
+
config: Config<TCtx>,
|
|
25
|
+
) {
|
|
78
26
|
const log = new Logger(config.logLevel);
|
|
79
|
-
globalThis._EDGE_STORE_LOGGER = log;
|
|
80
27
|
log.debug('Creating EdgeStore Fastify handler');
|
|
81
28
|
|
|
82
|
-
const resolvedCookieConfig = getCookieConfig(cookieConfig);
|
|
83
|
-
|
|
84
29
|
return async (req: FastifyRequest, reply: FastifyReply): Promise<void> => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
router: config.router,
|
|
109
|
-
cookieConfig,
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
// Set cookies more efficiently - handling them using void operator
|
|
113
|
-
// to explicitly mark these synchronous calls as intentionally not awaited
|
|
114
|
-
if (Array.isArray(newCookies)) {
|
|
115
|
-
// If it's an array of cookies, set them all
|
|
116
|
-
for (const cookie of newCookies) {
|
|
117
|
-
void reply.header('Set-Cookie', cookie);
|
|
118
|
-
}
|
|
119
|
-
} else if (newCookies) {
|
|
120
|
-
// If it's a single cookie string
|
|
121
|
-
void reply.header('Set-Cookie', newCookies);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return reply.send(body);
|
|
125
|
-
} else if (matchPath(pathname, '/request-upload')) {
|
|
126
|
-
return reply.send(
|
|
127
|
-
await requestUpload({
|
|
128
|
-
provider,
|
|
129
|
-
router: config.router,
|
|
130
|
-
body: req.body as RequestUploadBody,
|
|
131
|
-
ctxToken: getCookie(req, resolvedCookieConfig.ctx.name),
|
|
132
|
-
}),
|
|
133
|
-
);
|
|
134
|
-
} else if (matchPath(pathname, '/request-upload-parts')) {
|
|
135
|
-
return reply.send(
|
|
136
|
-
await requestUploadParts({
|
|
137
|
-
provider,
|
|
138
|
-
router: config.router,
|
|
139
|
-
body: req.body as RequestUploadPartsParams,
|
|
140
|
-
ctxToken: getCookie(req, resolvedCookieConfig.ctx.name),
|
|
141
|
-
}),
|
|
142
|
-
);
|
|
143
|
-
} else if (matchPath(pathname, '/complete-multipart-upload')) {
|
|
144
|
-
await completeMultipartUpload({
|
|
145
|
-
provider,
|
|
146
|
-
router: config.router,
|
|
147
|
-
body: req.body as CompleteMultipartUploadBody,
|
|
148
|
-
ctxToken: getCookie(req, resolvedCookieConfig.ctx.name),
|
|
149
|
-
});
|
|
150
|
-
return reply.status(200).send();
|
|
151
|
-
} else if (matchPath(pathname, '/confirm-upload')) {
|
|
152
|
-
return reply.send(
|
|
153
|
-
await confirmUpload({
|
|
154
|
-
provider,
|
|
155
|
-
router: config.router,
|
|
156
|
-
body: req.body as ConfirmUploadBody,
|
|
157
|
-
ctxToken: getCookie(req, resolvedCookieConfig.ctx.name),
|
|
30
|
+
const url = new URL(req.url, 'http://edgestore.local');
|
|
31
|
+
const response = await dispatchEdgeStoreRequest<TCtx>({
|
|
32
|
+
edgestore: config.edgestore,
|
|
33
|
+
logger: log,
|
|
34
|
+
cookieConfig: config.cookieConfig,
|
|
35
|
+
request: {
|
|
36
|
+
pathname: url.pathname,
|
|
37
|
+
readJson: async () => req.body,
|
|
38
|
+
getQuery: (name) => {
|
|
39
|
+
const value = (req.query as Record<string, unknown>)[name];
|
|
40
|
+
return typeof value === 'string'
|
|
41
|
+
? value
|
|
42
|
+
: (url.searchParams.get(name) ?? undefined);
|
|
43
|
+
},
|
|
44
|
+
cookieHeader: req.headers.cookie,
|
|
45
|
+
cookies:
|
|
46
|
+
'cookies' in req
|
|
47
|
+
? (req.cookies as Record<string, string>)
|
|
48
|
+
: undefined,
|
|
49
|
+
createContext: () =>
|
|
50
|
+
resolveContext<TCtx, CreateContextOptions>(config, {
|
|
51
|
+
req,
|
|
52
|
+
reply,
|
|
158
53
|
}),
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
router: config.router,
|
|
165
|
-
body: req.body as DeleteFileBody,
|
|
166
|
-
ctxToken: getCookie(req, resolvedCookieConfig.ctx.name),
|
|
167
|
-
}),
|
|
168
|
-
);
|
|
169
|
-
} else if (matchPath(pathname, '/proxy-file')) {
|
|
170
|
-
const url = req.query
|
|
171
|
-
? (req.query as Record<string, any>).url
|
|
172
|
-
: undefined;
|
|
173
|
-
|
|
174
|
-
if (typeof url === 'string') {
|
|
175
|
-
const proxyRes = await fetchProxyFile({
|
|
176
|
-
cookieHeader: req.headers.cookie,
|
|
177
|
-
url,
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
void reply.header('Content-Type', proxyRes.contentType);
|
|
181
|
-
|
|
182
|
-
return reply
|
|
183
|
-
.status(proxyRes.status)
|
|
184
|
-
.send(
|
|
185
|
-
proxyRes.body === null ? undefined : Buffer.from(proxyRes.body),
|
|
186
|
-
);
|
|
187
|
-
} else {
|
|
188
|
-
return reply.status(400).send();
|
|
189
|
-
}
|
|
190
|
-
} else {
|
|
191
|
-
return reply.status(404).send();
|
|
192
|
-
}
|
|
193
|
-
} catch (err) {
|
|
194
|
-
if (err instanceof EdgeStoreError) {
|
|
195
|
-
log[err.level](err.formattedMessage());
|
|
196
|
-
if (err.cause) log[err.level](err.cause);
|
|
197
|
-
return reply
|
|
198
|
-
.status(EDGE_STORE_ERROR_CODES[err.code as EdgeStoreErrorCodeKey])
|
|
199
|
-
.send(err.formattedJson());
|
|
200
|
-
} else {
|
|
201
|
-
log.error(err);
|
|
202
|
-
return reply.status(500).send(
|
|
203
|
-
new EdgeStoreError({
|
|
204
|
-
message: 'Internal Server Error',
|
|
205
|
-
code: 'SERVER_ERROR',
|
|
206
|
-
}).formattedJson(),
|
|
207
|
-
);
|
|
208
|
-
}
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
const normalized = await toNodeDispatchResponse(response);
|
|
57
|
+
for (const [name, value] of normalized.headers) {
|
|
58
|
+
void reply.header(name, value);
|
|
209
59
|
}
|
|
60
|
+
void reply.status(normalized.status);
|
|
61
|
+
return reply.send(normalized.body);
|
|
210
62
|
};
|
|
211
63
|
}
|
|
@@ -1,199 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
EDGE_STORE_ERROR_CODES,
|
|
3
|
-
EdgeStoreError,
|
|
4
|
-
type EdgeStoreErrorCodeKey,
|
|
5
|
-
type EdgeStoreRouter,
|
|
6
|
-
type MaybePromise,
|
|
7
|
-
type Provider,
|
|
8
|
-
} from '@edgestore/shared';
|
|
1
|
+
import { type AnyContext } from '@edgestore/shared';
|
|
9
2
|
import { type Context as HonoContext } from 'hono';
|
|
10
3
|
import Logger, { type LogLevel } from '../../libs/logger';
|
|
11
|
-
import { matchPath } from '../../libs/utils';
|
|
12
|
-
import { EdgeStoreProvider } from '../../providers/edgestore';
|
|
13
4
|
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
init,
|
|
20
|
-
requestUpload,
|
|
21
|
-
requestUploadParts,
|
|
22
|
-
type CompleteMultipartUploadBody,
|
|
23
|
-
type ConfirmUploadBody,
|
|
24
|
-
type CookieConfig,
|
|
25
|
-
type DeleteFileBody,
|
|
26
|
-
type RequestUploadBody,
|
|
27
|
-
type RequestUploadPartsParams,
|
|
28
|
-
} from '../shared';
|
|
5
|
+
dispatchEdgeStoreRequest,
|
|
6
|
+
resolveContext,
|
|
7
|
+
type CreateContextConfig,
|
|
8
|
+
} from '../dispatcher';
|
|
9
|
+
import { type CookieConfig, type HandlerEdgeStore } from '../shared';
|
|
29
10
|
|
|
30
11
|
export type CreateContextOptions = {
|
|
31
12
|
c: HonoContext;
|
|
32
13
|
};
|
|
33
14
|
|
|
34
|
-
export type Config<TCtx> = {
|
|
35
|
-
|
|
36
|
-
router: EdgeStoreRouter<TCtx>;
|
|
15
|
+
export type Config<TCtx extends AnyContext> = {
|
|
16
|
+
edgestore: HandlerEdgeStore<TCtx>;
|
|
37
17
|
logLevel?: LogLevel;
|
|
38
18
|
cookieConfig?: CookieConfig;
|
|
39
|
-
} &
|
|
40
|
-
? object
|
|
41
|
-
: {
|
|
42
|
-
provider?: Provider;
|
|
43
|
-
router: EdgeStoreRouter<TCtx>;
|
|
44
|
-
createContext: (opts: CreateContextOptions) => MaybePromise<TCtx>;
|
|
45
|
-
cookieConfig?: CookieConfig;
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
declare const globalThis: {
|
|
49
|
-
_EDGE_STORE_LOGGER: Logger;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
// Helper to get a cookie value from Hono Context
|
|
53
|
-
function getCookie(c: HonoContext, name: string): string | undefined {
|
|
54
|
-
const cookies = c.req.header('cookie');
|
|
55
|
-
if (!cookies) return undefined;
|
|
19
|
+
} & CreateContextConfig<TCtx, CreateContextOptions>;
|
|
56
20
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
export function createEdgeStoreHonoHandler<TCtx>(config: Config<TCtx>) {
|
|
62
|
-
const { provider = EdgeStoreProvider(), cookieConfig } = config;
|
|
21
|
+
export function createEdgeStoreHonoHandler<TCtx extends AnyContext>(
|
|
22
|
+
config: Config<TCtx>,
|
|
23
|
+
) {
|
|
24
|
+
const { cookieConfig } = config;
|
|
63
25
|
const log = new Logger(config.logLevel);
|
|
64
|
-
globalThis._EDGE_STORE_LOGGER = log;
|
|
65
26
|
log.debug('Creating EdgeStore Hono handler');
|
|
66
27
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
? await config.createContext({ c })
|
|
81
|
-
: ({} as TCtx);
|
|
82
|
-
} catch (err) {
|
|
83
|
-
throw new EdgeStoreError({
|
|
84
|
-
message: 'Error creating context',
|
|
85
|
-
code: 'CREATE_CONTEXT_ERROR',
|
|
86
|
-
cause: err instanceof Error ? err : undefined,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
const { newCookies, ...body } = await init({
|
|
90
|
-
ctx,
|
|
91
|
-
provider,
|
|
92
|
-
router: config.router,
|
|
93
|
-
cookieConfig,
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
// Set cookies
|
|
97
|
-
if (Array.isArray(newCookies)) {
|
|
98
|
-
for (const cookie of newCookies) {
|
|
99
|
-
c.header('Set-Cookie', cookie, { append: true });
|
|
100
|
-
}
|
|
101
|
-
} else if (newCookies) {
|
|
102
|
-
c.header('Set-Cookie', newCookies);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return c.json(body);
|
|
106
|
-
} else if (matchPath(pathname, '/request-upload')) {
|
|
107
|
-
const body = await c.req.json<RequestUploadBody>();
|
|
108
|
-
return c.json(
|
|
109
|
-
await requestUpload({
|
|
110
|
-
provider,
|
|
111
|
-
router: config.router,
|
|
112
|
-
body,
|
|
113
|
-
ctxToken: getCookie(c, resolvedCookieConfig.ctx.name),
|
|
114
|
-
}),
|
|
115
|
-
);
|
|
116
|
-
} else if (matchPath(pathname, '/request-upload-parts')) {
|
|
117
|
-
const body = await c.req.json<RequestUploadPartsParams>();
|
|
118
|
-
return c.json(
|
|
119
|
-
await requestUploadParts({
|
|
120
|
-
provider,
|
|
121
|
-
router: config.router,
|
|
122
|
-
body,
|
|
123
|
-
ctxToken: getCookie(c, resolvedCookieConfig.ctx.name),
|
|
124
|
-
}),
|
|
125
|
-
);
|
|
126
|
-
} else if (matchPath(pathname, '/complete-multipart-upload')) {
|
|
127
|
-
const body = await c.req.json<CompleteMultipartUploadBody>();
|
|
128
|
-
await completeMultipartUpload({
|
|
129
|
-
provider,
|
|
130
|
-
router: config.router,
|
|
131
|
-
body,
|
|
132
|
-
ctxToken: getCookie(c, resolvedCookieConfig.ctx.name),
|
|
133
|
-
});
|
|
134
|
-
return c.body(null, 200);
|
|
135
|
-
} else if (matchPath(pathname, '/confirm-upload')) {
|
|
136
|
-
const body = await c.req.json<ConfirmUploadBody>();
|
|
137
|
-
return c.json(
|
|
138
|
-
await confirmUpload({
|
|
139
|
-
provider,
|
|
140
|
-
router: config.router,
|
|
141
|
-
body,
|
|
142
|
-
ctxToken: getCookie(c, resolvedCookieConfig.ctx.name),
|
|
28
|
+
return async (c: HonoContext): Promise<Response> =>
|
|
29
|
+
await dispatchEdgeStoreRequest<TCtx>({
|
|
30
|
+
edgestore: config.edgestore,
|
|
31
|
+
logger: log,
|
|
32
|
+
cookieConfig,
|
|
33
|
+
request: {
|
|
34
|
+
pathname: new URL(c.req.url).pathname,
|
|
35
|
+
readJson: () => c.req.json(),
|
|
36
|
+
getQuery: (name) => c.req.query(name),
|
|
37
|
+
cookieHeader: c.req.header('cookie'),
|
|
38
|
+
createContext: () =>
|
|
39
|
+
resolveContext<TCtx, CreateContextOptions>(config, {
|
|
40
|
+
c,
|
|
143
41
|
}),
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const body = await c.req.json<DeleteFileBody>();
|
|
147
|
-
return c.json(
|
|
148
|
-
await deleteFile({
|
|
149
|
-
provider,
|
|
150
|
-
router: config.router,
|
|
151
|
-
body,
|
|
152
|
-
ctxToken: getCookie(c, resolvedCookieConfig.ctx.name),
|
|
153
|
-
}),
|
|
154
|
-
);
|
|
155
|
-
} else if (matchPath(pathname, '/proxy-file')) {
|
|
156
|
-
const url = c.req.query('url');
|
|
157
|
-
|
|
158
|
-
if (typeof url === 'string') {
|
|
159
|
-
const proxyRes = await fetchProxyFile({
|
|
160
|
-
cookieHeader: c.req.header('cookie'),
|
|
161
|
-
url,
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
return new Response(
|
|
165
|
-
proxyRes.body === null ? null : Buffer.from(proxyRes.body),
|
|
166
|
-
{
|
|
167
|
-
status: proxyRes.status,
|
|
168
|
-
headers: {
|
|
169
|
-
'Content-Type': proxyRes.contentType,
|
|
170
|
-
},
|
|
171
|
-
},
|
|
172
|
-
);
|
|
173
|
-
} else {
|
|
174
|
-
return c.body(null, 400);
|
|
175
|
-
}
|
|
176
|
-
} else {
|
|
177
|
-
return c.body(null, 404);
|
|
178
|
-
}
|
|
179
|
-
} catch (err) {
|
|
180
|
-
if (err instanceof EdgeStoreError) {
|
|
181
|
-
log[err.level](err.formattedMessage());
|
|
182
|
-
if (err.cause) log[err.level](err.cause);
|
|
183
|
-
return c.json(
|
|
184
|
-
err.formattedJson(),
|
|
185
|
-
EDGE_STORE_ERROR_CODES[err.code as EdgeStoreErrorCodeKey],
|
|
186
|
-
);
|
|
187
|
-
} else {
|
|
188
|
-
log.error(err);
|
|
189
|
-
return c.json(
|
|
190
|
-
new EdgeStoreError({
|
|
191
|
-
message: 'Internal Server Error',
|
|
192
|
-
code: 'SERVER_ERROR',
|
|
193
|
-
}).formattedJson(),
|
|
194
|
-
500,
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
};
|
|
42
|
+
},
|
|
43
|
+
});
|
|
199
44
|
}
|