diff --git a/common/settings.ts b/common/settings.ts index f554cb2c..4dda254e 100644 --- a/common/settings.ts +++ b/common/settings.ts @@ -32,6 +32,7 @@ export function parseYamlSettings(settingsMarkdown: string): { export const defaultSettings: BuiltinSettings = { indexPage: "index", hideSyncButton: false, + maximumAttachmentSize: 10, // MiB actionButtons: [ { icon: "Home", diff --git a/plugs/editor/upload.ts b/plugs/editor/upload.ts index e5e20a3f..f373f0e1 100644 --- a/plugs/editor/upload.ts +++ b/plugs/editor/upload.ts @@ -1,18 +1,22 @@ +import { readSetting } from "$sb/lib/settings_page.ts"; import { editor, space } from "$sb/syscalls.ts"; import { UploadFile } from "../../plug-api/types.ts"; -const maximumAttachmentSize = 1024 * 1024 * 10; // 10MB +const maximumAttachmentSize = 10; // MiB function folderName(path: string) { return path.split("/").slice(0, -1).join("/"); } async function saveFile(file: UploadFile) { - if (file.content.length > maximumAttachmentSize) { + const maxSize = await readSetting("maximumAttachmentSize", maximumAttachmentSize); + if (typeof maxSize !== "number") { + await editor.flashNotification( + "The setting 'maximumAttachmentSize' must be a number", "error"); + } + if (file.content.length > maxSize * 1024 * 1024) { editor.flashNotification( - `Attachment is too large, maximum is ${ - maximumAttachmentSize / 1024 / 1024 - }MB`, + `Attachment is too large, maximum is ${maxSize}MiB`, "error", ); return; diff --git a/type/web.ts b/type/web.ts index df4de583..e9c23ff5 100644 --- a/type/web.ts +++ b/type/web.ts @@ -17,6 +17,7 @@ export type BuiltinSettings = { plugOverrides?: Record>; shortcuts?: Shortcut[]; hideSyncButton?: boolean; + maximumAttachmentSize?: number; actionButtons: ActionButton[]; // Format: compatible with docker ignore spaceIgnore?: string; diff --git a/website/SETTINGS.md b/website/SETTINGS.md index be51e12c..53e75f60 100644 --- a/website/SETTINGS.md +++ b/website/SETTINGS.md @@ -42,6 +42,9 @@ spaceIgnore: | largefolder *.mp4 +# Defines the maximum size of a file you can upload to the space (in MiB) +maximumAttachmentSize: 10 + # Add alternative names to emoji picker emoji: aliases: