chore: Download pipeline now reads nfoEnabled from platform_settings pe…
- "src/services/download.ts" - "src/__tests__/download.test.ts" GSD-Task: S04/T02
This commit is contained in:
parent
0f42a4b269
commit
d8d876e9b8
2 changed files with 18 additions and 17 deletions
|
|
@ -39,13 +39,13 @@ vi.mock('node:fs/promises', async (importOriginal) => {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// Mock getAppSetting for NFO feature flag
|
// Mock getPlatformSettings for per-platform NFO feature flag
|
||||||
const getAppSettingMock = vi.fn();
|
const getPlatformSettingsMock = vi.fn();
|
||||||
vi.mock('../db/repositories/system-config-repository', async (importOriginal) => {
|
vi.mock('../db/repositories/platform-settings-repository', async (importOriginal) => {
|
||||||
const actual = await importOriginal() as Record<string, unknown>;
|
const actual = await importOriginal() as Record<string, unknown>;
|
||||||
return {
|
return {
|
||||||
...actual,
|
...actual,
|
||||||
getAppSetting: (...args: unknown[]) => getAppSettingMock(...args),
|
getPlatformSettings: (...args: unknown[]) => getPlatformSettingsMock(...args),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -788,7 +788,7 @@ describe('DownloadService', () => {
|
||||||
return outputPath;
|
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 deps = createMockDeps();
|
||||||
const service = new DownloadService(
|
const service = new DownloadService(
|
||||||
db, deps.rateLimiter, deps.fileOrganizer,
|
db, deps.rateLimiter, deps.fileOrganizer,
|
||||||
|
|
@ -796,7 +796,7 @@ describe('DownloadService', () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
const outputPath = setupSuccessfulDownload(deps);
|
const outputPath = setupSuccessfulDownload(deps);
|
||||||
getAppSettingMock.mockResolvedValueOnce('true');
|
getPlatformSettingsMock.mockResolvedValueOnce({ nfoEnabled: true });
|
||||||
|
|
||||||
await service.downloadItem(testContentItem, testChannel);
|
await service.downloadItem(testContentItem, testChannel);
|
||||||
|
|
||||||
|
|
@ -812,7 +812,7 @@ describe('DownloadService', () => {
|
||||||
expect(nfoContent).toContain('<studio>Test Channel</studio>');
|
expect(nfoContent).toContain('<studio>Test Channel</studio>');
|
||||||
});
|
});
|
||||||
|
|
||||||
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 deps = createMockDeps();
|
||||||
const service = new DownloadService(
|
const service = new DownloadService(
|
||||||
db, deps.rateLimiter, deps.fileOrganizer,
|
db, deps.rateLimiter, deps.fileOrganizer,
|
||||||
|
|
@ -820,7 +820,7 @@ describe('DownloadService', () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
const outputPath = setupSuccessfulDownload(deps);
|
const outputPath = setupSuccessfulDownload(deps);
|
||||||
getAppSettingMock.mockResolvedValueOnce(null); // Not set
|
getPlatformSettingsMock.mockResolvedValueOnce({ nfoEnabled: false });
|
||||||
|
|
||||||
await service.downloadItem(testContentItem, testChannel);
|
await service.downloadItem(testContentItem, testChannel);
|
||||||
|
|
||||||
|
|
@ -828,7 +828,7 @@ describe('DownloadService', () => {
|
||||||
expect(existsSync(nfoPath)).toBe(false);
|
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 deps = createMockDeps();
|
||||||
const service = new DownloadService(
|
const service = new DownloadService(
|
||||||
db, deps.rateLimiter, deps.fileOrganizer,
|
db, deps.rateLimiter, deps.fileOrganizer,
|
||||||
|
|
@ -836,7 +836,7 @@ describe('DownloadService', () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
const outputPath = setupSuccessfulDownload(deps);
|
const outputPath = setupSuccessfulDownload(deps);
|
||||||
getAppSettingMock.mockResolvedValueOnce('false');
|
getPlatformSettingsMock.mockResolvedValueOnce(null); // No settings for platform
|
||||||
|
|
||||||
await service.downloadItem(testContentItem, testChannel);
|
await service.downloadItem(testContentItem, testChannel);
|
||||||
|
|
||||||
|
|
@ -852,7 +852,7 @@ describe('DownloadService', () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
setupSuccessfulDownload(deps);
|
setupSuccessfulDownload(deps);
|
||||||
getAppSettingMock.mockRejectedValueOnce(new Error('DB read failed'));
|
getPlatformSettingsMock.mockRejectedValueOnce(new Error('DB read failed'));
|
||||||
|
|
||||||
// Download should still succeed
|
// Download should still succeed
|
||||||
const result = await service.downloadItem(testContentItem, testChannel);
|
const result = await service.downloadItem(testContentItem, testChannel);
|
||||||
|
|
@ -867,7 +867,7 @@ describe('DownloadService', () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
setupSuccessfulDownload(deps);
|
setupSuccessfulDownload(deps);
|
||||||
getAppSettingMock.mockResolvedValueOnce('true');
|
getPlatformSettingsMock.mockResolvedValueOnce({ nfoEnabled: true });
|
||||||
|
|
||||||
const result = await service.downloadItem(testContentItem, testChannel);
|
const result = await service.downloadItem(testContentItem, testChannel);
|
||||||
expect(result.status).toBe('downloaded');
|
expect(result.status).toBe('downloaded');
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import type { LibSQLDatabase } from 'drizzle-orm/libsql';
|
||||||
import type * as schema from '../db/schema/index';
|
import type * as schema from '../db/schema/index';
|
||||||
import { execYtDlp, spawnYtDlp, YtDlpError, classifyYtDlpError } from '../sources/yt-dlp';
|
import { execYtDlp, spawnYtDlp, YtDlpError, classifyYtDlpError } from '../sources/yt-dlp';
|
||||||
import { updateContentItem } from '../db/repositories/content-repository';
|
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 { generateNfo, writeNfoFile } from './nfo-generator';
|
||||||
import { parseProgressLine } from './progress-parser';
|
import { parseProgressLine } from './progress-parser';
|
||||||
import type { DownloadEventBus } from './event-bus';
|
import type { DownloadEventBus } from './event-bus';
|
||||||
|
|
@ -140,7 +140,7 @@ export class DownloadService {
|
||||||
this.rateLimiter.reportSuccess(platform as Platform);
|
this.rateLimiter.reportSuccess(platform as Platform);
|
||||||
|
|
||||||
// Generate NFO sidecar if enabled
|
// Generate NFO sidecar if enabled
|
||||||
await this.maybeWriteNfo(contentItem, channel, finalPath, logPrefix);
|
await this.maybeWriteNfo(contentItem, channel, finalPath, logPrefix, platform);
|
||||||
|
|
||||||
// Emit download:complete event
|
// Emit download:complete event
|
||||||
this.eventBus?.emitDownload('download:complete', { contentItemId: contentItem.id });
|
this.eventBus?.emitDownload('download:complete', { contentItemId: contentItem.id });
|
||||||
|
|
@ -471,11 +471,12 @@ export class DownloadService {
|
||||||
contentItem: ContentItem,
|
contentItem: ContentItem,
|
||||||
channel: Channel | null,
|
channel: Channel | null,
|
||||||
mediaFilePath: string,
|
mediaFilePath: string,
|
||||||
logPrefix: string
|
logPrefix: string,
|
||||||
|
platform: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const nfoEnabled = await getAppSetting(this.db, APP_NFO_ENABLED);
|
const settings = await getPlatformSettings(this.db, platform);
|
||||||
if (nfoEnabled !== 'true') return;
|
if (!settings?.nfoEnabled) return;
|
||||||
|
|
||||||
const nfoXml = generateNfo(contentItem, channel);
|
const nfoXml = generateNfo(contentItem, channel);
|
||||||
const nfoPath = await writeNfoFile(nfoXml, mediaFilePath);
|
const nfoPath = await writeNfoFile(nfoXml, mediaFilePath);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue