Spaces:
Running
Running
feat: add content disposition to file endpoint (#1500)
Browse files* feat: add content disposition to file endpoint
* fix: use `mime-types` to get extension
package-lock.json
CHANGED
@@ -69,6 +69,7 @@
|
|
69 |
"@types/js-yaml": "^4.0.9",
|
70 |
"@types/jsdom": "^21.1.1",
|
71 |
"@types/jsonpath": "^0.2.4",
|
|
|
72 |
"@types/minimist": "^1.2.5",
|
73 |
"@types/node": "^22.1.0",
|
74 |
"@types/parquetjs": "^0.10.3",
|
@@ -4308,6 +4309,13 @@
|
|
4308 |
"integrity": "sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==",
|
4309 |
"dev": true
|
4310 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4311 |
"node_modules/@types/minimist": {
|
4312 |
"version": "1.2.5",
|
4313 |
"resolved": "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.5.tgz",
|
|
|
69 |
"@types/js-yaml": "^4.0.9",
|
70 |
"@types/jsdom": "^21.1.1",
|
71 |
"@types/jsonpath": "^0.2.4",
|
72 |
+
"@types/mime-types": "^2.1.4",
|
73 |
"@types/minimist": "^1.2.5",
|
74 |
"@types/node": "^22.1.0",
|
75 |
"@types/parquetjs": "^0.10.3",
|
|
|
4309 |
"integrity": "sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==",
|
4310 |
"dev": true
|
4311 |
},
|
4312 |
+
"node_modules/@types/mime-types": {
|
4313 |
+
"version": "2.1.4",
|
4314 |
+
"resolved": "https://registry.npmjs.org/@types/mime-types/-/mime-types-2.1.4.tgz",
|
4315 |
+
"integrity": "sha512-lfU4b34HOri+kAY5UheuFMWPDOI+OPceBSHZKp69gEyTL/mmJ4cnU6Y/rlme3UL3GyOn6Y42hyIEw0/q8sWx5w==",
|
4316 |
+
"dev": true,
|
4317 |
+
"license": "MIT"
|
4318 |
+
},
|
4319 |
"node_modules/@types/minimist": {
|
4320 |
"version": "1.2.5",
|
4321 |
"resolved": "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.5.tgz",
|
package.json
CHANGED
@@ -28,6 +28,7 @@
|
|
28 |
"@types/js-yaml": "^4.0.9",
|
29 |
"@types/jsdom": "^21.1.1",
|
30 |
"@types/jsonpath": "^0.2.4",
|
|
|
31 |
"@types/minimist": "^1.2.5",
|
32 |
"@types/node": "^22.1.0",
|
33 |
"@types/parquetjs": "^0.10.3",
|
@@ -108,9 +109,9 @@
|
|
108 |
"zod": "^3.22.3"
|
109 |
},
|
110 |
"optionalDependencies": {
|
111 |
-
"@aws-sdk/client-bedrock-runtime": "^3.631.0",
|
112 |
"@anthropic-ai/sdk": "^0.25.0",
|
113 |
"@anthropic-ai/vertex-sdk": "^0.4.1",
|
|
|
114 |
"@google-cloud/vertexai": "^1.1.0",
|
115 |
"@google/generative-ai": "^0.14.1",
|
116 |
"aws4fetch": "^1.0.17",
|
|
|
28 |
"@types/js-yaml": "^4.0.9",
|
29 |
"@types/jsdom": "^21.1.1",
|
30 |
"@types/jsonpath": "^0.2.4",
|
31 |
+
"@types/mime-types": "^2.1.4",
|
32 |
"@types/minimist": "^1.2.5",
|
33 |
"@types/node": "^22.1.0",
|
34 |
"@types/parquetjs": "^0.10.3",
|
|
|
109 |
"zod": "^3.22.3"
|
110 |
},
|
111 |
"optionalDependencies": {
|
|
|
112 |
"@anthropic-ai/sdk": "^0.25.0",
|
113 |
"@anthropic-ai/vertex-sdk": "^0.4.1",
|
114 |
+
"@aws-sdk/client-bedrock-runtime": "^3.631.0",
|
115 |
"@google-cloud/vertexai": "^1.1.0",
|
116 |
"@google/generative-ai": "^0.14.1",
|
117 |
"aws4fetch": "^1.0.17",
|
src/routes/conversation/[id]/output/[sha256]/+server.ts
CHANGED
@@ -5,6 +5,7 @@ import { ObjectId } from "mongodb";
|
|
5 |
import { z } from "zod";
|
6 |
import type { RequestHandler } from "./$types";
|
7 |
import { downloadFile } from "$lib/server/files/downloadFile";
|
|
|
8 |
|
9 |
export const GET: RequestHandler = async ({ locals, params }) => {
|
10 |
const sha256 = z.string().parse(params.sha256);
|
@@ -47,6 +48,9 @@ export const GET: RequestHandler = async ({ locals, params }) => {
|
|
47 |
"Content-Type": mime ?? "application/octet-stream",
|
48 |
"Content-Security-Policy":
|
49 |
"default-src 'none'; script-src 'none'; style-src 'none'; sandbox;",
|
|
|
|
|
|
|
50 |
"Content-Length": b64Value.length.toString(),
|
51 |
"Accept-Range": "bytes",
|
52 |
},
|
|
|
5 |
import { z } from "zod";
|
6 |
import type { RequestHandler } from "./$types";
|
7 |
import { downloadFile } from "$lib/server/files/downloadFile";
|
8 |
+
import mimeTypes from "mime-types";
|
9 |
|
10 |
export const GET: RequestHandler = async ({ locals, params }) => {
|
11 |
const sha256 = z.string().parse(params.sha256);
|
|
|
48 |
"Content-Type": mime ?? "application/octet-stream",
|
49 |
"Content-Security-Policy":
|
50 |
"default-src 'none'; script-src 'none'; style-src 'none'; sandbox;",
|
51 |
+
"Content-Disposition": `attachment; filename="${sha256.slice(0, 8)}.${
|
52 |
+
mime ? mimeTypes.extension(mime) || "bin" : "bin"
|
53 |
+
}"`,
|
54 |
"Content-Length": b64Value.length.toString(),
|
55 |
"Accept-Range": "bytes",
|
56 |
},
|