diff --git a/src/server/index.ts b/src/server/index.ts index 3b2c5ed..3d32eaa 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -85,6 +85,23 @@ const apiRouter = new APIRouter(files) apiRouter.loadAPIMethods().then(() => { app.route("/", apiRouter.root) console.log("API OK!") + + // listen on 3000 or MONOFILE_PORT + // moved here to prevent a crash if someone manages to access monofile before api routes are mounted + + serve( + { + fetch: app.fetch, + port: Number(process.env.MONOFILE_PORT || 3000), + serverOptions: { + //@ts-ignore + requestTimeout: config.requestTimeout + } + }, + (info) => { + console.log("Web OK!", info.port, info.address) + } + ) }) // index, clone @@ -104,20 +121,4 @@ app.get("/", async (ctx) => file serving */ -// listen on 3000 or MONOFILE_PORT - -serve( - { - fetch: app.fetch, - port: Number(process.env.MONOFILE_PORT || 3000), - serverOptions: { - //@ts-ignore - requestTimeout: config.requestTimeout - } - }, - (info) => { - console.log("Web OK!", info.port, info.address) - } -) - export default app \ No newline at end of file diff --git a/src/server/routes/api/web/preview.ts b/src/server/routes/api/web/preview.ts index 8370697..052a2cc 100644 --- a/src/server/routes/api/web/preview.ts +++ b/src/server/routes/api/web/preview.ts @@ -107,9 +107,7 @@ export default function (files: Files) { : `@${fileOwner?.username || "Deleted User"}` ) ) - } else { - ServeError(ctx, 404, "file not found") - } + } else return ServeError(ctx, 404, "file not found") }) return router diff --git a/src/svelte/elem/UploadWindow.svelte b/src/svelte/elem/UploadWindow.svelte index 28d3c32..8e5c332 100644 --- a/src/svelte/elem/UploadWindow.svelte +++ b/src/svelte/elem/UploadWindow.svelte @@ -4,6 +4,7 @@ import { fade } from "svelte/transition" import { circIn, circOut } from "svelte/easing" import { serverStats, refresh_stats, account } from "./stores.mjs" + import bytes from "bytes" import AttachmentZone from "./uploader/AttachmentZone.svelte" @@ -213,9 +214,7 @@ {upload[1].name} {upload[1].type}{@html upload[1].type == "upload" - ? ` (${Math.round( - upload[1].file.size / 1048576 - )}MiB)` + ? ` (${bytes(upload[1].file.size)})` : ""} @@ -372,11 +371,12 @@ >{$serverStats.files || "•••"} files — Maximum filesize is - {(($serverStats.maxDiscordFileSize || 0) * - ($serverStats.maxDiscordFiles || 0)) / - 1048576 || "•••"}MiB + + { + $serverStats.maxDiscordFiles + ? bytes($serverStats.maxDiscordFileSize * $serverStats.maxDiscordFiles) + : "•••" + }