@softure-ai/files 0.2.0 → 0.4.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 +33 -0
- package/README.md +131 -4
- 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/jobs/index.d.ts +23 -1
- package/dist/jobs/index.d.ts.map +1 -1
- package/dist/jobs/index.js +46 -11
- package/dist/jobs/index.js.map +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 +2 -2
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +2 -2
- package/dist/server/index.js.map +1 -1
- package/dist/server/prune.d.ts +4 -0
- package/dist/server/prune.d.ts.map +1 -1
- package/dist/server/prune.js +8 -2
- package/dist/server/prune.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 +8 -3
- 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/jobs/index.ts +66 -13
- 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 +2 -2
- package/src/server/prune.ts +10 -1
- package/src/server/serve.ts +51 -14
- package/src/server/upload-page.ts +16 -23
package/dist/jobs/index.d.ts
CHANGED
|
@@ -1,4 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
export type FilesJobsLogFields = Readonly<Record<string, unknown>>;
|
|
2
|
+
/**
|
|
3
|
+
* Where the files jobs report a run. A subset of `@softure-ai/observability`'s `Logger`, so an app passes
|
|
4
|
+
* `createLogger("files")` as it is; without one, lines go to the console.
|
|
5
|
+
*/
|
|
6
|
+
export interface FilesJobsLogger {
|
|
7
|
+
info(message: string, fields?: FilesJobsLogFields): void;
|
|
8
|
+
}
|
|
9
|
+
export interface CreateFilesJobHandlersOptions {
|
|
10
|
+
readonly logger?: FilesJobsLogger;
|
|
11
|
+
}
|
|
12
|
+
/** One `key=value` line per call; an array is joined with commas. */
|
|
13
|
+
export declare const consoleFilesJobsLogger: FilesJobsLogger;
|
|
14
|
+
/**
|
|
15
|
+
* Handlers for the worker with a logger of the app's choice: `handlers: { ...createFilesJobHandlers({ logger }) }`.
|
|
16
|
+
* Every `files.prune` run logs one line `files.prune finished` with `removed`, `freedBytes`, `failedFiles`,
|
|
17
|
+
* `deletedUploads`, `failedUploads` and, when at most 10 files went, their ids as `fileIds`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createFilesJobHandlers(options?: CreateFilesJobHandlersOptions): {
|
|
20
|
+
/** Removes expired and deleted files from storage and the table (`pruneFiles`). */
|
|
21
|
+
"files.prune": import("@softure-ai/jobs").JobHandler<Record<string, never>>;
|
|
22
|
+
};
|
|
23
|
+
/** Handlers for the worker: `handlers: { ...filesJobHandlers }`; they log to the console. */
|
|
2
24
|
export declare const filesJobHandlers: {
|
|
3
25
|
/** Removes expired and deleted files from storage and the table (`pruneFiles`). */
|
|
4
26
|
"files.prune": import("@softure-ai/jobs").JobHandler<Record<string, never>>;
|
package/dist/jobs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/jobs/index.ts"],"names":[],"mappings":"AAOA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/jobs/index.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAEnE;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAC;CAC1D;AAED,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,MAAM,CAAC,EAAE,eAAe,CAAC;CACnC;AAID,qEAAqE;AACrE,eAAO,MAAM,sBAAsB,EAAE,eAEpC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,GAAE,6BAAkC;IAG9E,mFAAmF;;EAStF;AAED,6FAA6F;AAC7F,eAAO,MAAM,gBAAgB;IAZzB,mFAAmF;;CAY/B,CAAC;AAEzD,6EAA6E;AAC7E,eAAO,MAAM,iBAAiB;;;;CAED,CAAC"}
|
package/dist/jobs/index.js
CHANGED
|
@@ -3,20 +3,55 @@
|
|
|
3
3
|
import { ok } from "@softure-ai/core";
|
|
4
4
|
import { defineJobHandler } from "@softure-ai/jobs";
|
|
5
5
|
import { z } from "zod";
|
|
6
|
-
import { pruneFiles } from "../server/prune.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
payload: z.object({}),
|
|
12
|
-
run: async (_payload, ctx) => {
|
|
13
|
-
await pruneFiles(ctx);
|
|
14
|
-
return ok();
|
|
15
|
-
},
|
|
16
|
-
}),
|
|
6
|
+
import { PRUNE_REPORT_MAX_FILE_IDS, pruneFiles } from "../server/prune.js";
|
|
7
|
+
const PREFIX = "@softure-ai/files:";
|
|
8
|
+
/** One `key=value` line per call; an array is joined with commas. */
|
|
9
|
+
export const consoleFilesJobsLogger = {
|
|
10
|
+
info: (message, fields) => console.log(formatLine(message, fields)),
|
|
17
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Handlers for the worker with a logger of the app's choice: `handlers: { ...createFilesJobHandlers({ logger }) }`.
|
|
14
|
+
* Every `files.prune` run logs one line `files.prune finished` with `removed`, `freedBytes`, `failedFiles`,
|
|
15
|
+
* `deletedUploads`, `failedUploads` and, when at most 10 files went, their ids as `fileIds`.
|
|
16
|
+
*/
|
|
17
|
+
export function createFilesJobHandlers(options = {}) {
|
|
18
|
+
const logger = options.logger ?? consoleFilesJobsLogger;
|
|
19
|
+
return {
|
|
20
|
+
/** Removes expired and deleted files from storage and the table (`pruneFiles`). */
|
|
21
|
+
"files.prune": defineJobHandler({
|
|
22
|
+
payload: z.object({}),
|
|
23
|
+
run: async (_payload, ctx) => {
|
|
24
|
+
logger.info("files.prune finished", getPruneLogFields(await pruneFiles(ctx)));
|
|
25
|
+
return ok();
|
|
26
|
+
},
|
|
27
|
+
}),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** Handlers for the worker: `handlers: { ...filesJobHandlers }`; they log to the console. */
|
|
31
|
+
export const filesJobHandlers = createFilesJobHandlers();
|
|
18
32
|
/** Schedules for `jobs({ schedules: { ...filesJobSchedules } })`: hourly. */
|
|
19
33
|
export const filesJobSchedules = {
|
|
20
34
|
"files.prune": { every: "1h" },
|
|
21
35
|
};
|
|
36
|
+
function getPruneLogFields(report) {
|
|
37
|
+
const fields = {
|
|
38
|
+
removed: report.deletedFiles,
|
|
39
|
+
freedBytes: report.freedBytes,
|
|
40
|
+
failedFiles: report.failedFiles,
|
|
41
|
+
deletedUploads: report.deletedUploads,
|
|
42
|
+
failedUploads: report.failedUploads,
|
|
43
|
+
};
|
|
44
|
+
return report.deletedFiles > PRUNE_REPORT_MAX_FILE_IDS ? fields : { ...fields, fileIds: report.removedFileIds };
|
|
45
|
+
}
|
|
46
|
+
function formatLine(message, fields) {
|
|
47
|
+
const parts = Object.entries(fields ?? {}).map(([key, value]) => `${key}=${formatValue(value)}`);
|
|
48
|
+
return [PREFIX, message, ...parts].join(" ");
|
|
49
|
+
}
|
|
50
|
+
function formatValue(value) {
|
|
51
|
+
if (Array.isArray(value))
|
|
52
|
+
return value.map(formatValue).join(",");
|
|
53
|
+
if (typeof value === "string")
|
|
54
|
+
return value;
|
|
55
|
+
return JSON.stringify(value) ?? String(value);
|
|
56
|
+
}
|
|
22
57
|
//# sourceMappingURL=index.js.map
|
package/dist/jobs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/jobs/index.ts"],"names":[],"mappings":"AAAA,kHAAkH;AAClH,yDAAyD;AACzD,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAA4C,MAAM,kBAAkB,CAAC;AAC9F,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/jobs/index.ts"],"names":[],"mappings":"AAAA,kHAAkH;AAClH,yDAAyD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UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,cAAc,EAAE,MAAM,CAAC,cAAc;QACrC,aAAa,EAAE,MAAM,CAAC,aAAa;KACpC,CAAC;IACF,OAAO,MAAM,CAAC,YAAY,GAAG,yBAAyB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,cAAc,EAAE,CAAC;AAClH,CAAC;AAED,SAAS,UAAU,CAAC,OAAe,EAAE,MAAsC;IACzE,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACjG,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAClE,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5C,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;AAChD,CAAC"}
|
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,sBAAsB,CAAC;AAGzD,eAAO,MAAM,uBAAuB,kBAAkB,CAAC;AACvD,eAAO,MAAM,yBAAyB,oBAAoB,CAAC;AAE3D,wGAAwG;AACxG,eAAO,MAAM,6BAA6B;;;CAShC,CAAC;AAEX,+GAA+G;AAC/G,eAAO,MAAM,qBAAqB;;;;;;;;;;;;EAGxB,CAAC;AAEX,2GAA2G;AAC3G,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,QAAQ,EAAE,sBAAsB,CAAC;IAC1C,uFAAuF;IACvF,QAAQ,CAAC,UAAU,EAAE,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAChE,mEAAmE;IACnE,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,sBAAsB,KAAK,MAAM,CAAC;IACnE,uDAAuD;IACvD,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,YAAY,KAAK,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC7F,oFAAoF;IACpF,QAAQ,CAAC,YAAY,CAAC,EAAE;QAAE,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/F;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACnD;AAED,6FAA6F;AAC7F,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,GAAG,CAAC,SAAS,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":["../../src/mcp/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,aAAa,EAA4B,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAE3E,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEpE,MAAM,CAAC,MAAM,uBAAuB,GAAG,eAAe,CAAC;AACvD,MAAM,CAAC,MAAM,yBAAyB,GAAG,iBAAiB,CAAC;AAE3D,wGAAwG;AACxG,MAAM,CAAC,MAAM,6BAA6B,GAAG;IAC3C,aAAa,EACX,gHAAgH;QAClH,qHAAqH;QACrH,gH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AI,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,EAAE;QACN,KAAK,EAAE;YACL,gBAAgB,EAAE,+DAA+D;YACjF,gBAAgB,EAAE,0DAA0D;YAC5E,aAAa,EAAE,iCAAiC;YAChD,SAAS,EAAE,wBAAwB;YACnC,cAAc,EAAE,uCAAuC;YACvD,SAAS,EAAE,yBAAyB;YACpC,qBAAqB,EAAE,+CAA+C;YACtE,wBAAwB,EAAE,uCAAuC;YACjE,gBAAgB,EAAE,iEAAiE;YACnF,iBAAiB,EAAE,8DAA8D;YACjF,iBAAiB,EAAE,gDAAgD;
|
|
1
|
+
{"version":3,"file":"en.js","sourceRoot":"","sources":["../../src/messages/en.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,EAAE,GAAG;IAChB,MAAM,EAAE;QACN,KAAK,EAAE;YACL,gBAAgB,EAAE,+DAA+D;YACjF,gBAAgB,EAAE,0DAA0D;YAC5E,aAAa,EAAE,iCAAiC;YAChD,SAAS,EAAE,wBAAwB;YACnC,cAAc,EAAE,uCAAuC;YACvD,SAAS,EAAE,yBAAyB;YACpC,qBAAqB,EAAE,+CAA+C;YACtE,wBAAwB,EAAE,uCAAuC;YACjE,gBAAgB,EAAE,iEAAiE;YACnF,iBAAiB,EAAE,8DAA8D;YACjF,iBAAiB,EAAE,gDAAgD;YACnE,cAAc,EAAE,0CAA0C;YAC1D,eAAe,EAAE,0EAA0E;YAC3F,OAAO,EAAE,+DAA+D;YACxE,cAAc,EAAE,yBAAyB;SAC1C;QACD,IAAI,EAAE;YACJ,UAAU,EAAE,kCAAkC;SAC/C;KACF;IACD,UAAU,EAAE;QACV,KAAK,EAAE,eAAe;QACtB,KAAK,EAAE,oHAAoH;QAC3H,QAAQ,EAAE,2BAA2B;QACrC,MAAM,EAAE,eAAe;QACvB,KAAK,EAAE,QAAQ;QACf,QAAQ,EAAE,6BAA6B;QACvC,IAAI,EAAE,6DAA6D;QACnE,SAAS,EAAE,yDAAyD;QACpE,MAAM,EAAE,mDAAmD;QAC3D,OAAO,EAAE,4EAA4E;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
|
@@ -7,13 +7,13 @@ export { createLocalStorage, type LocalStorageOptions } from "./local-storage.js
|
|
|
7
7
|
export { DEFAULT_CONTENT_TYPE, formatContentDisposition, normalizeContentType, sanitizeFileName } from "./names.js";
|
|
8
8
|
export { getFilesModule, getFilesOptions, getLinksRoute, getUploadsRoute } from "./options.js";
|
|
9
9
|
export { deleteFilesUserData, exportFilesUserData, filesPrivacyContributor, type FilesDeletionReport, type FilesUserData } from "./privacy.js";
|
|
10
|
-
export { pruneFiles, type PruneFilesOptions, type PruneFilesReport } from "./prune.js";
|
|
10
|
+
export { PRUNE_REPORT_MAX_FILE_IDS, pruneFiles, type PruneFilesOptions, type PruneFilesReport } from "./prune.js";
|
|
11
11
|
export { createS3Storage, S3_ACCESS_KEY_ID_ENV, S3_SECRET_ACCESS_KEY_ENV, S3StorageError, splitIntoParts, type S3StorageOptions, } from "./s3-storage.js";
|
|
12
12
|
export { saveFile, validateFileDescription, type FileDescription, type FileDescriptionInput, type SaveFileInput, type SaveFileResult } from "./save.js";
|
|
13
13
|
export { countChunks, createUpload, finalizeUpload, getPartKey, getUpload, writeUploadChunk, type CreateUploadInput, type CreateUploadResult, type FinalizeUploadResult, type UploadChunkErrorCode, type UploadLookupOptions, type WriteUploadChunkInput, type WriteUploadChunkResult, } from "./uploads.js";
|
|
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,oBAAo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E,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
|
@@ -9,13 +9,13 @@ export { createLocalStorage } from "./local-storage.js";
|
|
|
9
9
|
export { DEFAULT_CONTENT_TYPE, formatContentDisposition, normalizeContentType, sanitizeFileName } from "./names.js";
|
|
10
10
|
export { getFilesModule, getFilesOptions, getLinksRoute, getUploadsRoute } from "./options.js";
|
|
11
11
|
export { deleteFilesUserData, exportFilesUserData, filesPrivacyContributor } from "./privacy.js";
|
|
12
|
-
export { pruneFiles } from "./prune.js";
|
|
12
|
+
export { PRUNE_REPORT_MAX_FILE_IDS, pruneFiles } from "./prune.js";
|
|
13
13
|
export { createS3Storage, S3_ACCESS_KEY_ID_ENV, S3_SECRET_ACCESS_KEY_ENV, S3StorageError, splitIntoParts, } from "./s3-storage.js";
|
|
14
14
|
export { saveFile, validateFileDescription } from "./save.js";
|
|
15
15
|
export { countChunks, createUpload, finalizeUpload, getPartKey, getUpload, writeUploadChunk, } from "./uploads.js";
|
|
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":[],"mappings":"AAAA,kHAAkH;AAClH,yEAAyE;AACz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AAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACpH,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/F,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,uBAAuB,EAAgD,MAAM,cAAc,CAAC;AAC/I,OAAO,EAAE,yBAAyB,EAAE,UAAU,EAAiD,MAAM,YAAY,CAAC;AAClH,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,wBAAwB,EACxB,cAAc,EACd,cAAc,GAEf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,uBAAuB,EAA4F,MAAM,WAAW,CAAC;AACxJ,OAAO,EACL,WAAW,EACX,YAAY,EACZ,cAAc,EACd,UAAU,EACV,SAAS,EACT,gBAAgB,GAQjB,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,EAA+B,MAAM,YAAY,CAAC;AAC3G,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,WAAW,EAAgD,MAAM,YAAY,CAAC"}
|
package/dist/server/prune.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { FilesContext } from "./context.js";
|
|
2
|
+
/** How many removed file ids a prune report keeps (`removedFileIds`). */
|
|
3
|
+
export declare const PRUNE_REPORT_MAX_FILE_IDS = 10;
|
|
2
4
|
export interface PruneFilesOptions {
|
|
3
5
|
/** Rows read per round; rounds repeat until one comes back short. */
|
|
4
6
|
readonly batchSize?: number;
|
|
@@ -6,6 +8,8 @@ export interface PruneFilesOptions {
|
|
|
6
8
|
export interface PruneFilesReport {
|
|
7
9
|
readonly deletedFiles: number;
|
|
8
10
|
readonly freedBytes: number;
|
|
11
|
+
/** Ids of the first `PRUNE_REPORT_MAX_FILE_IDS` (10) removed files, in removal order; `deletedFiles` has the count. */
|
|
12
|
+
readonly removedFileIds: readonly string[];
|
|
9
13
|
/** Files whose storage delete failed; they stay for the next run. */
|
|
10
14
|
readonly failedFiles: number;
|
|
11
15
|
/** Expired upload sessions removed with their parts. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prune.d.ts","sourceRoot":"","sources":["../../src/server/prune.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAMjD,MAAM,WAAW,iBAAiB;IAChC,qEAAqE;IACrE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,qEAAqE;IACrE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,wDAAwD;IACxD,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,4FAA4F;IAC5F,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AAED,wBAAsB,UAAU,CAAC,GAAG,EAAE,YAAY,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,gBAAgB,CAAC,
|
|
1
|
+
{"version":3,"file":"prune.d.ts","sourceRoot":"","sources":["../../src/server/prune.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAMjD,yEAAyE;AACzE,eAAO,MAAM,yBAAyB,KAAK,CAAC;AAE5C,MAAM,WAAW,iBAAiB;IAChC,qEAAqE;IACrE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,uHAAuH;IACvH,QAAQ,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3C,qEAAqE;IACrE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,wDAAwD;IACxD,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,4FAA4F;IAC5F,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AAED,wBAAsB,UAAU,CAAC,GAAG,EAAE,YAAY,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA4B9G"}
|
package/dist/server/prune.js
CHANGED
|
@@ -6,12 +6,15 @@ import { files } from "../schema.js";
|
|
|
6
6
|
import { removeMarkedFile } from "./files.js";
|
|
7
7
|
import { pruneUploads } from "./uploads.js";
|
|
8
8
|
const DEFAULT_BATCH_SIZE = 500;
|
|
9
|
+
/** How many removed file ids a prune report keeps (`removedFileIds`). */
|
|
10
|
+
export const PRUNE_REPORT_MAX_FILE_IDS = 10;
|
|
9
11
|
export async function pruneFiles(ctx, options = {}) {
|
|
10
12
|
const batchSize = Math.max(1, Math.trunc(options.batchSize ?? DEFAULT_BATCH_SIZE));
|
|
11
13
|
const now = ctx.clock.now();
|
|
12
14
|
let deletedFiles = 0;
|
|
13
15
|
let freedBytes = 0;
|
|
14
16
|
let failedFiles = 0;
|
|
17
|
+
const removedFileIds = [];
|
|
15
18
|
for (;;) {
|
|
16
19
|
const rows = await ctx.db
|
|
17
20
|
.select()
|
|
@@ -24,13 +27,16 @@ export async function pruneFiles(ctx, options = {}) {
|
|
|
24
27
|
if (await removeMarkedFile(ctx, row)) {
|
|
25
28
|
deletedFiles += 1;
|
|
26
29
|
freedBytes += row.size;
|
|
30
|
+
if (removedFileIds.length < PRUNE_REPORT_MAX_FILE_IDS)
|
|
31
|
+
removedFileIds.push(row.id);
|
|
27
32
|
}
|
|
28
33
|
else {
|
|
29
34
|
failedFiles += 1;
|
|
30
35
|
}
|
|
31
36
|
}
|
|
32
|
-
if (rows.length < batchSize)
|
|
33
|
-
return { deletedFiles, freedBytes, failedFiles, ...(await pruneUploads(ctx, batchSize)) };
|
|
37
|
+
if (rows.length < batchSize) {
|
|
38
|
+
return { deletedFiles, freedBytes, removedFileIds, failedFiles, ...(await pruneUploads(ctx, batchSize)) };
|
|
39
|
+
}
|
|
34
40
|
}
|
|
35
41
|
}
|
|
36
42
|
//# sourceMappingURL=prune.js.map
|
package/dist/server/prune.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prune.js","sourceRoot":"","sources":["../../src/server/prune.ts"],"names":[],"mappings":"AAAA,iHAAiH;AACjH,4DAA4D;AAC5D,oGAAoG;AACpG,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAErC,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,kBAAkB,GAAG,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"prune.js","sourceRoot":"","sources":["../../src/server/prune.ts"],"names":[],"mappings":"AAAA,iHAAiH;AACjH,4DAA4D;AAC5D,oGAAoG;AACpG,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAErC,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,kBAAkB,GAAG,GAAG,C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AAW,IAAI,CAAC,CAAC;YACnB,CAAC;QACH,CAAC;QACD,IAAI,IAAI,CAAC,MAAM,GAAG,SAAS,EAAE,CAAC;YAC5B,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,WAAW,EAAE,GAAG,CAAC,MAAM,YAAY,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC;QAC5G,CAAC;IACH,CAAC;AACH,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"}
|