From 7b859e73580f6e7e7eb9f65e0185f438d83d057d Mon Sep 17 00:00:00 2001 From: SukkaW Date: Sat, 11 Jan 2025 12:37:42 +0800 Subject: [PATCH] Fix(#52): DB parent path not found --- Build/constants/dir.ts | 2 ++ Build/lib/cache-filesystem.ts | 4 ++-- Build/lib/fetch-retry.ts | 9 +++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Build/constants/dir.ts b/Build/constants/dir.ts index 8ca55486..335bb5cd 100644 --- a/Build/constants/dir.ts +++ b/Build/constants/dir.ts @@ -2,6 +2,8 @@ import path from 'node:path'; export const ROOT_DIR = path.resolve(__dirname, '../..'); +export const CACHE_DIR = path.resolve(ROOT_DIR, '.cache'); + export const SOURCE_DIR = path.join(ROOT_DIR, 'Source'); export const PUBLIC_DIR = path.resolve(ROOT_DIR, 'public'); diff --git a/Build/lib/cache-filesystem.ts b/Build/lib/cache-filesystem.ts index 0e89e4cd..87e2d457 100644 --- a/Build/lib/cache-filesystem.ts +++ b/Build/lib/cache-filesystem.ts @@ -18,7 +18,7 @@ import { Custom304NotModifiedError, CustomAbortError, CustomNoETagFallbackError, import type { IncomingHttpHeaders } from 'undici/types/header'; import { Headers } from 'undici'; -import { ROOT_DIR } from '../constants/dir'; +import { CACHE_DIR } from '../constants/dir'; export interface CacheOptions { /** Path to sqlite file dir */ @@ -430,7 +430,7 @@ export class Cache { } } -export const fsFetchCache = new Cache({ cachePath: path.resolve(ROOT_DIR, '.cache') }); +export const fsFetchCache = new Cache({ cachePath: CACHE_DIR }); // process.on('exit', () => { // fsFetchCache.destroy(); // }); diff --git a/Build/lib/fetch-retry.ts b/Build/lib/fetch-retry.ts index 821554e7..3ac951e7 100644 --- a/Build/lib/fetch-retry.ts +++ b/Build/lib/fetch-retry.ts @@ -16,7 +16,12 @@ export type UndiciResponseData = Dispatcher.ResponseData; import { inspect } from 'node:util'; import path from 'node:path'; -import { ROOT_DIR } from '../constants/dir'; +import fs from 'node:fs'; +import { CACHE_DIR } from '../constants/dir'; + +if (!fs.existsSync(CACHE_DIR)) { + fs.mkdirSync(CACHE_DIR, { recursive: true }); +} const agent = new Agent({}); @@ -106,7 +111,7 @@ setGlobalDispatcher(agent.compose( }), interceptors.cache({ store: new BetterSqlite3CacheStore({ - location: path.join(ROOT_DIR, '.cache/undici-better-sqlite3-cache-store.db'), + location: path.join(CACHE_DIR, 'undici-better-sqlite3-cache-store.db'), maxEntrySize: 1024 * 1024 * 50 // 50 MiB }) })