@edgestore/server 0.7.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.d.ts.map +1 -1
- package/dist/adapters/astro/index.js +35 -43
- package/dist/adapters/express/index.d.ts +2 -2
- package/dist/adapters/express/index.d.ts.map +1 -1
- package/dist/adapters/express/index.js +34 -41
- package/dist/adapters/fastify/index.d.ts +3 -3
- package/dist/adapters/fastify/index.d.ts.map +1 -1
- package/dist/adapters/fastify/index.js +33 -42
- package/dist/adapters/hono/index.d.ts +6 -72
- package/dist/adapters/hono/index.d.ts.map +1 -1
- package/dist/adapters/hono/index.js +38 -41
- package/dist/adapters/imageTypes.js +1 -3
- package/dist/adapters/next/app/index.d.ts +2 -2
- package/dist/adapters/next/app/index.d.ts.map +1 -1
- package/dist/adapters/next/app/index.js +34 -42
- package/dist/adapters/next/pages/index.d.ts +2 -2
- package/dist/adapters/next/pages/index.d.ts.map +1 -1
- package/dist/adapters/next/pages/index.js +35 -42
- package/dist/adapters/remix/index.d.ts +2 -2
- package/dist/adapters/remix/index.d.ts.map +1 -1
- package/dist/adapters/remix/index.js +35 -42
- package/dist/adapters/shared.d.ts +8 -0
- package/dist/adapters/shared.d.ts.map +1 -1
- package/dist/adapters/shared.js +79 -56
- package/dist/adapters/start/index.d.ts +2 -2
- package/dist/adapters/start/index.d.ts.map +1 -1
- package/dist/adapters/start/index.js +35 -43
- 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 +59 -13
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +2 -10
- 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 +43 -16
- 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 +1 -1
- package/dist/providers/aws/index.d.ts.map +1 -1
- package/dist/providers/aws/index.js +14 -17
- package/dist/providers/azure/index.d.ts.map +1 -1
- package/dist/providers/azure/index.js +38 -15
- package/dist/providers/edgestore/index.d.ts.map +1 -1
- package/dist/providers/edgestore/index.js +36 -18
- 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 +4 -0
- package/package.json +59 -49
- 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/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 +61 -17
- package/src/adapters/start/index.ts +11 -12
- package/src/core/client/index.ts +199 -75
- package/src/core/sdk/index.ts +76 -8
- package/src/providers/aws/index.ts +4 -5
- package/src/providers/azure/index.ts +40 -11
- package/src/providers/edgestore/index.ts +29 -0
- package/src/test-utils/edgestoreSmoke.ts +141 -0
- package/src/version.ts +2 -0
- package/dist/adapters/astro/index.mjs +0 -178
- package/dist/adapters/express/index.mjs +0 -113
- package/dist/adapters/fastify/index.mjs +0 -142
- package/dist/adapters/hono/index.mjs +0 -132
- package/dist/adapters/imageTypes.mjs +0 -12
- package/dist/adapters/next/app/index.mjs +0 -169
- package/dist/adapters/next/pages/index.mjs +0 -117
- package/dist/adapters/remix/index.mjs +0 -153
- package/dist/adapters/shared.mjs +0 -443
- package/dist/adapters/start/index.mjs +0 -187
- package/dist/core/client/index.mjs +0 -173
- package/dist/core/index.mjs +0 -2
- package/dist/core/sdk/index.mjs +0 -223
- 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 -59
- package/dist/providers/edgestore/index.mjs +0 -144
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edgestoreSmoke.d.ts","sourceRoot":"","sources":["../../src/test-utils/edgestoreSmoke.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,yBAAyB,CAAC;AAEpD,wBAAgB,mBAAmB,WAElC;AAED,wBAAgB,kBAAkB,WAEjC;AAED,wBAAgB,uBAAuB,WAKtC;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,UAEjD;AAED,wBAAgB,uBAAuB,SAStC;AAMD,wBAAsB,iBAAiB,CAAC,MAAM,EAAE;IAC9C,MAAM,EAAE,MAAM,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAC5C,WAAW,EAAE,MAAM,CAAC;CACrB;aAE4B,OAAO;GAkCnC;AAED,KAAK,eAAe,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAuBF,wBAAsB,uBAAuB,CAAC,MAAM,EAAE;IACpD,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAC9D,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAC3D,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,eAAe,CAAC,CAAC;IACpD,MAAM,EAAE,MAAM,OAAO,CAAC,eAAe,CAAC,CAAC;CACxC,4BA4BA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,uBAAuB,sBAAsB,CAAC;AAC3D,eAAO,MAAM,0BAA0B,iBAAiB,CAAC"}
|
package/dist/version.js
ADDED
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edgestore/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-next.0",
|
|
4
4
|
"description": "Upload files with ease from React/Next.js",
|
|
5
5
|
"homepage": "https://edgestore.dev",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"sideEffects": false,
|
|
8
|
+
"type": "module",
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": ">=24"
|
|
11
|
+
},
|
|
8
12
|
"repository": {
|
|
9
13
|
"type": "git",
|
|
10
14
|
"url": "https://github.com/edgestorejs/edgestore.git",
|
|
@@ -15,7 +19,6 @@
|
|
|
15
19
|
},
|
|
16
20
|
"author": "Ravi <me@ravi.com>",
|
|
17
21
|
"main": "dist/index.js",
|
|
18
|
-
"module": "dist/index.mjs",
|
|
19
22
|
"types": "dist/index.d.ts",
|
|
20
23
|
"keywords": [
|
|
21
24
|
"react",
|
|
@@ -31,68 +34,68 @@
|
|
|
31
34
|
"exports": {
|
|
32
35
|
"./package.json": "./package.json",
|
|
33
36
|
".": {
|
|
34
|
-
"
|
|
35
|
-
"
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"import": "./dist/index.js",
|
|
36
39
|
"default": "./dist/index.js"
|
|
37
40
|
},
|
|
38
41
|
"./adapters/astro": {
|
|
39
|
-
"
|
|
40
|
-
"
|
|
42
|
+
"types": "./dist/adapters/astro/index.d.ts",
|
|
43
|
+
"import": "./dist/adapters/astro/index.js",
|
|
41
44
|
"default": "./dist/adapters/astro/index.js"
|
|
42
45
|
},
|
|
43
46
|
"./adapters/express": {
|
|
44
|
-
"
|
|
45
|
-
"
|
|
47
|
+
"types": "./dist/adapters/express/index.d.ts",
|
|
48
|
+
"import": "./dist/adapters/express/index.js",
|
|
46
49
|
"default": "./dist/adapters/express/index.js"
|
|
47
50
|
},
|
|
48
51
|
"./adapters/fastify": {
|
|
49
|
-
"
|
|
50
|
-
"
|
|
52
|
+
"types": "./dist/adapters/fastify/index.d.ts",
|
|
53
|
+
"import": "./dist/adapters/fastify/index.js",
|
|
51
54
|
"default": "./dist/adapters/fastify/index.js"
|
|
52
55
|
},
|
|
53
56
|
"./adapters/hono": {
|
|
54
|
-
"
|
|
55
|
-
"
|
|
57
|
+
"types": "./dist/adapters/hono/index.d.ts",
|
|
58
|
+
"import": "./dist/adapters/hono/index.js",
|
|
56
59
|
"default": "./dist/adapters/hono/index.js"
|
|
57
60
|
},
|
|
58
61
|
"./adapters/next/app": {
|
|
59
|
-
"
|
|
60
|
-
"
|
|
62
|
+
"types": "./dist/adapters/next/app/index.d.ts",
|
|
63
|
+
"import": "./dist/adapters/next/app/index.js",
|
|
61
64
|
"default": "./dist/adapters/next/app/index.js"
|
|
62
65
|
},
|
|
63
66
|
"./adapters/next/pages": {
|
|
64
|
-
"
|
|
65
|
-
"
|
|
67
|
+
"types": "./dist/adapters/next/pages/index.d.ts",
|
|
68
|
+
"import": "./dist/adapters/next/pages/index.js",
|
|
66
69
|
"default": "./dist/adapters/next/pages/index.js"
|
|
67
70
|
},
|
|
68
71
|
"./adapters/remix": {
|
|
69
|
-
"
|
|
70
|
-
"
|
|
72
|
+
"types": "./dist/adapters/remix/index.d.ts",
|
|
73
|
+
"import": "./dist/adapters/remix/index.js",
|
|
71
74
|
"default": "./dist/adapters/remix/index.js"
|
|
72
75
|
},
|
|
73
76
|
"./adapters/start": {
|
|
74
|
-
"
|
|
75
|
-
"
|
|
77
|
+
"types": "./dist/adapters/start/index.d.ts",
|
|
78
|
+
"import": "./dist/adapters/start/index.js",
|
|
76
79
|
"default": "./dist/adapters/start/index.js"
|
|
77
80
|
},
|
|
78
81
|
"./core": {
|
|
79
|
-
"
|
|
80
|
-
"
|
|
82
|
+
"types": "./dist/core/index.d.ts",
|
|
83
|
+
"import": "./dist/core/index.js",
|
|
81
84
|
"default": "./dist/core/index.js"
|
|
82
85
|
},
|
|
83
86
|
"./providers/aws": {
|
|
84
|
-
"
|
|
85
|
-
"
|
|
87
|
+
"types": "./dist/providers/aws/index.d.ts",
|
|
88
|
+
"import": "./dist/providers/aws/index.js",
|
|
86
89
|
"default": "./dist/providers/aws/index.js"
|
|
87
90
|
},
|
|
88
91
|
"./providers/azure": {
|
|
89
|
-
"
|
|
90
|
-
"
|
|
92
|
+
"types": "./dist/providers/azure/index.d.ts",
|
|
93
|
+
"import": "./dist/providers/azure/index.js",
|
|
91
94
|
"default": "./dist/providers/azure/index.js"
|
|
92
95
|
},
|
|
93
96
|
"./providers/edgestore": {
|
|
94
|
-
"
|
|
95
|
-
"
|
|
97
|
+
"types": "./dist/providers/edgestore/index.d.ts",
|
|
98
|
+
"import": "./dist/providers/edgestore/index.js",
|
|
96
99
|
"default": "./dist/providers/edgestore/index.js"
|
|
97
100
|
}
|
|
98
101
|
},
|
|
@@ -109,11 +112,10 @@
|
|
|
109
112
|
"!**/__tests__"
|
|
110
113
|
],
|
|
111
114
|
"dependencies": {
|
|
112
|
-
"@edgestore/shared": "0.
|
|
113
|
-
"@panva/hkdf": "^1.
|
|
114
|
-
"cookie": "^0.
|
|
115
|
-
"jose": "^
|
|
116
|
-
"uuid": "^9.0.0"
|
|
115
|
+
"@edgestore/shared": "1.0.0-next.0",
|
|
116
|
+
"@panva/hkdf": "^1.2.1",
|
|
117
|
+
"cookie": "^2.0.1",
|
|
118
|
+
"jose": "^6.2.3"
|
|
117
119
|
},
|
|
118
120
|
"peerDependencies": {
|
|
119
121
|
"@aws-sdk/client-s3": ">=3.0.0",
|
|
@@ -136,28 +138,36 @@
|
|
|
136
138
|
}
|
|
137
139
|
},
|
|
138
140
|
"devDependencies": {
|
|
139
|
-
"@aws-sdk/client-s3": "
|
|
140
|
-
"@aws-sdk/s3-request-presigner": "
|
|
141
|
-
"@azure/storage-blob": "
|
|
142
|
-
"@types/
|
|
143
|
-
"@types/express": "^4.17.21",
|
|
141
|
+
"@aws-sdk/client-s3": "3.1091.0",
|
|
142
|
+
"@aws-sdk/s3-request-presigner": "3.1091.0",
|
|
143
|
+
"@azure/storage-blob": "12.33.0",
|
|
144
|
+
"@types/express": "5.0.6",
|
|
144
145
|
"@types/node": "25.0.3",
|
|
145
|
-
"
|
|
146
|
-
"
|
|
147
|
-
"express": "
|
|
148
|
-
"fastify": "
|
|
149
|
-
"hono": "
|
|
150
|
-
"next": "16.
|
|
151
|
-
"react": "19.2.
|
|
152
|
-
"react-dom": "19.2.
|
|
153
|
-
"
|
|
154
|
-
"
|
|
146
|
+
"astro": "7.1.3",
|
|
147
|
+
"dotenv": "17.4.2",
|
|
148
|
+
"express": "5.2.1",
|
|
149
|
+
"fastify": "5.10.0",
|
|
150
|
+
"hono": "4.12.31",
|
|
151
|
+
"next": "16.2.10",
|
|
152
|
+
"react": "19.2.7",
|
|
153
|
+
"react-dom": "19.2.7",
|
|
154
|
+
"tsx": "4.23.1",
|
|
155
|
+
"typescript": "6.0.3",
|
|
156
|
+
"zod": "3.25.76"
|
|
155
157
|
},
|
|
156
158
|
"gitHead": "a223c4cb8df50e6b64f9db5dc2daf93848748da9",
|
|
157
159
|
"scripts": {
|
|
158
160
|
"build": "rollup --config rollup.config.ts --configPlugin rollup-plugin-swc3",
|
|
159
161
|
"dev": "pnpm build --watch",
|
|
160
162
|
"codegen:entrypoints": "tsx entrypoints.script.ts",
|
|
161
|
-
"
|
|
163
|
+
"test": "vitest run --config vitest.config.ts",
|
|
164
|
+
"test:smoke": "vitest run --config vitest.smoke.config.ts",
|
|
165
|
+
"test:smoke:dev": "TEST_ENV=dev vitest run --config vitest.smoke.config.ts",
|
|
166
|
+
"test:smoke:prod": "TEST_ENV=prod vitest run --config vitest.smoke.config.ts",
|
|
167
|
+
"test:smoke:adapter": "vitest run --config vitest.smoke.config.ts src/adapters/edgestore.smoke.test.ts",
|
|
168
|
+
"test:smoke:client": "vitest run --config vitest.smoke.config.ts src/core/client/edgestore.smoke.test.ts",
|
|
169
|
+
"test:smoke:errors": "vitest run --config vitest.smoke.config.ts src/core/sdk/edgestore.errors.smoke.test.ts",
|
|
170
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
171
|
+
"lint": "eslint --cache --report-unused-disable-directives src"
|
|
162
172
|
}
|
|
163
173
|
}
|
package/providers/aws/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from '../../dist/providers/aws';
|
|
1
|
+
export * from '../../dist/providers/aws/index.js';
|
package/providers/aws/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export * from '../../dist/providers/aws/index.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from '../../dist/providers/azure';
|
|
1
|
+
export * from '../../dist/providers/azure/index.js';
|
package/providers/azure/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export * from '../../dist/providers/azure/index.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from '../../dist/providers/edgestore';
|
|
1
|
+
export * from '../../dist/providers/edgestore/index.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export * from '../../dist/providers/edgestore/index.js';
|
|
@@ -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,
|
|
@@ -89,7 +90,7 @@ export function createEdgeStoreAstroHandler<TCtx>(config: Config<TCtx>) {
|
|
|
89
90
|
cause: err instanceof Error ? err : undefined,
|
|
90
91
|
});
|
|
91
92
|
}
|
|
92
|
-
const { newCookies,
|
|
93
|
+
const { newCookies, ...body } = await init({
|
|
93
94
|
ctx,
|
|
94
95
|
provider,
|
|
95
96
|
router: config.router,
|
|
@@ -108,14 +109,7 @@ export function createEdgeStoreAstroHandler<TCtx>(config: Config<TCtx>) {
|
|
|
108
109
|
headers.append('Set-Cookie', newCookies);
|
|
109
110
|
}
|
|
110
111
|
|
|
111
|
-
return new Response(
|
|
112
|
-
JSON.stringify({
|
|
113
|
-
token,
|
|
114
|
-
baseUrl,
|
|
115
|
-
providerName,
|
|
116
|
-
}),
|
|
117
|
-
{ headers },
|
|
118
|
-
);
|
|
112
|
+
return new Response(JSON.stringify(body), { headers });
|
|
119
113
|
} else if (matchPath(url.pathname, 'request-upload')) {
|
|
120
114
|
const body = (await request.json()) as RequestUploadBody;
|
|
121
115
|
const result = await requestUpload({
|
|
@@ -178,22 +172,18 @@ export function createEdgeStoreAstroHandler<TCtx>(config: Config<TCtx>) {
|
|
|
178
172
|
const url = new URL(request.url).searchParams.get('url');
|
|
179
173
|
|
|
180
174
|
if (typeof url === 'string') {
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
headers: {
|
|
185
|
-
cookie: cookieHeader,
|
|
186
|
-
},
|
|
175
|
+
const proxyRes = await fetchProxyFile({
|
|
176
|
+
cookieHeader: request.headers.get('cookie') ?? undefined,
|
|
177
|
+
url,
|
|
187
178
|
});
|
|
188
179
|
|
|
189
|
-
const data = await proxyRes.arrayBuffer();
|
|
190
180
|
const headers = new Headers();
|
|
191
|
-
headers.set(
|
|
192
|
-
'Content-Type',
|
|
193
|
-
proxyRes.headers.get('Content-Type') ?? 'application/octet-stream',
|
|
194
|
-
);
|
|
181
|
+
headers.set('Content-Type', proxyRes.contentType);
|
|
195
182
|
|
|
196
|
-
return new Response(
|
|
183
|
+
return new Response(proxyRes.body, {
|
|
184
|
+
headers,
|
|
185
|
+
status: proxyRes.status,
|
|
186
|
+
});
|
|
197
187
|
} else {
|
|
198
188
|
return new Response(null, { status: 400 });
|
|
199
189
|
}
|
|
@@ -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
|
}
|