Skip to content

Commit acfc04d

Browse files
author
hjy
committed
后端fix
1 parent 95056f3 commit acfc04d

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

backendnode/src/logger.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ function ts(): string {
1212
}
1313

1414
export const logger = {
15+
/** 启动相关 */
16+
startup: (msg: string) => console.log(`${ts()} [STARTUP] ${msg}`),
1517
/** DB 初始化相关 */
1618
db: (msg: string) => console.log(`${ts()} [DB] ${msg}`),
1719
/** 扫描进度 */
@@ -20,4 +22,6 @@ export const logger = {
2022
fs: (msg: string) => console.log(`${ts()} [FS] ${msg}`),
2123
/** 压缩任务 */
2224
compress: (msg: string) => console.log(`${ts()} [COMPRESS] ${msg}`),
25+
/** 解压缓存 */
26+
extract: (msg: string) => console.log(`${ts()} [EXTRACT] ${msg}`),
2327
};

backendnode/src/server.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { buildApp } from "./app.js";
22
import { initDb, getDb } from "./db/client.js";
33
import { IndexRepository } from "./db/repository.js";
44
import { config } from "./config.js";
5+
import { logger } from "./logger.js";
6+
import { clearExtractCache } from "./services/archiveService.js";
57
import path from "node:path";
68
import { fileURLToPath } from "node:url";
79

@@ -18,10 +20,20 @@ async function main() {
1820
repo.logActivity("startup", "Server started", "started", "startup");
1921
} catch { /* ignore */ }
2022

23+
// 启动时清除解压缓存
24+
try {
25+
logger.startup("Clearing extract cache...");
26+
const cacheResult = clearExtractCache();
27+
logger.startup(`Extract cache cleared: ${cacheResult.deleted_files} files, ${cacheResult.freed_size_readable} freed`);
28+
} catch (e) {
29+
logger.startup(`Failed to clear extract cache: ${e}`);
30+
}
31+
2132
const app = buildApp();
2233

2334
try {
2435
await app.listen({ port: config.PORT, host: config.HOST });
36+
logger.startup(`ShiguReader backend running at http://${config.HOST === "0.0.0.0" ? "localhost" : config.HOST}:${config.PORT}`);
2537
console.log(`ShiguReader backend running at http://${config.HOST === "0.0.0.0" ? "localhost" : config.HOST}:${config.PORT}`);
2638
} catch (err) {
2739
app.log.error(err);

backendnode/src/services/archiveService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function getEntryType(entryPath: string): EntryType {
6767
// ── cache dir ────────────────────────────────────────────────────────────────
6868

6969
export function getExtractCacheDir(archivePath: string): string {
70-
const hash = crypto.createHash("sha256").update(archivePath).digest("hex");
70+
const hash = crypto.createHash("sha256").update(archivePath).digest("hex").slice(0, 10);
7171
const base = path.resolve(config.EXTRACT_CACHE_DIR);
7272
return path.join(base, hash.slice(0, 2), hash.slice(2));
7373
}

0 commit comments

Comments
 (0)