Adds an option in SETTINGS to change the maximum size of file you can upload to your space. (#832)
parent
331d526f52
commit
e280dfee4a
|
@ -32,6 +32,7 @@ export function parseYamlSettings(settingsMarkdown: string): {
|
||||||
export const defaultSettings: BuiltinSettings = {
|
export const defaultSettings: BuiltinSettings = {
|
||||||
indexPage: "index",
|
indexPage: "index",
|
||||||
hideSyncButton: false,
|
hideSyncButton: false,
|
||||||
|
maximumAttachmentSize: 10, // MiB
|
||||||
actionButtons: [
|
actionButtons: [
|
||||||
{
|
{
|
||||||
icon: "Home",
|
icon: "Home",
|
||||||
|
|
|
@ -1,18 +1,22 @@
|
||||||
|
import { readSetting } from "$sb/lib/settings_page.ts";
|
||||||
import { editor, space } from "$sb/syscalls.ts";
|
import { editor, space } from "$sb/syscalls.ts";
|
||||||
import { UploadFile } from "../../plug-api/types.ts";
|
import { UploadFile } from "../../plug-api/types.ts";
|
||||||
|
|
||||||
const maximumAttachmentSize = 1024 * 1024 * 10; // 10MB
|
const maximumAttachmentSize = 10; // MiB
|
||||||
|
|
||||||
function folderName(path: string) {
|
function folderName(path: string) {
|
||||||
return path.split("/").slice(0, -1).join("/");
|
return path.split("/").slice(0, -1).join("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveFile(file: UploadFile) {
|
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(
|
editor.flashNotification(
|
||||||
`Attachment is too large, maximum is ${
|
`Attachment is too large, maximum is ${maxSize}MiB`,
|
||||||
maximumAttachmentSize / 1024 / 1024
|
|
||||||
}MB`,
|
|
||||||
"error",
|
"error",
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -17,6 +17,7 @@ export type BuiltinSettings = {
|
||||||
plugOverrides?: Record<string, Partial<Manifest>>;
|
plugOverrides?: Record<string, Partial<Manifest>>;
|
||||||
shortcuts?: Shortcut[];
|
shortcuts?: Shortcut[];
|
||||||
hideSyncButton?: boolean;
|
hideSyncButton?: boolean;
|
||||||
|
maximumAttachmentSize?: number;
|
||||||
actionButtons: ActionButton[];
|
actionButtons: ActionButton[];
|
||||||
// Format: compatible with docker ignore
|
// Format: compatible with docker ignore
|
||||||
spaceIgnore?: string;
|
spaceIgnore?: string;
|
||||||
|
|
|
@ -42,6 +42,9 @@ spaceIgnore: |
|
||||||
largefolder
|
largefolder
|
||||||
*.mp4
|
*.mp4
|
||||||
|
|
||||||
|
# Defines the maximum size of a file you can upload to the space (in MiB)
|
||||||
|
maximumAttachmentSize: 10
|
||||||
|
|
||||||
# Add alternative names to emoji picker
|
# Add alternative names to emoji picker
|
||||||
emoji:
|
emoji:
|
||||||
aliases:
|
aliases:
|
||||||
|
|
Loading…
Reference in New Issue