diff --git a/src/server/routes/api/v0/fileApiRoutes.ts b/src/server/routes/api/v0/fileApiRoutes.ts index e3f1ccb..9b59fff 100644 --- a/src/server/routes/api/v0/fileApiRoutes.ts +++ b/src/server/routes/api/v0/fileApiRoutes.ts @@ -14,17 +14,7 @@ export let fileApiRoutes = new Hono<{ } }>() -fileApiRoutes.use("*", getAccount) // :warning: /list somehow crashes Hono with an internal error! -/* - -/home/jack/Code/Web/monofile/node_modules/.pnpm/@hono+node-server@1.2.0/node_modules/@hono/node-server/dist/listener.js:55 - const contentType = res.headers.get("content-type") || ""; - ^ - -TypeError: Cannot read properties of undefined (reading 'get') - at Server. (/home/jack/Code/Web/monofile/node_modules/.pnpm/@hono+node-server@1.2.0/node_modules/@hono/node-server/dist/listener.js:55:37) - at process.processTicksAndRejections (node:internal/process/task_queues:95:5) -*/ +fileApiRoutes.use("*", getAccount) export default function (files: Files) { fileApiRoutes.get( @@ -37,7 +27,7 @@ export default function (files: Files) { if (!acc) return let accId = acc.id - ctx.json( + return ctx.json( acc.files .map((e) => { let fp = files.files[e] diff --git a/src/server/routes/api/v0/primaryApi.ts b/src/server/routes/api/v0/primaryApi.ts index d9b7b61..183e30c 100644 --- a/src/server/routes/api/v0/primaryApi.ts +++ b/src/server/routes/api/v0/primaryApi.ts @@ -32,7 +32,7 @@ export default function (files: Files) { let file = files.files[fileId] ctx.header("Access-Control-Allow-Origin", "*") ctx.header("Content-Security-Policy", "sandbox allow-scripts") - ctx.header("Content-Disposition", `${ctx.req.query("attachment") == "1" ? "attachment" : "inline"}; filename="${file.filename.replaceAll("\n","\\n")}"`) + ctx.header("Content-Disposition", `${ctx.req.query("attachment") == "1" ? "attachment" : "inline"}; filename="${encodeURI(file.filename.replaceAll("\n","\\n"))}"`) if (file) { if (file.visibility == "private") { @@ -68,6 +68,8 @@ export default function (files: Files) { } } + console.log(range) + return files .readFileStream(fileId, range) .then(async (stream) => { @@ -84,7 +86,7 @@ export default function (files: Files) { } return ctx.req.method == "HEAD" ? ctx.body(null) : ctx.stream(async (webStream) => { - webStream.pipe(Readable.toWeb(stream) as ReadableStream).catch(e => {}) // emits an AbortError for some reason so this catches that + webStream.pipe(Readable.toWeb(stream.on("error", e => {})) as ReadableStream).catch(e => {}) }) }) .catch((err) => {