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:
@@ -3,11 +3,12 @@ import { promisify } from 'util';
|
||||
import { existsSync } from 'fs';
|
||||
import { mkdir, unlink, rename } from 'fs/promises';
|
||||
import { join } from 'path';
|
||||
import { DATA_DIR } from './data-dir.js';
|
||||
import type { AudioMode, AudioAnalysis } from '$lib/types.js';
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
|
||||
const TMP_DIR = join(process.env.DATA_DIR ?? '/tmp/.whisper-pwa', 'audio');
|
||||
const TMP_DIR = join(DATA_DIR, 'audio');
|
||||
|
||||
export async function ensureTmpDir() {
|
||||
if (!existsSync(TMP_DIR)) await mkdir(TMP_DIR, { recursive: true });
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { join } from 'path';
|
||||
|
||||
/**
|
||||
* Single source of truth for the app's persistent data directory.
|
||||
* Uses db.ts's pre-existing $HOME-based default (the one already backed by
|
||||
* a real persistent volume in prod) so uploads, audio prep, remux temp files,
|
||||
* and job rows all resolve under the same path when DATA_DIR env var is unset.
|
||||
*
|
||||
* All modules that need a data directory root import this constant instead of
|
||||
* defining their own inline default.
|
||||
*/
|
||||
export const DATA_DIR = process.env.DATA_DIR ?? join(process.env.HOME ?? '/tmp', '.whisper-pwa');
|
||||
@@ -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'));
|
||||
|
||||
@@ -4,9 +4,9 @@ import { existsSync } from 'fs';
|
||||
import { mkdir, writeFile } from 'fs/promises';
|
||||
import { join } from 'path';
|
||||
import { fetchTranscript, type TranscriptResponse } from 'youtube-transcript';
|
||||
import { DATA_DIR } from './data-dir.js';
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
const DATA_DIR = process.env.DATA_DIR ?? '/tmp/.whisper-pwa';
|
||||
const TMP_DIR = join(DATA_DIR, 'downloads');
|
||||
const UPLOADS_DIR = join(DATA_DIR, 'uploads');
|
||||
|
||||
|
||||
@@ -2,8 +2,9 @@ import { execFile } from 'child_process';
|
||||
import { unlink, rename, mkdir } from 'fs/promises';
|
||||
import { join, extname } from 'path';
|
||||
import { existsSync } from 'fs';
|
||||
import { DATA_DIR } from './data-dir.js';
|
||||
|
||||
const REMUX_DIR = join(process.env.DATA_DIR ?? '/tmp/.whisper-pwa', 'remux');
|
||||
const REMUX_DIR = join(DATA_DIR, 'remux');
|
||||
|
||||
async function ensureTmpDir() {
|
||||
if (!existsSync(REMUX_DIR)) await mkdir(REMUX_DIR, { recursive: true });
|
||||
|
||||
Reference in New Issue
Block a user