@softure-ai/files 0.2.0 → 0.3.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/CHANGELOG.md +24 -0
- package/README.md +127 -3
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +6 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/send-upload.d.ts +26 -0
- package/dist/client/send-upload.d.ts.map +1 -0
- package/dist/client/send-upload.js +66 -0
- package/dist/client/send-upload.js.map +1 -0
- package/dist/client/upload-queue.d.ts +52 -0
- package/dist/client/upload-queue.d.ts.map +1 -0
- package/dist/client/upload-queue.js +164 -0
- package/dist/client/upload-queue.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/mcp/index.d.ts +25 -1
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +31 -14
- package/dist/mcp/index.js.map +1 -1
- package/dist/messages/en.d.ts +5 -0
- package/dist/messages/en.d.ts.map +1 -1
- package/dist/messages/en.js +7 -1
- package/dist/messages/en.js.map +1 -1
- package/dist/messages/index.d.ts +5 -0
- package/dist/messages/index.d.ts.map +1 -1
- package/dist/next/index.d.ts +1 -0
- package/dist/next/index.d.ts.map +1 -1
- package/dist/next/index.js +3 -2
- package/dist/next/index.js.map +1 -1
- package/dist/next/stored-file-route.d.ts +25 -0
- package/dist/next/stored-file-route.d.ts.map +1 -0
- package/dist/next/stored-file-route.js +14 -0
- package/dist/next/stored-file-route.js.map +1 -0
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/serve.d.ts +15 -0
- package/dist/server/serve.d.ts.map +1 -1
- package/dist/server/serve.js +38 -14
- package/dist/server/serve.js.map +1 -1
- package/dist/server/upload-page.d.ts.map +1 -1
- package/dist/server/upload-page.js +16 -23
- package/dist/server/upload-page.js.map +1 -1
- package/module.json +1 -1
- package/package.json +7 -2
- package/src/client/index.ts +12 -0
- package/src/client/send-upload.ts +89 -0
- package/src/client/upload-queue.ts +220 -0
- package/src/index.ts +1 -1
- package/src/mcp/index.ts +52 -15
- package/src/messages/en.ts +7 -1
- package/src/next/index.ts +9 -2
- package/src/next/stored-file-route.ts +43 -0
- package/src/server/index.ts +1 -1
- package/src/server/serve.ts +51 -14
- package/src/server/upload-page.ts +16 -23
package/dist/mcp/index.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import type { McpServer } from "@modelcontextprotocol/server";
|
|
2
|
-
import type
|
|
2
|
+
import { type Err, type ErrorCode } from "@softure-ai/core";
|
|
3
|
+
import type { CreatedUpload, StoredFile } from "../contract.js";
|
|
3
4
|
import type { FilesContext } from "../server/context.js";
|
|
4
5
|
export declare const CREATE_UPLOAD_TOOL_NAME = "create_upload";
|
|
5
6
|
export declare const FINALIZE_UPLOAD_TOOL_NAME = "finalize_upload";
|
|
7
|
+
/** The served tool descriptions by default; an app prefixes or replaces them through `descriptions`. */
|
|
8
|
+
export declare const FILE_UPLOAD_TOOL_DESCRIPTIONS: {
|
|
9
|
+
readonly create_upload: string;
|
|
10
|
+
readonly finalize_upload: string;
|
|
11
|
+
};
|
|
6
12
|
/** The catalog entries for `mcpAccess({ tools })`, so the token page and the catalog check know both tools. */
|
|
7
13
|
export declare const FILE_UPLOAD_MCP_TOOLS: readonly [{
|
|
8
14
|
readonly name: "create_upload";
|
|
@@ -30,7 +36,25 @@ export interface FileUploadToolsOptions {
|
|
|
30
36
|
readonly getOwnerId?: (identity: FileUploadToolIdentity) => string;
|
|
31
37
|
/** The kind of the stored files; `file` by default. */
|
|
32
38
|
readonly kind?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Runs after every successful `finalize_upload`, a repeated one for the same file included (so keep it idempotent,
|
|
41
|
+
* e.g. an upsert by `file.id`). Returned fields join the answer (the file's own fields win a name clash); a returned
|
|
42
|
+
* `err(code)` answers that code as a failure; a thrown error answers the generic failure and is logged.
|
|
43
|
+
*/
|
|
44
|
+
readonly onFinalized?: (file: StoredFile, ctx: FilesContext) => Promise<FileFinalizedAnswer>;
|
|
45
|
+
/** The served descriptions; a missing one keeps `FILE_UPLOAD_TOOL_DESCRIPTIONS`. */
|
|
46
|
+
readonly descriptions?: {
|
|
47
|
+
readonly create_upload?: string;
|
|
48
|
+
readonly finalize_upload?: string;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* The text answered for an error code, the hook's codes and the package's `files.*` codes alike, followed by the code.
|
|
52
|
+
* Without a hint a `files.*` code answers its English sentence and any other code answers the code alone.
|
|
53
|
+
*/
|
|
54
|
+
readonly hints?: Readonly<Record<string, string>>;
|
|
33
55
|
}
|
|
56
|
+
/** What `onFinalized` answers: extra fields for the tool's answer, nothing, or a failure. */
|
|
57
|
+
export type FileFinalizedAnswer = Readonly<Record<string, unknown>> | Err<ErrorCode> | undefined | void;
|
|
34
58
|
/** Registers `create_upload` and `finalize_upload` for an identity that can write; does nothing for a read-only one. */
|
|
35
59
|
export declare function registerFileUploadTools(server: Pick<McpServer, "registerTool">, options: FileUploadToolsOptions): void;
|
|
36
60
|
/**
|
package/dist/mcp/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAkB,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC9E,OAAO,EAAiB,KAAK,GAAG,EAAE,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE3E,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEhE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,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AS,CAAC,GAAG,SAAS,GAAG,IAAI,CAAC;AAiBxG,wHAAwH;AACxH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,EAAE,OAAO,EAAE,sBAAsB,GAAG,IAAI,CA2CtH;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,IAAI,CAAC,aAAa,EAAE,WAAW,GAAG,WAAW,GAAG,YAAY,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAYjI"}
|
package/dist/mcp/index.js
CHANGED
|
@@ -4,12 +4,15 @@ import { filesMessages, getFilesErrorMessage } from "../messages/index.js";
|
|
|
4
4
|
import { createUpload, finalizeUpload } from "../server/uploads.js";
|
|
5
5
|
export const CREATE_UPLOAD_TOOL_NAME = "create_upload";
|
|
6
6
|
export const FINALIZE_UPLOAD_TOOL_NAME = "finalize_upload";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"file
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
/** The served tool descriptions by default; an app prefixes or replaces them through `descriptions`. */
|
|
8
|
+
export const FILE_UPLOAD_TOOL_DESCRIPTIONS = {
|
|
9
|
+
create_upload: "Starts an upload of a file from your own environment (for a file too large for a tool call, such as a video). " +
|
|
10
|
+
"The file's bytes never go through this tool: it answers a one-time upload URL and a ready curl loop that sends the " +
|
|
11
|
+
"file in chunks; run it where the file is, then call finalize_upload with the upload_id. A person can open the " +
|
|
12
|
+
"same URL in a browser to upload the file there instead.",
|
|
13
|
+
finalize_upload: "Finishes an upload started with create_upload once every chunk is sent: checks the bytes and stores the file. " +
|
|
14
|
+
"Answers the stored file's id. Calling it again answers the same file.",
|
|
15
|
+
};
|
|
13
16
|
/** The catalog entries for `mcpAccess({ tools })`, so the token page and the catalog check know both tools. */
|
|
14
17
|
export const FILE_UPLOAD_MCP_TOOLS = [
|
|
15
18
|
{ name: CREATE_UPLOAD_TOOL_NAME, access: "write", description: { en: "Starts an upload of a large file to a one-time URL." } },
|
|
@@ -34,10 +37,10 @@ export function registerFileUploadTools(server, options) {
|
|
|
34
37
|
return;
|
|
35
38
|
const ownerId = (options.getOwnerId ?? ((identity) => identity.userId))(options.identity);
|
|
36
39
|
server.registerTool(CREATE_UPLOAD_TOOL_NAME, {
|
|
37
|
-
description:
|
|
40
|
+
description: options.descriptions?.create_upload ?? FILE_UPLOAD_TOOL_DESCRIPTIONS.create_upload,
|
|
38
41
|
inputSchema: createUploadInput,
|
|
39
42
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
|
|
40
|
-
}, (args) => answer(CREATE_UPLOAD_TOOL_NAME, async () => {
|
|
43
|
+
}, (args) => answer(CREATE_UPLOAD_TOOL_NAME, options.hints, async () => {
|
|
41
44
|
const ctx = await options.getContext();
|
|
42
45
|
const created = await createUpload(ctx, {
|
|
43
46
|
ownerId,
|
|
@@ -50,13 +53,18 @@ export function registerFileUploadTools(server, options) {
|
|
|
50
53
|
return created.ok ? describeCreatedUpload(created.value, args.size) : created;
|
|
51
54
|
}));
|
|
52
55
|
server.registerTool(FINALIZE_UPLOAD_TOOL_NAME, {
|
|
53
|
-
description:
|
|
56
|
+
description: options.descriptions?.finalize_upload ?? FILE_UPLOAD_TOOL_DESCRIPTIONS.finalize_upload,
|
|
54
57
|
inputSchema: finalizeUploadInput,
|
|
55
58
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
56
|
-
}, (args) => answer(FINALIZE_UPLOAD_TOOL_NAME, async () => {
|
|
59
|
+
}, (args) => answer(FINALIZE_UPLOAD_TOOL_NAME, options.hints, async () => {
|
|
57
60
|
const ctx = await options.getContext();
|
|
58
61
|
const finalized = await finalizeUpload(ctx, args.upload_id, { ownerId });
|
|
59
|
-
|
|
62
|
+
if (!finalized.ok)
|
|
63
|
+
return finalized;
|
|
64
|
+
const extra = options.onFinalized === undefined ? undefined : await options.onFinalized(finalized.value, ctx);
|
|
65
|
+
if (isFailure(extra))
|
|
66
|
+
return extra;
|
|
67
|
+
return { ...extra, ...describeStoredFile(finalized.value) };
|
|
60
68
|
}));
|
|
61
69
|
}
|
|
62
70
|
/**
|
|
@@ -92,12 +100,12 @@ function describeCreatedUpload(upload, size) {
|
|
|
92
100
|
function describeStoredFile(file) {
|
|
93
101
|
return { file_id: file.id, name: file.name, size: file.size, content_type: file.contentType, sha256: file.sha256 };
|
|
94
102
|
}
|
|
95
|
-
/** The tool's answer: a value as JSON text, an error code as its
|
|
96
|
-
async function answer(tool, work) {
|
|
103
|
+
/** The tool's answer: a value as JSON text, an error code as its hint or sentence, a thrown error as a fixed text. */
|
|
104
|
+
async function answer(tool, hints, work) {
|
|
97
105
|
try {
|
|
98
106
|
const value = await work();
|
|
99
107
|
if (isFailure(value))
|
|
100
|
-
return failure(
|
|
108
|
+
return failure(describeErrorCode(value.error, hints));
|
|
101
109
|
return { content: [{ type: "text", text: JSON.stringify(value) }] };
|
|
102
110
|
}
|
|
103
111
|
catch (error) {
|
|
@@ -105,6 +113,15 @@ async function answer(tool, work) {
|
|
|
105
113
|
return failure(filesMessages.en.errors.core.unexpected);
|
|
106
114
|
}
|
|
107
115
|
}
|
|
116
|
+
/** `<hint or files sentence> (<code>)`, or the code alone for another module's code without a hint. */
|
|
117
|
+
function describeErrorCode(code, hints) {
|
|
118
|
+
const hint = hints !== undefined && Object.hasOwn(hints, code) ? hints[code] : undefined;
|
|
119
|
+
if (hint !== undefined)
|
|
120
|
+
return `${hint} (${code})`;
|
|
121
|
+
if (code.startsWith("files."))
|
|
122
|
+
return `${getFilesErrorMessage(filesMessages.en, code)} (${code})`;
|
|
123
|
+
return code;
|
|
124
|
+
}
|
|
108
125
|
function failure(text) {
|
|
109
126
|
return { content: [{ type: "text", text }], isError: true };
|
|
110
127
|
}
|
package/dist/mcp/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../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CAAC,CAAC,CAAC,SAAS,CAAC;IACzF,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,GAAG,IAAI,KAAK,IAAI,GAAG,CAAC;IACnD,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;QAAE,OAAO,GAAG,oBAAoB,CAAC,aAAa,CAAC,EAAE,EAAE,IAAI,CAAC,KAAK,IAAI,GAAG,CAAC;IAClG,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,OAAO,CAAC,IAAY;IAC3B,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC9D,CAAC;AAED,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,IAAI,IAAI,KAAK,IAAI,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,OAAO,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ,CAAC;AACnJ,CAAC"}
|
package/dist/messages/en.d.ts
CHANGED
|
@@ -12,6 +12,10 @@ export declare const en: {
|
|
|
12
12
|
too_many_uploads: string;
|
|
13
13
|
upload_incomplete: string;
|
|
14
14
|
checksum_mismatch: string;
|
|
15
|
+
upload_expired: string;
|
|
16
|
+
upload_rejected: string;
|
|
17
|
+
network: string;
|
|
18
|
+
upload_aborted: string;
|
|
15
19
|
};
|
|
16
20
|
core: {
|
|
17
21
|
unexpected: string;
|
|
@@ -27,6 +31,7 @@ export declare const en: {
|
|
|
27
31
|
done: string;
|
|
28
32
|
wrongSize: string;
|
|
29
33
|
failed: string;
|
|
34
|
+
expired: string;
|
|
30
35
|
};
|
|
31
36
|
};
|
|
32
37
|
//# sourceMappingURL=en.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"en.d.ts","sourceRoot":"","sources":["../../src/messages/en.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,EAAE
|
|
1
|
+
{"version":3,"file":"en.d.ts","sourceRoot":"","sources":["../../src/messages/en.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmCd,CAAC"}
|
package/dist/messages/en.js
CHANGED
|
@@ -12,11 +12,16 @@ export const en = {
|
|
|
12
12
|
too_many_uploads: "Too many uploads are in progress. Finish or wait for one first.",
|
|
13
13
|
upload_incomplete: "The upload is not complete yet: some parts have not arrived.",
|
|
14
14
|
checksum_mismatch: "The uploaded file does not match its checksum.",
|
|
15
|
+
upload_expired: "This upload has expired. Start it again.",
|
|
16
|
+
upload_rejected: "The upload was refused: the file does not match what the upload expects.",
|
|
17
|
+
network: "The connection dropped. Try again to resume where it stopped.",
|
|
18
|
+
upload_aborted: "The upload was stopped.",
|
|
15
19
|
},
|
|
16
20
|
core: {
|
|
17
21
|
unexpected: "Something went wrong. Try again.",
|
|
18
22
|
},
|
|
19
|
-
},
|
|
23
|
+
},
|
|
24
|
+
uploadPage: {
|
|
20
25
|
title: "Upload a file",
|
|
21
26
|
intro: "Choose the file this upload is waiting for. It is sent in parts, and a broken connection resumes where it stopped.",
|
|
22
27
|
expected: "Expected: {name}, {size}.",
|
|
@@ -26,6 +31,7 @@ export const en = {
|
|
|
26
31
|
done: "Upload complete. Go back to where you started it to finish.",
|
|
27
32
|
wrongSize: "This file has a different size than the upload expects.",
|
|
28
33
|
failed: "The upload stopped. Press Upload again to resume.",
|
|
34
|
+
expired: "This upload link has expired. Start a new upload where you began this one.",
|
|
29
35
|
},
|
|
30
36
|
};
|
|
31
37
|
//# sourceMappingURL=en.js.map
|
package/dist/messages/en.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"en.js","sourceRoot":"","sources":["../../src/messages/en.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,EAAE,GAAG;IAChB,MAAM,E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KACtF;CACF,CAAC"}
|
package/dist/messages/index.d.ts
CHANGED
|
@@ -15,6 +15,10 @@ export declare const filesMessages: {
|
|
|
15
15
|
too_many_uploads: string;
|
|
16
16
|
upload_incomplete: string;
|
|
17
17
|
checksum_mismatch: string;
|
|
18
|
+
upload_expired: string;
|
|
19
|
+
upload_rejected: string;
|
|
20
|
+
network: string;
|
|
21
|
+
upload_aborted: string;
|
|
18
22
|
};
|
|
19
23
|
core: {
|
|
20
24
|
unexpected: string;
|
|
@@ -30,6 +34,7 @@ export declare const filesMessages: {
|
|
|
30
34
|
done: string;
|
|
31
35
|
wrongSize: string;
|
|
32
36
|
failed: string;
|
|
37
|
+
expired: string;
|
|
33
38
|
};
|
|
34
39
|
};
|
|
35
40
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/messages/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAE7B,0GAA0G;AAC1G,eAAO,MAAM,aAAa
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/messages/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAE7B,0GAA0G;AAC1G,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAAS,CAAC;AAEpC,MAAM,MAAM,aAAa,GAAG,OAAO,EAAE,CAAC;AAEtC,wFAAwF;AACxF,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAIlF"}
|
package/dist/next/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { getFilesContext } from "./context.js";
|
|
2
2
|
export { serveFileLinkRoute } from "./route.js";
|
|
3
|
+
export { createStoredFileRoute, type StoredFileRoute, type StoredFileRouteContext, type StoredFileRouteHandler, type StoredFileRouteOptions, } from "./stored-file-route.js";
|
|
3
4
|
export { serveUploadRoute } from "./upload-route.js";
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/next/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/next/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/next/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EACL,qBAAqB,EACrB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,GAC5B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/next/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
// The Next.js adapter of @softure-ai/files: the public link route, the upload route and the
|
|
2
|
-
// (docs/02-module-standard.md §8).
|
|
1
|
+
// The Next.js adapter of @softure-ai/files: the public link route, the owner route, the upload route and the
|
|
2
|
+
// request-side context (docs/02-module-standard.md §8).
|
|
3
3
|
export { getFilesContext } from "./context.js";
|
|
4
4
|
export { serveFileLinkRoute } from "./route.js";
|
|
5
|
+
export { createStoredFileRoute, } from "./stored-file-route.js";
|
|
5
6
|
export { serveUploadRoute } from "./upload-route.js";
|
|
6
7
|
//# sourceMappingURL=index.js.map
|
package/dist/next/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/next/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/next/index.ts"],"names":[],"mappings":"AAAA,6GAA6G;AAC7G,wDAAwD;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EACL,qBAAqB,GAKtB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { FilesContext } from "../server/context.js";
|
|
2
|
+
/** The second argument Next.js passes a handler of a `[id]` segment. */
|
|
3
|
+
export interface StoredFileRouteContext {
|
|
4
|
+
readonly params: Promise<{
|
|
5
|
+
readonly id: string;
|
|
6
|
+
}>;
|
|
7
|
+
}
|
|
8
|
+
export type StoredFileRouteHandler = (request: Request, route: StoredFileRouteContext) => Promise<Response>;
|
|
9
|
+
export interface StoredFileRoute {
|
|
10
|
+
readonly GET: StoredFileRouteHandler;
|
|
11
|
+
readonly HEAD: StoredFileRouteHandler;
|
|
12
|
+
}
|
|
13
|
+
export interface StoredFileRouteOptions {
|
|
14
|
+
/**
|
|
15
|
+
* The signed-in user's id, the same value the app passed to `saveFile({ ownerId })`; null when nobody is signed in
|
|
16
|
+
* (the route answers 404). Typically the app's session lookup through auth.
|
|
17
|
+
*/
|
|
18
|
+
readonly getOwnerId: (request: Request) => Promise<string | null>;
|
|
19
|
+
/** `inline` (the default: a player, an image) or `attachment` (a download). */
|
|
20
|
+
readonly disposition?: "attachment" | "inline";
|
|
21
|
+
/** The context the route reads; `getFilesContext()` (the registered config's database) by default. */
|
|
22
|
+
readonly getContext?: () => Promise<FilesContext>;
|
|
23
|
+
}
|
|
24
|
+
export declare function createStoredFileRoute(options: StoredFileRouteOptions): StoredFileRoute;
|
|
25
|
+
//# sourceMappingURL=stored-file-route.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stored-file-route.d.ts","sourceRoot":"","sources":["../../src/next/stored-file-route.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAIzD,wEAAwE;AACxE,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;QAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACnD;AAED,MAAM,MAAM,sBAAsB,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,sBAAsB,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAE5G,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,GAAG,EAAE,sBAAsB,CAAC;IACrC,QAAQ,CAAC,IAAI,EAAE,sBAAsB,CAAC;CACvC;AAED,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAClE,+EAA+E;IAC/E,QAAQ,CAAC,WAAW,CAAC,EAAE,YAAY,GAAG,QAAQ,CAAC;IAC/C,sGAAsG;IACtG,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,CAAC;CACnD;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,GAAG,eAAe,CAStF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { notFound, serveStoredFile } from "../server/serve.js";
|
|
2
|
+
import { getFilesContext } from "./context.js";
|
|
3
|
+
export function createStoredFileRoute(options) {
|
|
4
|
+
const getContext = options.getContext ?? (() => getFilesContext());
|
|
5
|
+
const handle = async (request, route) => {
|
|
6
|
+
const ownerId = await options.getOwnerId(request);
|
|
7
|
+
if (ownerId === null)
|
|
8
|
+
return notFound();
|
|
9
|
+
const { id } = await route.params;
|
|
10
|
+
return serveStoredFile(await getContext(), id, request, { ownerId, disposition: options.disposition });
|
|
11
|
+
};
|
|
12
|
+
return { GET: handle, HEAD: handle };
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=stored-file-route.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stored-file-route.js","sourceRoot":"","sources":["../../src/next/stored-file-route.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AA0B/C,MAAM,UAAU,qBAAqB,CAAC,OAA+B;IACnE,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,CAAC,GAAG,EAAE,CAAC,eAAe,EAAE,CAAC,CAAC;IACnE,MAAM,MAAM,GAA2B,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;QAC9D,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAClD,IAAI,OAAO,KAAK,IAAI;YAAE,OAAO,QAAQ,EAAE,CAAC;QACxC,MAAM,EAAE,EAAE,EAAE,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC;QAClC,OAAO,eAAe,CAAC,MAAM,UAAU,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IACzG,CAAC,CAAC;IACF,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AACvC,CAAC"}
|
package/dist/server/index.d.ts
CHANGED
|
@@ -14,6 +14,6 @@ export { countChunks, createUpload, finalizeUpload, getPartKey, getUpload, write
|
|
|
14
14
|
export { signUploadPath, verifyUploadPath } from "./upload-tokens.js";
|
|
15
15
|
export { FILES_UPLOAD_RATE_LIMIT_BUCKET, serveUpload } from "./serve-upload.js";
|
|
16
16
|
export { renderUploadPage } from "./upload-page.js";
|
|
17
|
-
export { parseRangeHeader, serveFileLink } from "./serve.js";
|
|
17
|
+
export { parseRangeHeader, serveFileLink, serveStoredFile, type ServeStoredFileOptions } from "./serve.js";
|
|
18
18
|
export { EMPTY_PAYLOAD_SHA256, encodeRfc3986, signRequest, type SigV4Credentials, type SignRequestInput } from "./sigv4.js";
|
|
19
19
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,KAAK,GAAG,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,EACL,SAAS,EACT,UAAU,EACV,QAAQ,EACR,aAAa,EACb,SAAS,EACT,QAAQ,EACR,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,cAAc,GACpB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,gBAAgB,EAAE,KAAK,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,eAAe,EAAE,KAAK,WAAW,EAAE,KAAK,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACjI,OAAO,EACL,cAAc,EACd,eAAe,EACf,cAAc,EACd,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EACjB,KAAK,oBAAoB,GAC1B,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,KAAK,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACpH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,cAAc,EAAE,MAAM,WAAW,CAAC;AACxJ,OAAO,EACL,WAAW,EACX,YAAY,EACZ,cAAc,EACd,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,GAC5B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,8BAA8B,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,eAAe,EAAE,KAAK,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAC3G,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,WAAW,EAAE,KAAK,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/server/index.js
CHANGED
|
@@ -16,6 +16,6 @@ export { countChunks, createUpload, finalizeUpload, getPartKey, getUpload, write
|
|
|
16
16
|
export { signUploadPath, verifyUploadPath } from "./upload-tokens.js";
|
|
17
17
|
export { FILES_UPLOAD_RATE_LIMIT_BUCKET, serveUpload } from "./serve-upload.js";
|
|
18
18
|
export { renderUploadPage } from "./upload-page.js";
|
|
19
|
-
export { parseRangeHeader, serveFileLink } from "./serve.js";
|
|
19
|
+
export { parseRangeHeader, serveFileLink, serveStoredFile } from "./serve.js";
|
|
20
20
|
export { EMPTY_PAYLOAD_SHA256, encodeRfc3986, signRequest } from "./sigv4.js";
|
|
21
21
|
//# sourceMappingURL=index.js.map
|
package/dist/server/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"m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,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,eAAe,EAA+B,MAAM,YAAY,CAAC;AAC3G,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,WAAW,EAAgD,MAAM,YAAY,CAAC"}
|
package/dist/server/serve.d.ts
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
import type { ByteRange } from "../contract.js";
|
|
2
2
|
import type { FilesContext } from "./context.js";
|
|
3
|
+
/** The one answer for every link or lookup that does not lead to a live file. */
|
|
4
|
+
export declare function notFound(): Response;
|
|
3
5
|
/** Answers a request for a public link (`GET` or `HEAD`). */
|
|
4
6
|
export declare function serveFileLink(ctx: FilesContext, request: Request): Promise<Response>;
|
|
7
|
+
export interface ServeStoredFileOptions {
|
|
8
|
+
/** The signed-in user the app's session names; another owner's file reads as missing. */
|
|
9
|
+
readonly ownerId: string;
|
|
10
|
+
/** `inline` (the default: shown in the app's own page, a player or an image) or `attachment` (a download). */
|
|
11
|
+
readonly disposition?: "attachment" | "inline";
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Answers a request (`GET` or `HEAD`) for a stored file on behalf of its signed-in owner: the answer of a public link
|
|
15
|
+
* (single byte ranges, `private, no-store`, `nosniff`, the sandboxing CSP) under the file's stored name, with no link
|
|
16
|
+
* to mint or verify. The caller has already checked the session; a file that is missing, expired, deleted or another
|
|
17
|
+
* owner's gets the same `404`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function serveStoredFile(ctx: FilesContext, fileId: string, request: Request, options: ServeStoredFileOptions): Promise<Response>;
|
|
5
20
|
/**
|
|
6
21
|
* The single byte range a `Range` header asks for in a file of `size` bytes (RFC 9110 §14): null to answer the whole
|
|
7
22
|
* file (no header, a malformed one, another unit or several ranges, which a server may ignore), `"unsatisfiable"`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../src/server/serve.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../src/server/serve.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAejD,iFAAiF;AACjF,wBAAgB,QAAQ,IAAI,QAAQ,CASnC;AAED,6DAA6D;AAC7D,wBAAsB,aAAa,CAAC,GAAG,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAW1F;AAED,MAAM,WAAW,sBAAsB;IACrC,yFAAyF;IACzF,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,8GAA8G;IAC9G,QAAQ,CAAC,WAAW,CAAC,EAAE,YAAY,GAAG,QAAQ,CAAC;CAChD;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CAAC,GAAG,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAK7I;AAqDD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,eAAe,GAAG,IAAI,CAiBvG"}
|
package/dist/server/serve.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
// The
|
|
2
|
-
//
|
|
3
|
-
//
|
|
1
|
+
// The answer for a stored file, framework-free, behind a public link (`serveFileLink`) or for its signed-in owner
|
|
2
|
+
// (`serveStoredFile`): `GET` and `HEAD` with `Content-Length`, `Accept-Ranges`, single byte ranges (`206`, `416`),
|
|
3
|
+
// `Content-Disposition`, and `Cache-Control: private, no-store` so no CDN keeps a copy. Every dead link or lookup
|
|
4
|
+
// (forged, expired, revoked, deleted, another owner's, missing from storage) gets the same `404`. A stored file is user
|
|
4
5
|
// content on the app's origin, so it is sent with `nosniff` and a sandboxing CSP: an HTML or SVG file never runs.
|
|
5
6
|
import { errorLogLabel } from "@softure-ai/core";
|
|
6
7
|
import { findLiveRow } from "./files.js";
|
|
@@ -14,8 +15,8 @@ const BASE_HEADERS = {
|
|
|
14
15
|
};
|
|
15
16
|
const ALLOWED_METHODS = "GET, HEAD";
|
|
16
17
|
const NOT_FOUND_BODY = "Not found\n";
|
|
17
|
-
/** The one answer for every link that does not lead to a live file. */
|
|
18
|
-
function notFound() {
|
|
18
|
+
/** The one answer for every link or lookup that does not lead to a live file. */
|
|
19
|
+
export function notFound() {
|
|
19
20
|
return new Response(NOT_FOUND_BODY, {
|
|
20
21
|
status: 404,
|
|
21
22
|
headers: {
|
|
@@ -27,12 +28,8 @@ function notFound() {
|
|
|
27
28
|
}
|
|
28
29
|
/** Answers a request for a public link (`GET` or `HEAD`). */
|
|
29
30
|
export async function serveFileLink(ctx, request) {
|
|
30
|
-
if (request
|
|
31
|
-
return
|
|
32
|
-
status: 405,
|
|
33
|
-
headers: { ...BASE_HEADERS, allow: ALLOWED_METHODS },
|
|
34
|
-
});
|
|
35
|
-
}
|
|
31
|
+
if (!isReadMethod(request))
|
|
32
|
+
return methodNotAllowed();
|
|
36
33
|
const link = verifyFileLink(ctx, new URL(request.url).pathname);
|
|
37
34
|
if (!link.ok) {
|
|
38
35
|
if (link.error !== "files.not_found")
|
|
@@ -42,12 +39,39 @@ export async function serveFileLink(ctx, request) {
|
|
|
42
39
|
const row = await findLiveRow(ctx, link.value.fileId);
|
|
43
40
|
if (row?.linkGeneration !== link.value.generation)
|
|
44
41
|
return notFound();
|
|
45
|
-
const
|
|
42
|
+
const disposition = getFilesOptions(ctx.config).links.disposition;
|
|
43
|
+
return answerStoredFile(ctx, request, row, { name: link.value.name, disposition });
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Answers a request (`GET` or `HEAD`) for a stored file on behalf of its signed-in owner: the answer of a public link
|
|
47
|
+
* (single byte ranges, `private, no-store`, `nosniff`, the sandboxing CSP) under the file's stored name, with no link
|
|
48
|
+
* to mint or verify. The caller has already checked the session; a file that is missing, expired, deleted or another
|
|
49
|
+
* owner's gets the same `404`.
|
|
50
|
+
*/
|
|
51
|
+
export async function serveStoredFile(ctx, fileId, request, options) {
|
|
52
|
+
if (!isReadMethod(request))
|
|
53
|
+
return methodNotAllowed();
|
|
54
|
+
const row = await findLiveRow(ctx, fileId, { ownerId: options.ownerId });
|
|
55
|
+
if (row === undefined)
|
|
56
|
+
return notFound();
|
|
57
|
+
return answerStoredFile(ctx, request, row, { name: row.originalName, disposition: options.disposition ?? "inline" });
|
|
58
|
+
}
|
|
59
|
+
function isReadMethod(request) {
|
|
60
|
+
return request.method === "GET" || request.method === "HEAD";
|
|
61
|
+
}
|
|
62
|
+
function methodNotAllowed() {
|
|
63
|
+
return new Response(null, {
|
|
64
|
+
status: 405,
|
|
65
|
+
headers: { ...BASE_HEADERS, allow: ALLOWED_METHODS },
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/** The bytes of a live row as the answer to a `GET` or `HEAD`, honouring a single byte range. */
|
|
69
|
+
async function answerStoredFile(ctx, request, row, options) {
|
|
46
70
|
const headers = {
|
|
47
71
|
...BASE_HEADERS,
|
|
48
72
|
"content-type": row.contentType,
|
|
49
73
|
"accept-ranges": "bytes",
|
|
50
|
-
"content-disposition": formatContentDisposition(options.
|
|
74
|
+
"content-disposition": formatContentDisposition(options.disposition, options.name),
|
|
51
75
|
"content-security-policy": "sandbox; default-src 'none'",
|
|
52
76
|
};
|
|
53
77
|
const range = parseRangeHeader(request.headers.get("range"), row.size);
|
|
@@ -65,7 +89,7 @@ export async function serveFileLink(ctx, request) {
|
|
|
65
89
|
return new Response(null, { status, headers });
|
|
66
90
|
let body;
|
|
67
91
|
try {
|
|
68
|
-
body = await
|
|
92
|
+
body = await getFilesOptions(ctx.config).storage.get(row.storageKey, range ?? undefined);
|
|
69
93
|
}
|
|
70
94
|
catch (error) {
|
|
71
95
|
console.error(`@softure-ai/files: reading file ${row.id} from storage failed: ${errorLogLabel(error)}`);
|
package/dist/server/serve.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve.js","sourceRoot":"","sources":["../../src/server/serve.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"serve.js","sourceRoot":"","sources":["../../src/server/serve.ts"],"names":[],"mappings":"AAAA,kHAAkH;AAClH,mHAAmH;AACnH,kHAAkH;AAClH,wHAAwH;AACxH,kHAAkH;AAClH,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAIjD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,YAAY,GAAG;IACnB,eAAe,EAAE,mBAAmB;IACpC,wBAAwB,EAAE,SAAS;IACnC,iBAAiB,EAAE,aAAa;CACxB,CAAC;AACX,MAAM,eAAe,GAAG,WAAW,CAAC;AAEpC,MAAM,cAAc,GAAG,aAAa,CAAC;AAErC,iFAAiF;AACjF,MAAM,UAAU,QAAQ;IACtB,OAAO,IAAI,QAAQ,CAAC,cAAc,EAAE;QAClC,MAAM,EAAE,GAAG;QACX,OAAO,EAAE;YACP,GAAG,YAAY;YACf,cAAc,EAAE,2BAA2B;YAC3C,gBAAgB,EAAE,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC;SAChD;KACF,CAAC,CAAC;AACL,CAAC;AAED,6DAA6D;AAC7D,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,GAAiB,EAAE,OAAgB;IACrE,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC;QAAE,OAAO,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AC,CAAC,CAAC,qBAAqB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IAC/E,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAChC,MAAM,CAAC,EAAE,KAAK,GAAG,EAAE,EAAE,IAAI,GAAG,EAAE,CAAC,GAAG,KAAK,CAAC;IACxC,IAAI,KAAK,KAAK,EAAE,IAAI,IAAI,KAAK,EAAE;QAAE,OAAO,IAAI,CAAC;IAC7C,IAAI,KAAK,KAAK,EAAE,EAAE,CAAC;QACjB,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QAC5B,IAAI,MAAM,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC;YAAE,OAAO,eAAe,CAAC;QACvD,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,MAAM,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,GAAG,CAAC,EAAE,CAAC;IAC9D,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC5B,IAAI,IAAI,KAAK,EAAE,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK;QAAE,OAAO,IAAI,CAAC;IACrD,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,eAAe,CAAC;IAC1C,OAAO;QACL,KAAK;QACL,GAAG,EAAE,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,GAAG,CAAC,CAAC;KAC/D,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload-page.d.ts","sourceRoot":"","sources":["../../src/server/upload-page.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"upload-page.d.ts","sourceRoot":"","sources":["../../src/server/upload-page.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAiCjD,iFAAiF;AACjF,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,YAAY,GAAG,QAAQ,CA0ClG"}
|
|
@@ -1,45 +1,38 @@
|
|
|
1
1
|
// The browser fallback for an upload session: a small page on the upload URL itself, for a person on a phone or an
|
|
2
2
|
// assistant that cannot run `curl`. It sends the missing chunks of the chosen file one by one with `fetch`, so a
|
|
3
|
-
// broken connection resumes where it stopped.
|
|
4
|
-
// style, allowed by a per-response nonce. The copy
|
|
3
|
+
// broken connection resumes where it stopped. The loop is `sendUpload` of `@softure-ai/files/client`, inlined. No
|
|
4
|
+
// framework and no external asset: one inline script and one inline style, allowed by a per-response nonce. The copy
|
|
5
|
+
// comes from the module dictionary (`uploadPage`).
|
|
5
6
|
import { randomBytes } from "node:crypto";
|
|
6
7
|
import { selectMessages } from "@softure-ai/core";
|
|
8
|
+
import { sendUpload } from "../client/send-upload.js";
|
|
7
9
|
import { getFilesModule } from "./options.js";
|
|
8
10
|
const STYLE = `body{font:16px/1.5 system-ui,sans-serif;max-width:32rem;margin:2rem auto;padding:0 1rem}
|
|
9
11
|
button,input{font:inherit}button{margin-top:1rem;padding:.5rem 1rem}progress{width:100%;margin-top:1rem}
|
|
10
12
|
p[role=status]{min-height:1.5em}`;
|
|
11
|
-
|
|
13
|
+
// The page's script: the client's own `sendUpload`, inlined from its source, then the few lines that wire it to the
|
|
14
|
+
// form. `sendUpload` references nothing outside its body (see `client/send-upload.ts`).
|
|
15
|
+
const SCRIPT = `${sendUpload.toString()}
|
|
16
|
+
const config = JSON.parse(document.getElementById("upload-config").textContent);
|
|
12
17
|
const input = document.getElementById("file");
|
|
13
18
|
const button = document.getElementById("start");
|
|
14
19
|
const bar = document.getElementById("bar");
|
|
15
20
|
const status = document.getElementById("status");
|
|
16
21
|
const megabytes = (bytes) => (bytes / 1048576).toFixed(1) + " MB";
|
|
17
22
|
function show(text) { status.textContent = text; }
|
|
23
|
+
function showProgress(progress) {
|
|
24
|
+
bar.value = progress.totalBytes === 0 ? 1 : progress.sentBytes / progress.totalBytes;
|
|
25
|
+
show(config.text.progress.replace("{done}", megabytes(progress.sentBytes)).replace("{total}", megabytes(progress.totalBytes)));
|
|
26
|
+
}
|
|
18
27
|
async function upload() {
|
|
19
28
|
const file = input.files[0];
|
|
20
29
|
if (!file) return;
|
|
21
30
|
if (file.size !== config.size) { show(config.text.wrongSize); return; }
|
|
22
31
|
button.disabled = true;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
let done = state.receivedBytes;
|
|
28
|
-
for (const index of state.missingChunks) {
|
|
29
|
-
const start = index * config.chunkSize;
|
|
30
|
-
const end = Math.min(start + config.chunkSize, config.size) - 1;
|
|
31
|
-
const sent = await fetch(location.href, { method: "PUT", headers: { "content-range": "bytes " + start + "-" + end + "/" + config.size }, body: file.slice(start, end + 1) });
|
|
32
|
-
if (!sent.ok) throw new Error("status " + sent.status);
|
|
33
|
-
done += end - start + 1;
|
|
34
|
-
bar.value = done / config.size;
|
|
35
|
-
show(config.text.progress.replace("{done}", megabytes(done)).replace("{total}", megabytes(config.size)));
|
|
36
|
-
}
|
|
37
|
-
bar.value = 1;
|
|
38
|
-
show(config.text.done);
|
|
39
|
-
} catch {
|
|
40
|
-
show(config.text.failed);
|
|
41
|
-
button.disabled = false;
|
|
42
|
-
}
|
|
32
|
+
const sent = await sendUpload(file, { uploadUrl: location.href, onProgress: showProgress });
|
|
33
|
+
if (sent.ok) { bar.value = 1; show(config.text.done); return; }
|
|
34
|
+
show(sent.error === "files.upload_expired" ? config.text.expired : config.text.failed);
|
|
35
|
+
button.disabled = sent.error === "files.upload_expired";
|
|
43
36
|
}
|
|
44
37
|
button.addEventListener("click", upload);`;
|
|
45
38
|
/** The page for a session; a finalized or complete one shows that it is done. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload-page.js","sourceRoot":"","sources":["../../src/server/upload-page.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH,iHAAiH;AACjH,
|
|
1
|
+
{"version":3,"file":"upload-page.js","sourceRoot":"","sources":["../../src/server/upload-page.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH,iHAAiH;AACjH,kHAAkH;AAClH,qHAAqH;AACrH,mDAAmD;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAItD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,KAAK,GAAG;;iCAEmB,CAAC;AAElC,oHAAoH;AACpH,wFAAwF;AACxF,MAAM,MAAM,GAAG,GAAG,UAAU,CAAC,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;;;0CAsBG,CAAC;AAE3C,iFAAiF;AACjF,MAAM,UAAU,gBAAgB,CAAC,GAAiC,EAAE,MAAoB;IACtF,MAAM,IAAI,GAAI,cAAc,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,MAAM,CAAmB,CAAC,UAAU,CAAC;IAClH,MAAM,KAAK,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACjD,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,KAAK,UAAU,IAAI,MAAM,CAAC,KAAK,KAAK,WAAW,CAAC;IAC3E,MAAM,MAAM,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,IAAI,EAAE,CAAC;IACxE,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