@edgestore/server 0.7.0 → 0.8.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/astro/index.d.ts.map +1 -1
- package/dist/adapters/astro/index.js +9 -15
- package/dist/adapters/astro/index.mjs +10 -16
- package/dist/adapters/express/index.d.ts.map +1 -1
- package/dist/adapters/express/index.js +8 -13
- package/dist/adapters/express/index.mjs +9 -14
- package/dist/adapters/fastify/index.d.ts +1 -1
- package/dist/adapters/fastify/index.d.ts.map +1 -1
- package/dist/adapters/fastify/index.js +7 -14
- package/dist/adapters/fastify/index.mjs +8 -15
- package/dist/adapters/hono/index.d.ts +4 -70
- package/dist/adapters/hono/index.d.ts.map +1 -1
- package/dist/adapters/hono/index.js +12 -13
- package/dist/adapters/hono/index.mjs +13 -14
- package/dist/adapters/next/app/index.d.ts.map +1 -1
- package/dist/adapters/next/app/index.js +7 -13
- package/dist/adapters/next/app/index.mjs +8 -14
- package/dist/adapters/next/pages/index.d.ts.map +1 -1
- package/dist/adapters/next/pages/index.js +8 -13
- package/dist/adapters/next/pages/index.mjs +9 -14
- package/dist/adapters/remix/index.d.ts.map +1 -1
- package/dist/adapters/remix/index.js +9 -14
- package/dist/adapters/remix/index.mjs +10 -15
- package/dist/adapters/shared.d.ts +8 -0
- package/dist/adapters/shared.d.ts.map +1 -1
- package/dist/adapters/shared.js +36 -7
- package/dist/adapters/shared.mjs +36 -8
- package/dist/adapters/start/index.d.ts.map +1 -1
- package/dist/adapters/start/index.js +9 -15
- package/dist/adapters/start/index.mjs +10 -16
- package/dist/core/client/index.d.ts +112 -69
- package/dist/core/client/index.d.ts.map +1 -1
- package/dist/core/client/index.js +52 -4
- package/dist/core/client/index.mjs +52 -4
- package/dist/core/sdk/index.d.ts +44 -2
- package/dist/core/sdk/index.d.ts.map +1 -1
- package/dist/core/sdk/index.js +36 -6
- package/dist/core/sdk/index.mjs +36 -6
- package/dist/providers/aws/index.d.ts +1 -1
- package/dist/providers/aws/index.d.ts.map +1 -1
- package/dist/providers/aws/index.js +3 -3
- package/dist/providers/aws/index.mjs +3 -3
- package/dist/providers/azure/index.d.ts.map +1 -1
- package/dist/providers/azure/index.js +33 -7
- package/dist/providers/azure/index.mjs +33 -7
- package/dist/providers/edgestore/index.d.ts.map +1 -1
- package/dist/providers/edgestore/index.js +24 -4
- package/dist/providers/edgestore/index.mjs +24 -4
- package/dist/test-utils/edgestoreSmoke.d.ts +32 -0
- package/dist/test-utils/edgestoreSmoke.d.ts.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +7 -0
- package/dist/version.mjs +4 -0
- package/package.json +11 -2
- package/src/adapters/astro/index.ts +11 -21
- package/src/adapters/express/index.ts +10 -16
- package/src/adapters/fastify/index.ts +13 -19
- package/src/adapters/hono/index.ts +19 -23
- package/src/adapters/next/app/index.ts +12 -22
- package/src/adapters/next/pages/index.ts +11 -16
- package/src/adapters/remix/index.ts +11 -12
- package/src/adapters/shared.ts +49 -4
- package/src/adapters/start/index.ts +11 -12
- package/src/core/client/index.ts +199 -74
- package/src/core/sdk/index.ts +75 -0
- package/src/providers/aws/index.ts +4 -4
- package/src/providers/azure/index.ts +40 -10
- package/src/providers/edgestore/index.ts +29 -0
- package/src/test-utils/edgestoreSmoke.ts +141 -0
- package/src/version.ts +2 -0
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
completeMultipartUpload,
|
|
15
15
|
confirmUpload,
|
|
16
16
|
deleteFile,
|
|
17
|
+
fetchProxyFile,
|
|
17
18
|
getCookieConfig,
|
|
18
19
|
init,
|
|
19
20
|
requestUpload,
|
|
@@ -76,18 +77,14 @@ export function createEdgeStoreExpressHandler<TCtx>(config: Config<TCtx>) {
|
|
|
76
77
|
cause: err instanceof Error ? err : undefined,
|
|
77
78
|
});
|
|
78
79
|
}
|
|
79
|
-
const { newCookies,
|
|
80
|
+
const { newCookies, ...body } = await init({
|
|
80
81
|
ctx,
|
|
81
82
|
provider,
|
|
82
83
|
router: config.router,
|
|
83
84
|
cookieConfig,
|
|
84
85
|
});
|
|
85
86
|
res.setHeader('Set-Cookie', newCookies);
|
|
86
|
-
res.json(
|
|
87
|
-
token,
|
|
88
|
-
baseUrl,
|
|
89
|
-
providerName,
|
|
90
|
-
});
|
|
87
|
+
res.json(body);
|
|
91
88
|
} else if (matchPath(pathname, '/request-upload')) {
|
|
92
89
|
res.json(
|
|
93
90
|
await requestUpload({
|
|
@@ -135,19 +132,16 @@ export function createEdgeStoreExpressHandler<TCtx>(config: Config<TCtx>) {
|
|
|
135
132
|
} else if (matchPath(pathname, '/proxy-file')) {
|
|
136
133
|
const { url } = req.query;
|
|
137
134
|
if (typeof url === 'string') {
|
|
138
|
-
const proxyRes = await
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
},
|
|
135
|
+
const proxyRes = await fetchProxyFile({
|
|
136
|
+
cookieHeader: req.headers.cookie,
|
|
137
|
+
url,
|
|
142
138
|
});
|
|
143
139
|
|
|
144
|
-
|
|
145
|
-
res.
|
|
146
|
-
|
|
147
|
-
proxyRes.
|
|
140
|
+
res.setHeader('Content-Type', proxyRes.contentType);
|
|
141
|
+
res.status(proxyRes.status);
|
|
142
|
+
res.end(
|
|
143
|
+
proxyRes.body === null ? undefined : Buffer.from(proxyRes.body),
|
|
148
144
|
);
|
|
149
|
-
|
|
150
|
-
res.end(Buffer.from(data));
|
|
151
145
|
} else {
|
|
152
146
|
res.status(400).end();
|
|
153
147
|
}
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
completeMultipartUpload,
|
|
15
15
|
confirmUpload,
|
|
16
16
|
deleteFile,
|
|
17
|
+
fetchProxyFile,
|
|
17
18
|
getCookieConfig,
|
|
18
19
|
init,
|
|
19
20
|
requestUpload,
|
|
@@ -80,7 +81,7 @@ export function createEdgeStoreFastifyHandler<TCtx>(config: Config<TCtx>) {
|
|
|
80
81
|
|
|
81
82
|
const resolvedCookieConfig = getCookieConfig(cookieConfig);
|
|
82
83
|
|
|
83
|
-
return async (req: FastifyRequest, reply: FastifyReply) => {
|
|
84
|
+
return async (req: FastifyRequest, reply: FastifyReply): Promise<void> => {
|
|
84
85
|
try {
|
|
85
86
|
// Get the URL from the request - simplified approach
|
|
86
87
|
const pathname = req.url;
|
|
@@ -101,7 +102,7 @@ export function createEdgeStoreFastifyHandler<TCtx>(config: Config<TCtx>) {
|
|
|
101
102
|
cause: err instanceof Error ? err : undefined,
|
|
102
103
|
});
|
|
103
104
|
}
|
|
104
|
-
const { newCookies,
|
|
105
|
+
const { newCookies, ...body } = await init({
|
|
105
106
|
ctx,
|
|
106
107
|
provider,
|
|
107
108
|
router: config.router,
|
|
@@ -120,11 +121,7 @@ export function createEdgeStoreFastifyHandler<TCtx>(config: Config<TCtx>) {
|
|
|
120
121
|
void reply.header('Set-Cookie', newCookies);
|
|
121
122
|
}
|
|
122
123
|
|
|
123
|
-
return reply.send(
|
|
124
|
-
token,
|
|
125
|
-
baseUrl,
|
|
126
|
-
providerName,
|
|
127
|
-
});
|
|
124
|
+
return reply.send(body);
|
|
128
125
|
} else if (matchPath(pathname, '/request-upload')) {
|
|
129
126
|
return reply.send(
|
|
130
127
|
await requestUpload({
|
|
@@ -175,21 +172,18 @@ export function createEdgeStoreFastifyHandler<TCtx>(config: Config<TCtx>) {
|
|
|
175
172
|
: undefined;
|
|
176
173
|
|
|
177
174
|
if (typeof url === 'string') {
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
headers: {
|
|
182
|
-
cookie: cookieHeader,
|
|
183
|
-
},
|
|
175
|
+
const proxyRes = await fetchProxyFile({
|
|
176
|
+
cookieHeader: req.headers.cookie,
|
|
177
|
+
url,
|
|
184
178
|
});
|
|
185
179
|
|
|
186
|
-
|
|
187
|
-
void reply.header(
|
|
188
|
-
'Content-Type',
|
|
189
|
-
proxyRes.headers.get('Content-Type') ?? 'application/octet-stream',
|
|
190
|
-
);
|
|
180
|
+
void reply.header('Content-Type', proxyRes.contentType);
|
|
191
181
|
|
|
192
|
-
return reply
|
|
182
|
+
return reply
|
|
183
|
+
.status(proxyRes.status)
|
|
184
|
+
.send(
|
|
185
|
+
proxyRes.body === null ? undefined : Buffer.from(proxyRes.body),
|
|
186
|
+
);
|
|
193
187
|
} else {
|
|
194
188
|
return reply.status(400).send();
|
|
195
189
|
}
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
type MaybePromise,
|
|
7
7
|
type Provider,
|
|
8
8
|
} from '@edgestore/shared';
|
|
9
|
-
import { type Context } from 'hono';
|
|
9
|
+
import { type Context as HonoContext } from 'hono';
|
|
10
10
|
import Logger, { type LogLevel } from '../../libs/logger';
|
|
11
11
|
import { matchPath } from '../../libs/utils';
|
|
12
12
|
import { EdgeStoreProvider } from '../../providers/edgestore';
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
completeMultipartUpload,
|
|
15
15
|
confirmUpload,
|
|
16
16
|
deleteFile,
|
|
17
|
+
fetchProxyFile,
|
|
17
18
|
getCookieConfig,
|
|
18
19
|
init,
|
|
19
20
|
requestUpload,
|
|
@@ -27,7 +28,7 @@ import {
|
|
|
27
28
|
} from '../shared';
|
|
28
29
|
|
|
29
30
|
export type CreateContextOptions = {
|
|
30
|
-
c:
|
|
31
|
+
c: HonoContext;
|
|
31
32
|
};
|
|
32
33
|
|
|
33
34
|
export type Config<TCtx> = {
|
|
@@ -49,7 +50,7 @@ declare const globalThis: {
|
|
|
49
50
|
};
|
|
50
51
|
|
|
51
52
|
// Helper to get a cookie value from Hono Context
|
|
52
|
-
function getCookie(c:
|
|
53
|
+
function getCookie(c: HonoContext, name: string): string | undefined {
|
|
53
54
|
const cookies = c.req.header('cookie');
|
|
54
55
|
if (!cookies) return undefined;
|
|
55
56
|
|
|
@@ -65,7 +66,7 @@ export function createEdgeStoreHonoHandler<TCtx>(config: Config<TCtx>) {
|
|
|
65
66
|
|
|
66
67
|
const resolvedCookieConfig = getCookieConfig(cookieConfig);
|
|
67
68
|
|
|
68
|
-
return async (c:
|
|
69
|
+
return async (c: HonoContext): Promise<Response> => {
|
|
69
70
|
try {
|
|
70
71
|
const pathname = new URL(c.req.url).pathname;
|
|
71
72
|
|
|
@@ -85,7 +86,7 @@ export function createEdgeStoreHonoHandler<TCtx>(config: Config<TCtx>) {
|
|
|
85
86
|
cause: err instanceof Error ? err : undefined,
|
|
86
87
|
});
|
|
87
88
|
}
|
|
88
|
-
const { newCookies,
|
|
89
|
+
const { newCookies, ...body } = await init({
|
|
89
90
|
ctx,
|
|
90
91
|
provider,
|
|
91
92
|
router: config.router,
|
|
@@ -95,17 +96,13 @@ export function createEdgeStoreHonoHandler<TCtx>(config: Config<TCtx>) {
|
|
|
95
96
|
// Set cookies
|
|
96
97
|
if (Array.isArray(newCookies)) {
|
|
97
98
|
for (const cookie of newCookies) {
|
|
98
|
-
c.header('Set-Cookie', cookie);
|
|
99
|
+
c.header('Set-Cookie', cookie, { append: true });
|
|
99
100
|
}
|
|
100
101
|
} else if (newCookies) {
|
|
101
102
|
c.header('Set-Cookie', newCookies);
|
|
102
103
|
}
|
|
103
104
|
|
|
104
|
-
return c.json(
|
|
105
|
-
token,
|
|
106
|
-
baseUrl,
|
|
107
|
-
providerName,
|
|
108
|
-
});
|
|
105
|
+
return c.json(body);
|
|
109
106
|
} else if (matchPath(pathname, '/request-upload')) {
|
|
110
107
|
const body = await c.req.json<RequestUploadBody>();
|
|
111
108
|
return c.json(
|
|
@@ -159,21 +156,20 @@ export function createEdgeStoreHonoHandler<TCtx>(config: Config<TCtx>) {
|
|
|
159
156
|
const url = c.req.query('url');
|
|
160
157
|
|
|
161
158
|
if (typeof url === 'string') {
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
headers: {
|
|
166
|
-
cookie: cookieHeader,
|
|
167
|
-
},
|
|
159
|
+
const proxyRes = await fetchProxyFile({
|
|
160
|
+
cookieHeader: c.req.header('cookie'),
|
|
161
|
+
url,
|
|
168
162
|
});
|
|
169
163
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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
|
+
},
|
|
174
172
|
);
|
|
175
|
-
|
|
176
|
-
return c.body(Buffer.from(data));
|
|
177
173
|
} else {
|
|
178
174
|
return c.body(null, 400);
|
|
179
175
|
}
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
completeMultipartUpload,
|
|
15
15
|
confirmUpload,
|
|
16
16
|
deleteFile,
|
|
17
|
+
fetchProxyFile,
|
|
17
18
|
getCookieConfig,
|
|
18
19
|
init,
|
|
19
20
|
requestUpload,
|
|
@@ -85,25 +86,18 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
85
86
|
cause: err instanceof Error ? err : undefined,
|
|
86
87
|
});
|
|
87
88
|
}
|
|
88
|
-
const { newCookies,
|
|
89
|
+
const { newCookies, ...body } = await init({
|
|
89
90
|
ctx,
|
|
90
91
|
provider,
|
|
91
92
|
router: config.router,
|
|
92
93
|
cookieConfig,
|
|
93
94
|
});
|
|
94
|
-
const res = new Response(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
providerName,
|
|
99
|
-
}),
|
|
100
|
-
{
|
|
101
|
-
status: 200,
|
|
102
|
-
headers: {
|
|
103
|
-
'Content-Type': 'application/json',
|
|
104
|
-
},
|
|
95
|
+
const res = new Response(JSON.stringify(body), {
|
|
96
|
+
status: 200,
|
|
97
|
+
headers: {
|
|
98
|
+
'Content-Type': 'application/json',
|
|
105
99
|
},
|
|
106
|
-
);
|
|
100
|
+
});
|
|
107
101
|
for (const cookie of newCookies) {
|
|
108
102
|
res.headers.append('Set-Cookie', cookie);
|
|
109
103
|
}
|
|
@@ -173,19 +167,15 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
173
167
|
} else if (matchPath(pathname, '/proxy-file')) {
|
|
174
168
|
const url = req.nextUrl.searchParams.get('url');
|
|
175
169
|
if (typeof url === 'string') {
|
|
176
|
-
const proxyRes = await
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
},
|
|
170
|
+
const proxyRes = await fetchProxyFile({
|
|
171
|
+
cookieHeader: req.cookies.toString(),
|
|
172
|
+
url,
|
|
180
173
|
});
|
|
181
174
|
|
|
182
|
-
|
|
183
|
-
return new Response(data, {
|
|
175
|
+
return new Response(proxyRes.body, {
|
|
184
176
|
status: proxyRes.status,
|
|
185
177
|
headers: {
|
|
186
|
-
'Content-Type':
|
|
187
|
-
proxyRes.headers.get('Content-Type') ??
|
|
188
|
-
'application/octet-stream',
|
|
178
|
+
'Content-Type': proxyRes.contentType,
|
|
189
179
|
},
|
|
190
180
|
});
|
|
191
181
|
} else {
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
completeMultipartUpload,
|
|
15
15
|
confirmUpload,
|
|
16
16
|
deleteFile,
|
|
17
|
+
fetchProxyFile,
|
|
17
18
|
getCookieConfig,
|
|
18
19
|
init,
|
|
19
20
|
requestUpload,
|
|
@@ -82,18 +83,14 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
82
83
|
cause: err instanceof Error ? err : undefined,
|
|
83
84
|
});
|
|
84
85
|
}
|
|
85
|
-
const { newCookies,
|
|
86
|
+
const { newCookies, ...body } = await init({
|
|
86
87
|
ctx,
|
|
87
88
|
provider,
|
|
88
89
|
router: config.router,
|
|
89
90
|
cookieConfig,
|
|
90
91
|
});
|
|
91
92
|
res.setHeader('Set-Cookie', newCookies);
|
|
92
|
-
res.json(
|
|
93
|
-
token,
|
|
94
|
-
baseUrl,
|
|
95
|
-
providerName,
|
|
96
|
-
});
|
|
93
|
+
res.json(body);
|
|
97
94
|
} else if (matchPath(pathname, '/request-upload')) {
|
|
98
95
|
res.json(
|
|
99
96
|
await requestUpload({
|
|
@@ -141,19 +138,17 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
141
138
|
} else if (matchPath(pathname, '/proxy-file')) {
|
|
142
139
|
const { url } = req.query;
|
|
143
140
|
if (typeof url === 'string') {
|
|
144
|
-
const proxyRes = await
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
},
|
|
141
|
+
const proxyRes = await fetchProxyFile({
|
|
142
|
+
cookieHeader: req.headers.cookie,
|
|
143
|
+
url,
|
|
148
144
|
});
|
|
149
145
|
|
|
150
|
-
|
|
151
|
-
res.setHeader(
|
|
152
|
-
'Content-Type',
|
|
153
|
-
proxyRes.headers.get('Content-Type') ?? 'application/octet-stream',
|
|
154
|
-
);
|
|
146
|
+
res.setHeader('Content-Type', proxyRes.contentType);
|
|
155
147
|
|
|
156
|
-
res.
|
|
148
|
+
res.status(proxyRes.status);
|
|
149
|
+
res.end(
|
|
150
|
+
proxyRes.body === null ? undefined : Buffer.from(proxyRes.body),
|
|
151
|
+
);
|
|
157
152
|
} else {
|
|
158
153
|
res.status(400).end();
|
|
159
154
|
}
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
completeMultipartUpload,
|
|
14
14
|
confirmUpload,
|
|
15
15
|
deleteFile,
|
|
16
|
+
fetchProxyFile,
|
|
16
17
|
getCookieConfig,
|
|
17
18
|
init,
|
|
18
19
|
requestUpload,
|
|
@@ -92,7 +93,7 @@ export function createEdgeStoreRemixHandler<TCtx>(config: Config<TCtx>) {
|
|
|
92
93
|
cause: err instanceof Error ? err : undefined,
|
|
93
94
|
});
|
|
94
95
|
}
|
|
95
|
-
const { newCookies,
|
|
96
|
+
const { newCookies, ...body } = await init({
|
|
96
97
|
ctx,
|
|
97
98
|
provider,
|
|
98
99
|
router: config.router,
|
|
@@ -110,7 +111,7 @@ export function createEdgeStoreRemixHandler<TCtx>(config: Config<TCtx>) {
|
|
|
110
111
|
responseHeaders.append('Set-Cookie', newCookies);
|
|
111
112
|
}
|
|
112
113
|
|
|
113
|
-
return new Response(JSON.stringify(
|
|
114
|
+
return new Response(JSON.stringify(body), {
|
|
114
115
|
headers: responseHeaders,
|
|
115
116
|
status: 200,
|
|
116
117
|
});
|
|
@@ -166,20 +167,18 @@ export function createEdgeStoreRemixHandler<TCtx>(config: Config<TCtx>) {
|
|
|
166
167
|
} else if (matchPath(pathname, '/proxy-file')) {
|
|
167
168
|
const url = new URL(req.url).searchParams.get('url');
|
|
168
169
|
if (typeof url === 'string') {
|
|
169
|
-
const proxyRes = await
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
},
|
|
170
|
+
const proxyRes = await fetchProxyFile({
|
|
171
|
+
cookieHeader: req.headers.get('cookie') ?? undefined,
|
|
172
|
+
url,
|
|
173
173
|
});
|
|
174
174
|
|
|
175
|
-
const data = await proxyRes.arrayBuffer();
|
|
176
175
|
const headers = new Headers();
|
|
177
|
-
headers.set(
|
|
178
|
-
'Content-Type',
|
|
179
|
-
proxyRes.headers.get('Content-Type') ?? 'application/octet-stream',
|
|
180
|
-
);
|
|
176
|
+
headers.set('Content-Type', proxyRes.contentType);
|
|
181
177
|
|
|
182
|
-
return new Response(
|
|
178
|
+
return new Response(proxyRes.body, {
|
|
179
|
+
headers,
|
|
180
|
+
status: proxyRes.status,
|
|
181
|
+
});
|
|
183
182
|
} else {
|
|
184
183
|
return new Response(null, { status: 400 });
|
|
185
184
|
}
|
package/src/adapters/shared.ts
CHANGED
|
@@ -22,6 +22,33 @@ declare const globalThis: {
|
|
|
22
22
|
_EDGE_STORE_LOGGER: Logger;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
+
const NO_BODY_STATUSES = new Set([204, 205, 304]);
|
|
26
|
+
|
|
27
|
+
export async function fetchProxyFile({
|
|
28
|
+
cookieHeader,
|
|
29
|
+
url,
|
|
30
|
+
}: {
|
|
31
|
+
cookieHeader?: string;
|
|
32
|
+
url: string;
|
|
33
|
+
}) {
|
|
34
|
+
const proxyRes = await fetch(url, {
|
|
35
|
+
headers: {
|
|
36
|
+
cookie: cookieHeader ?? '',
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const body = NO_BODY_STATUSES.has(proxyRes.status)
|
|
41
|
+
? null
|
|
42
|
+
: await proxyRes.arrayBuffer();
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
body,
|
|
46
|
+
contentType:
|
|
47
|
+
proxyRes.headers.get('Content-Type') ?? 'application/octet-stream',
|
|
48
|
+
status: proxyRes.status,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
25
52
|
export type CookieOptions = {
|
|
26
53
|
/**
|
|
27
54
|
* Cookie path
|
|
@@ -145,10 +172,24 @@ export async function init<TCtx>(params: {
|
|
|
145
172
|
const resolvedCookieConfig = getCookieConfig(cookieConfig);
|
|
146
173
|
|
|
147
174
|
const ctxToken = await encryptJWT(ctx);
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
router
|
|
151
|
-
|
|
175
|
+
const requiresFileAccessCookie =
|
|
176
|
+
provider.name === 'edgestore' &&
|
|
177
|
+
Object.values(router.buckets).some(
|
|
178
|
+
(bucket) =>
|
|
179
|
+
bucket._def.accessControl !== undefined &&
|
|
180
|
+
bucket._def.accessControl !== 'private',
|
|
181
|
+
);
|
|
182
|
+
const shouldRunProviderInit =
|
|
183
|
+
provider.name !== 'edgestore' || requiresFileAccessCookie;
|
|
184
|
+
|
|
185
|
+
let token: string | undefined;
|
|
186
|
+
if (shouldRunProviderInit) {
|
|
187
|
+
const initRes = await provider.init({
|
|
188
|
+
ctx,
|
|
189
|
+
router: router,
|
|
190
|
+
});
|
|
191
|
+
token = initRes.token;
|
|
192
|
+
}
|
|
152
193
|
const newCookies = [
|
|
153
194
|
serialize(
|
|
154
195
|
resolvedCookieConfig.ctx.name,
|
|
@@ -173,6 +214,7 @@ export async function init<TCtx>(params: {
|
|
|
173
214
|
token,
|
|
174
215
|
baseUrl,
|
|
175
216
|
providerName: provider.name,
|
|
217
|
+
requiresFileAccessCookie,
|
|
176
218
|
});
|
|
177
219
|
|
|
178
220
|
return {
|
|
@@ -180,6 +222,7 @@ export async function init<TCtx>(params: {
|
|
|
180
222
|
token,
|
|
181
223
|
baseUrl,
|
|
182
224
|
providerName: provider.name,
|
|
225
|
+
requiresFileAccessCookie,
|
|
183
226
|
};
|
|
184
227
|
}
|
|
185
228
|
|
|
@@ -313,6 +356,7 @@ export async function requestUpload<TCtx>(params: {
|
|
|
313
356
|
});
|
|
314
357
|
const metadata = await bucket._def.metadata?.({ ctx, input });
|
|
315
358
|
const isPublic = bucket._def.accessControl === undefined;
|
|
359
|
+
const autoSignedUrls = bucket._def.autoSignedUrls;
|
|
316
360
|
|
|
317
361
|
log.debug('upload info', {
|
|
318
362
|
path,
|
|
@@ -330,6 +374,7 @@ export async function requestUpload<TCtx>(params: {
|
|
|
330
374
|
isPublic,
|
|
331
375
|
metadata,
|
|
332
376
|
},
|
|
377
|
+
autoSignedUrls,
|
|
333
378
|
});
|
|
334
379
|
const { parsedPath, pathOrder } = parsePath(path);
|
|
335
380
|
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
completeMultipartUpload,
|
|
14
14
|
confirmUpload,
|
|
15
15
|
deleteFile,
|
|
16
|
+
fetchProxyFile,
|
|
16
17
|
getCookieConfig,
|
|
17
18
|
init,
|
|
18
19
|
requestUpload,
|
|
@@ -90,7 +91,7 @@ export function createEdgeStoreStartHandler<TCtx>(config: Config<TCtx>) {
|
|
|
90
91
|
cause: err instanceof Error ? err : undefined,
|
|
91
92
|
});
|
|
92
93
|
}
|
|
93
|
-
const { newCookies,
|
|
94
|
+
const { newCookies, ...body } = await init({
|
|
94
95
|
ctx,
|
|
95
96
|
provider,
|
|
96
97
|
router: config.router,
|
|
@@ -101,7 +102,7 @@ export function createEdgeStoreStartHandler<TCtx>(config: Config<TCtx>) {
|
|
|
101
102
|
headers.append('Set-Cookie', cookie);
|
|
102
103
|
});
|
|
103
104
|
headers.set('Content-Type', 'application/json');
|
|
104
|
-
return new Response(JSON.stringify(
|
|
105
|
+
return new Response(JSON.stringify(body), {
|
|
105
106
|
status: 200,
|
|
106
107
|
headers,
|
|
107
108
|
});
|
|
@@ -170,18 +171,16 @@ export function createEdgeStoreStartHandler<TCtx>(config: Config<TCtx>) {
|
|
|
170
171
|
} else if (matchPath(pathname, '/proxy-file')) {
|
|
171
172
|
const urlParam = new URL(request.url).searchParams.get('url');
|
|
172
173
|
if (typeof urlParam === 'string') {
|
|
173
|
-
const proxyRes = await
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
},
|
|
174
|
+
const proxyRes = await fetchProxyFile({
|
|
175
|
+
cookieHeader: request.headers.get('cookie') ?? undefined,
|
|
176
|
+
url: urlParam,
|
|
177
177
|
});
|
|
178
|
-
const data = await proxyRes.arrayBuffer();
|
|
179
178
|
const headers = new Headers();
|
|
180
|
-
headers.set(
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
179
|
+
headers.set('Content-Type', proxyRes.contentType);
|
|
180
|
+
return new Response(proxyRes.body, {
|
|
181
|
+
headers,
|
|
182
|
+
status: proxyRes.status,
|
|
183
|
+
});
|
|
185
184
|
} else {
|
|
186
185
|
return new Response(null, { status: 400 });
|
|
187
186
|
}
|