Editors upload files to a page (attach button, paste or drop); images go into the document as images and other files as download cards. Files are stored in a new attachments collection, so PocketBase's local or S3 storage applies, and docwell-server streams them after checking the reader's page access. Documents keep the file's API path. Because <img> tags cannot send the Authorization header, clients load files with a short-lived signed file token (?token=) instead of the session token. Uploads are limited by DOCWELL_MAX_UPLOAD_MB (default 50), their type is sniffed from the content, and only images, PDFs and media are served inline, so an uploaded HTML or SVG file never runs on the API's origin. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
42 lines
1.8 KiB
JavaScript
42 lines
1.8 KiB
JavaScript
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
/// <reference path="../pb_data/types.d.ts" />
|
|
|
|
// Files attached to pages (images and other uploads). PocketBase stores them
|
|
// on its disk or in S3, whichever the storage settings select. docwell-server
|
|
// checks page access and streams them; the file field is protected so even
|
|
// PocketBase's own file URLs need a superuser file token.
|
|
|
|
migrate(
|
|
(app) => {
|
|
const users = app.findCollectionByNameOrId("users");
|
|
const pages = app.findCollectionByNameOrId("pages");
|
|
const workspaces = app.findCollectionByNameOrId("workspaces");
|
|
|
|
app.save(
|
|
new Collection({
|
|
type: "base",
|
|
name: "attachments",
|
|
fields: [
|
|
{ name: "workspace", type: "relation", collectionId: workspaces.id, maxSelect: 1, required: true, cascadeDelete: true },
|
|
{ name: "page", type: "relation", collectionId: pages.id, maxSelect: 1, required: true, cascadeDelete: true },
|
|
// 100 MB is PocketBase's ceiling here; docwell-server enforces the configured limit.
|
|
{ name: "file", type: "file", maxSelect: 1, maxSize: 104857600, protected: true, required: true },
|
|
{ name: "name", type: "text", required: true, max: 255 },
|
|
{ name: "mime", type: "text", max: 255 },
|
|
{ name: "size", type: "number", onlyInt: true, min: 0 },
|
|
{ name: "uploader", type: "relation", collectionId: users.id, maxSelect: 1, cascadeDelete: false },
|
|
{ name: "created", type: "autodate", onCreate: true, onUpdate: false },
|
|
{ name: "updated", type: "autodate", onCreate: true, onUpdate: true },
|
|
],
|
|
indexes: ["CREATE INDEX idx_attachments_page ON attachments (page, created)"],
|
|
}),
|
|
);
|
|
},
|
|
(app) => {
|
|
try {
|
|
app.delete(app.findCollectionByNameOrId("attachments"));
|
|
} catch (_) {}
|
|
},
|
|
);
|