diff --git a/bun.lockb b/bun.lockb index 0424b96..d944849 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 2b512e5..fb47e8b 100644 --- a/package.json +++ b/package.json @@ -31,13 +31,13 @@ "start:server": "bun run ./dist/server.js" }, "dependencies": { - "@hono/zod-openapi": "~0.18.0", + "@hono/zod-openapi": "~0.18.2", "env-var": "~7.5.0", "hono": "~4.6.12" }, "devDependencies": { "@biomejs/biome": "~1.9.4", - "@types/bun": "^1.1.13", + "@types/bun": "^1.1.14", "lefthook": "~1.8.4", "sort-package-json": "~2.12.0" }, diff --git a/src/document/storage.ts b/src/document/storage.ts index a5a2007..c64c8d9 100644 --- a/src/document/storage.ts +++ b/src/document/storage.ts @@ -1,4 +1,5 @@ import { deserialize, serialize } from 'bun:jsc'; +import { logger } from '@x-util/logger.ts'; import { config } from '../config.ts'; import { errorHandler } from '../server/errorHandler.ts'; import type { Document } from '../types/Document.ts'; @@ -6,10 +7,18 @@ import { ErrorCode } from '../types/ErrorHandler.ts'; export const storage = { read: async (name: string): Promise => { + const document = await Bun.file(config.storagePath + name) + .arrayBuffer() + .catch(() => errorHandler.send(ErrorCode.documentNotFound)); + try { - return deserialize(await Bun.file(config.storagePath + name).arrayBuffer()); + if (document.byteLength <= 0) throw null; + + return deserialize(document); } catch { - return errorHandler.send(ErrorCode.documentNotFound); + logger.error(`Document "${name}" is corrupted! Aborting...`); + + return errorHandler.send(ErrorCode.documentCorrupted); } },