From d8d876e9b88ceb2096c9e445527e26ca48aabca2 Mon Sep 17 00:00:00 2001 From: jlightner Date: Sat, 4 Apr 2026 10:00:19 +0000 Subject: [PATCH] =?UTF-8?q?chore:=20Download=20pipeline=20now=20reads=20nf?= =?UTF-8?q?oEnabled=20from=20platform=5Fsettings=20pe=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - "src/services/download.ts" - "src/__tests__/download.test.ts" GSD-Task: S04/T02 --- src/__tests__/download.test.ts | 24 ++++++++++++------------ src/services/download.ts | 11 ++++++----- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/__tests__/download.test.ts b/src/__tests__/download.test.ts index 3a22e2f..9a4d9dc 100644 --- a/src/__tests__/download.test.ts +++ b/src/__tests__/download.test.ts @@ -39,13 +39,13 @@ vi.mock('node:fs/promises', async (importOriginal) => { }; }); -// Mock getAppSetting for NFO feature flag -const getAppSettingMock = vi.fn(); -vi.mock('../db/repositories/system-config-repository', async (importOriginal) => { +// Mock getPlatformSettings for per-platform NFO feature flag +const getPlatformSettingsMock = vi.fn(); +vi.mock('../db/repositories/platform-settings-repository', async (importOriginal) => { const actual = await importOriginal() as Record; return { ...actual, - getAppSetting: (...args: unknown[]) => getAppSettingMock(...args), + getPlatformSettings: (...args: unknown[]) => getPlatformSettingsMock(...args), }; }); @@ -788,7 +788,7 @@ describe('DownloadService', () => { return outputPath; } - it('writes .nfo sidecar when app.nfo_enabled is "true"', async () => { + it('writes .nfo sidecar when platform nfoEnabled is true', async () => { const deps = createMockDeps(); const service = new DownloadService( db, deps.rateLimiter, deps.fileOrganizer, @@ -796,7 +796,7 @@ describe('DownloadService', () => { ); const outputPath = setupSuccessfulDownload(deps); - getAppSettingMock.mockResolvedValueOnce('true'); + getPlatformSettingsMock.mockResolvedValueOnce({ nfoEnabled: true }); await service.downloadItem(testContentItem, testChannel); @@ -812,7 +812,7 @@ describe('DownloadService', () => { expect(nfoContent).toContain('Test Channel'); }); - it('does not write .nfo when app.nfo_enabled is not "true"', async () => { + it('does not write .nfo when platform nfoEnabled is false', async () => { const deps = createMockDeps(); const service = new DownloadService( db, deps.rateLimiter, deps.fileOrganizer, @@ -820,7 +820,7 @@ describe('DownloadService', () => { ); const outputPath = setupSuccessfulDownload(deps); - getAppSettingMock.mockResolvedValueOnce(null); // Not set + getPlatformSettingsMock.mockResolvedValueOnce({ nfoEnabled: false }); await service.downloadItem(testContentItem, testChannel); @@ -828,7 +828,7 @@ describe('DownloadService', () => { expect(existsSync(nfoPath)).toBe(false); }); - it('does not write .nfo when app.nfo_enabled is "false"', async () => { + it('does not write .nfo when no platform settings exist', async () => { const deps = createMockDeps(); const service = new DownloadService( db, deps.rateLimiter, deps.fileOrganizer, @@ -836,7 +836,7 @@ describe('DownloadService', () => { ); const outputPath = setupSuccessfulDownload(deps); - getAppSettingMock.mockResolvedValueOnce('false'); + getPlatformSettingsMock.mockResolvedValueOnce(null); // No settings for platform await service.downloadItem(testContentItem, testChannel); @@ -852,7 +852,7 @@ describe('DownloadService', () => { ); setupSuccessfulDownload(deps); - getAppSettingMock.mockRejectedValueOnce(new Error('DB read failed')); + getPlatformSettingsMock.mockRejectedValueOnce(new Error('DB read failed')); // Download should still succeed const result = await service.downloadItem(testContentItem, testChannel); @@ -867,7 +867,7 @@ describe('DownloadService', () => { ); setupSuccessfulDownload(deps); - getAppSettingMock.mockResolvedValueOnce('true'); + getPlatformSettingsMock.mockResolvedValueOnce({ nfoEnabled: true }); const result = await service.downloadItem(testContentItem, testChannel); expect(result.status).toBe('downloaded'); diff --git a/src/services/download.ts b/src/services/download.ts index ebfd34a..718ab41 100644 --- a/src/services/download.ts +++ b/src/services/download.ts @@ -5,7 +5,7 @@ import type { LibSQLDatabase } from 'drizzle-orm/libsql'; import type * as schema from '../db/schema/index'; import { execYtDlp, spawnYtDlp, YtDlpError, classifyYtDlpError } from '../sources/yt-dlp'; import { updateContentItem } from '../db/repositories/content-repository'; -import { getAppSetting, APP_NFO_ENABLED } from '../db/repositories/system-config-repository'; +import { getPlatformSettings } from '../db/repositories/platform-settings-repository'; import { generateNfo, writeNfoFile } from './nfo-generator'; import { parseProgressLine } from './progress-parser'; import type { DownloadEventBus } from './event-bus'; @@ -140,7 +140,7 @@ export class DownloadService { this.rateLimiter.reportSuccess(platform as Platform); // Generate NFO sidecar if enabled - await this.maybeWriteNfo(contentItem, channel, finalPath, logPrefix); + await this.maybeWriteNfo(contentItem, channel, finalPath, logPrefix, platform); // Emit download:complete event this.eventBus?.emitDownload('download:complete', { contentItemId: contentItem.id }); @@ -471,11 +471,12 @@ export class DownloadService { contentItem: ContentItem, channel: Channel | null, mediaFilePath: string, - logPrefix: string + logPrefix: string, + platform: string ): Promise { try { - const nfoEnabled = await getAppSetting(this.db, APP_NFO_ENABLED); - if (nfoEnabled !== 'true') return; + const settings = await getPlatformSettings(this.db, platform); + if (!settings?.nfoEnabled) return; const nfoXml = generateNfo(contentItem, channel); const nfoPath = await writeNfoFile(nfoXml, mediaFilePath);