From 7561f2a8c3a92c412f0d38b9f1323aa8bcfcf4a4 Mon Sep 17 00:00:00 2001 From: SnapOtter Date: Sun, 21 Jun 2026 01:34:58 +0800 Subject: [PATCH] fix(lint): make husky hook executable; rename backend useS3 to isS3Enabled (clears 17 false-positive useHookAtTopLevel) --- .husky/pre-commit | 0 apps/api/src/lib/file-storage.ts | 20 ++++++++++---------- apps/api/src/lib/object-storage.ts | 18 +++++++++--------- 3 files changed, 19 insertions(+), 19 deletions(-) mode change 100644 => 100755 .husky/pre-commit diff --git a/.husky/pre-commit b/.husky/pre-commit old mode 100644 new mode 100755 diff --git a/apps/api/src/lib/file-storage.ts b/apps/api/src/lib/file-storage.ts index dd96df81..313deb3b 100644 --- a/apps/api/src/lib/file-storage.ts +++ b/apps/api/src/lib/file-storage.ts @@ -74,7 +74,7 @@ async function getS3(): Promise { return s3Mod; } -function useS3(): boolean { +function isS3Enabled(): boolean { return env.STORAGE_MODE === "s3"; } @@ -92,7 +92,7 @@ let storageReady = false; export async function ensureStorageDir(): Promise { if (storageReady) return; - if (useS3()) { + if (isS3Enabled()) { const s3 = await getS3(); await s3.checkConnection(); storageReady = true; @@ -115,7 +115,7 @@ export async function ensureStorageDir(): Promise { export async function saveFile(buffer: Buffer, originalName: string): Promise { const storedName = generateStoredName(originalName); - if (useS3()) { + if (isS3Enabled()) { const s3 = await getS3(); await s3.putObject(storedName, buffer); return storedName; @@ -138,7 +138,7 @@ export async function saveFile(buffer: Buffer, originalName: string): Promise { - if (useS3()) { + if (isS3Enabled()) { const s3 = await getS3(); return s3.getObject(storedName); } @@ -146,7 +146,7 @@ export async function readStoredFile(storedName: string): Promise { } export async function streamStoredFile(storedName: string): Promise { - if (useS3()) { + if (isS3Enabled()) { const s3 = await getS3(); return s3.getObjectStream(storedName); } @@ -154,7 +154,7 @@ export async function streamStoredFile(storedName: string): Promise { } export async function deleteStoredFile(storedName: string): Promise { - if (useS3()) { + if (isS3Enabled()) { const s3 = await getS3(); await s3.deleteObject(storedName); return; @@ -177,7 +177,7 @@ let thumbDirReady = false; async function ensureThumbDir(): Promise { if (thumbDirReady) return; - if (useS3()) { + if (isS3Enabled()) { thumbDirReady = true; return; } @@ -197,7 +197,7 @@ function thumbPath(storedName: string): string { } export async function getCachedThumbnail(storedName: string): Promise { - if (useS3()) { + if (isS3Enabled()) { const s3 = await getS3(); return s3.getThumbnail(storedName); } @@ -209,7 +209,7 @@ export async function getCachedThumbnail(storedName: string): Promise { - if (useS3()) { + if (isS3Enabled()) { const s3 = await getS3(); await s3.putThumbnail(storedName, buffer); return; @@ -219,7 +219,7 @@ export async function saveThumbnail(storedName: string, buffer: Buffer): Promise } export async function deleteThumbnail(storedName: string): Promise { - if (useS3()) { + if (isS3Enabled()) { const s3 = await getS3(); await s3.deleteThumbnail(storedName); return; diff --git a/apps/api/src/lib/object-storage.ts b/apps/api/src/lib/object-storage.ts index 0e1f5064..768d3f4e 100644 --- a/apps/api/src/lib/object-storage.ts +++ b/apps/api/src/lib/object-storage.ts @@ -37,7 +37,7 @@ function localPath(key: string): string { return p; } -function useS3(): boolean { +function isS3Enabled(): boolean { return env.STORAGE_MODE === "s3"; } @@ -102,7 +102,7 @@ export async function assertLocalCapacity(): Promise { export async function putObject(key: string, data: Buffer): Promise { assertValidKey(key); - if (useS3()) { + if (isS3Enabled()) { const s3 = await getS3(); await s3.putGenericObject(key, data); return; @@ -129,7 +129,7 @@ export async function putObjectStream( yield chunk; } }; - if (useS3()) { + if (isS3Enabled()) { const s3 = await getS3(); await s3.putGenericObjectStream(key, counter(source)); return written; @@ -151,7 +151,7 @@ export async function getObjectStream( range?: { start: number; end?: number }, ): Promise { assertValidKey(key); - if (useS3()) { + if (isS3Enabled()) { const s3 = await getS3(); return s3.getGenericObjectStream(key, range); } @@ -166,7 +166,7 @@ export async function getObjectBuffer(key: string): Promise { export async function getObjectSize(key: string): Promise { assertValidKey(key); - if (useS3()) { + if (isS3Enabled()) { const s3 = await getS3(); return s3.getGenericObjectSize(key); } @@ -184,7 +184,7 @@ export async function objectExists(key: string): Promise { export async function deleteObject(key: string): Promise { assertValidKey(key); - if (useS3()) { + if (isS3Enabled()) { const s3 = await getS3(); await s3.deleteGenericObject(key); return; @@ -196,7 +196,7 @@ export async function deletePrefix(prefix: string): Promise { if (!/^(uploads|outputs)\/[A-Za-z0-9][A-Za-z0-9._-]*\/?$/.test(prefix)) { throw new Error(`Invalid prefix: ${prefix}`); } - if (useS3()) { + if (isS3Enabled()) { const s3 = await getS3(); await s3.deleteGenericPrefix(prefix); return; @@ -208,7 +208,7 @@ export async function listObjects(prefix: string): Promise { if (!/^(uploads|outputs)\/[A-Za-z0-9][A-Za-z0-9._-]*\/?$/.test(prefix) || prefix.includes("..")) { throw new Error(`Invalid prefix: ${prefix}`); } - if (useS3()) { + if (isS3Enabled()) { const s3 = await getS3(); return s3.listGenericObjects(prefix); } @@ -233,7 +233,7 @@ export async function listObjects(prefix: string): Promise { // Lists the top-level job directories under a prefix with their mtime so the // TTL sweeper can expire whole jobs. S3 derives them from key listings. export async function listJobDirs(prefix: "uploads" | "outputs"): Promise { - if (useS3()) { + if (isS3Enabled()) { const s3 = await getS3(); return s3.listGenericJobDirs(prefix); }