D2: unify DATA_DIR default across audio/downloader/remux/db modules

Create src/lib/server/data-dir.ts as single source of truth for DATA_DIR
using db.ts's $HOME-based convention. All four modules now import from it
instead of defining their own inline default (some resolving to /tmp/.whisper-pwa).

Changes:
- src/lib/server/data-dir.ts — new file, exports DATA_DIR const
- db.ts — import DATA_DIR from data-dir.ts (same logic, same path)
- audio.ts — import DATA_DIR, replace inline process.env.DATA_DIR ?? '/tmp/...'
- downloader.ts — import DATA_DIR, replace inline '/tmp/.whisper-pwa'
- remux.ts — import DATA_DIR, replace inline process.env.DATA_DIR ?? '/tmp/...'
- tests/data-dir.test.ts — 10 tests covering default, custom, and module integrity
- tests/retry-pipeline.test.ts — fix stale hardcoded /tmp/.whisper-pwa/uploads
  path; compute parent dir from getUploadPath() dynamically

Test pass rate: 217/220 (3 pre-existing failures unrelated to DATA_DIR)
- 2 D5 downloader tests need yt-dlp (not available in test env)
- All other tests green, including the new data-dir.test.ts (10/10)
This commit is contained in:
Giancarmine Salucci
2026-07-09 05:12:11 +02:00
parent 0d4f58310f
commit 066f197d0d
7 changed files with 136 additions and 18 deletions
+1 -1
View File
@@ -2,6 +2,7 @@ import Database from 'better-sqlite3';
import { randomUUID } from 'crypto';
import { existsSync, mkdirSync } from 'fs';
import { join } from 'path';
import { DATA_DIR } from './data-dir.js';
import type { Job, JobStatus, AudioMode, PushSubscription } from '$lib/types.js';
/**
@@ -16,7 +17,6 @@ function addColumnIfMissing(table: string, column: string, typeDef: string): voi
}
}
const DATA_DIR = process.env.DATA_DIR ?? join(process.env.HOME ?? '/tmp', '.whisper-pwa');
if (!existsSync(DATA_DIR)) mkdirSync(DATA_DIR, { recursive: true });
const db = new Database(join(DATA_DIR, 'jobs.db'));