Adds an option in SETTINGS to change the maximum size of file you can upload to your space. (#832)

pull/834/head
Thomas Michelat 2024-03-27 21:21:12 +01:00 committed by GitHub
parent 331d526f52
commit e280dfee4a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 5 deletions

View File

@ -32,6 +32,7 @@ export function parseYamlSettings(settingsMarkdown: string): {
export const defaultSettings: BuiltinSettings = {
indexPage: "index",
hideSyncButton: false,
maximumAttachmentSize: 10, // MiB
actionButtons: [
{
icon: "Home",

View File

@ -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;

View File

@ -17,6 +17,7 @@ export type BuiltinSettings = {
plugOverrides?: Record<string, Partial<Manifest>>;
shortcuts?: Shortcut[];
hideSyncButton?: boolean;
maximumAttachmentSize?: number;
actionButtons: ActionButton[];
// Format: compatible with docker ignore
spaceIgnore?: string;

View File

@ -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: