feat(api): add languages, music-video-credits-templates, stream-selectors, createChannel clients (#212)
New web/src/api/languages.ts module (getLanguages) plus channels.ts additions (getMusicVideoCreditsTemplates, getChannelStreamSelectors, createChannel) for the channel-editor gaps in #212. Each has URL-building tests.
This commit is contained in:
@@ -1,5 +1,13 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { getChannelById, updateChannel, type UpdateChannelRequest } from './channels';
|
||||
import {
|
||||
createChannel,
|
||||
getChannelById,
|
||||
getChannelStreamSelectors,
|
||||
getMusicVideoCreditsTemplates,
|
||||
updateChannel,
|
||||
type CreateChannelRequest,
|
||||
type UpdateChannelRequest
|
||||
} from './channels';
|
||||
|
||||
const sampleChannel = {
|
||||
id: 5,
|
||||
@@ -90,3 +98,69 @@ describe('updateChannel', () => {
|
||||
expect(JSON.parse(init?.body as string)).toMatchObject({ name: 'Renamed', number: '5' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('createChannel', () => {
|
||||
beforeEach(() => {
|
||||
window.localStorage.clear();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('POSTs the request body to /api/channels and returns the created view model', async () => {
|
||||
const fetchSpy = vi.spyOn(window, 'fetch').mockResolvedValue(
|
||||
new Response(JSON.stringify(sampleChannel), {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
status: 200
|
||||
})
|
||||
);
|
||||
|
||||
const body = { ...sampleChannel, id: undefined } as unknown as CreateChannelRequest;
|
||||
|
||||
await expect(createChannel(body)).resolves.toMatchObject({ id: 5 });
|
||||
|
||||
const [url, init] = fetchSpy.mock.calls[0];
|
||||
expect(url).toBe('/api/channels');
|
||||
expect((init?.method ?? '').toUpperCase()).toBe('POST');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getMusicVideoCreditsTemplates', () => {
|
||||
beforeEach(() => {
|
||||
window.localStorage.clear();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('GETs /api/channels/music-video-credits-templates', async () => {
|
||||
const fetchSpy = vi.spyOn(window, 'fetch').mockResolvedValue(
|
||||
new Response(JSON.stringify(['default']), {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
status: 200
|
||||
})
|
||||
);
|
||||
|
||||
await expect(getMusicVideoCreditsTemplates()).resolves.toEqual(['default']);
|
||||
|
||||
const [url] = fetchSpy.mock.calls[0];
|
||||
expect(url).toBe('/api/channels/music-video-credits-templates');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getChannelStreamSelectors', () => {
|
||||
beforeEach(() => {
|
||||
window.localStorage.clear();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('GETs /api/channels/stream-selectors', async () => {
|
||||
const fetchSpy = vi.spyOn(window, 'fetch').mockResolvedValue(
|
||||
new Response(JSON.stringify(['selector.py']), {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
status: 200
|
||||
})
|
||||
);
|
||||
|
||||
await expect(getChannelStreamSelectors()).resolves.toEqual(['selector.py']);
|
||||
|
||||
const [url] = fetchSpy.mock.calls[0];
|
||||
expect(url).toBe('/api/channels/stream-selectors');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -11,6 +11,7 @@ export type BulkMoveChannelsToGroupRequest = components['schemas']['BulkMoveChan
|
||||
export type BulkDeleteChannelsRequest = components['schemas']['BulkDeleteChannelsRequest'];
|
||||
export type CreateChannelFromLineupRequest = components['schemas']['CreateChannelFromLineupRequest'];
|
||||
export type CreateChannelFromLineupResponseModel = components['schemas']['CreateChannelFromLineupResponseModel'];
|
||||
export type CreateChannelRequest = components['schemas']['CreateChannelRequest'];
|
||||
|
||||
export interface ChannelsScreenData {
|
||||
channels: ChannelSummary[];
|
||||
@@ -46,6 +47,21 @@ export function updateChannel(channelId: number, body: UpdateChannelRequest): Pr
|
||||
});
|
||||
}
|
||||
|
||||
export function createChannel(body: CreateChannelRequest): Promise<Channel> {
|
||||
return request<Channel>('/api/channels', {
|
||||
body,
|
||||
method: 'POST'
|
||||
});
|
||||
}
|
||||
|
||||
export function getMusicVideoCreditsTemplates(): Promise<string[]> {
|
||||
return request<string[]>('/api/channels/music-video-credits-templates');
|
||||
}
|
||||
|
||||
export function getChannelStreamSelectors(): Promise<string[]> {
|
||||
return request<string[]>('/api/channels/stream-selectors');
|
||||
}
|
||||
|
||||
export async function getChannelsScreenData(): Promise<ChannelsScreenData> {
|
||||
const [channels, channelStates] = await Promise.all([
|
||||
getChannels(),
|
||||
|
||||
@@ -12,6 +12,7 @@ export * from './ffmpegProfiles';
|
||||
export * from './fillerPresets';
|
||||
export * from './guide';
|
||||
export * from './imageFolders';
|
||||
export * from './languages';
|
||||
export * from './libraries';
|
||||
export * from './libraryBrowse';
|
||||
export * from './logs';
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { getLanguages } from './languages';
|
||||
|
||||
function jsonResponse(body: unknown, status = 200): Response {
|
||||
return new Response(JSON.stringify(body), { headers: { 'Content-Type': 'application/json' }, status });
|
||||
}
|
||||
|
||||
describe('getLanguages', () => {
|
||||
beforeEach(() => {
|
||||
window.localStorage.clear();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('GETs /api/languages and returns the list', async () => {
|
||||
const fetchSpy = vi.spyOn(window, 'fetch').mockResolvedValue(
|
||||
jsonResponse([{ code: 'eng', englishName: 'English' }])
|
||||
);
|
||||
|
||||
await expect(getLanguages()).resolves.toEqual([{ code: 'eng', englishName: 'English' }]);
|
||||
|
||||
const [url, init] = fetchSpy.mock.calls[0];
|
||||
expect(url).toBe('/api/languages');
|
||||
expect((init?.method ?? 'GET').toUpperCase()).toBe('GET');
|
||||
});
|
||||
|
||||
it('rejects with the ApiError status on failure', async () => {
|
||||
vi.spyOn(window, 'fetch').mockResolvedValue(
|
||||
jsonResponse({ status: 500, title: 'Internal Server Error' }, 500)
|
||||
);
|
||||
|
||||
await expect(getLanguages()).rejects.toMatchObject({ status: 500 });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
import { ApiError, request } from './client';
|
||||
import type { components } from './generated/v1';
|
||||
|
||||
export type LanguageCode = components['schemas']['LanguageCodeResponseModel'];
|
||||
|
||||
export function getLanguages(): Promise<LanguageCode[]> {
|
||||
return request<LanguageCode[]>('/api/languages');
|
||||
}
|
||||
|
||||
export function messageFromLanguagesError(error: unknown, fallback = 'Unable to load languages'): string {
|
||||
if (error instanceof ApiError) {
|
||||
return error.detail ?? error.message;
|
||||
}
|
||||
|
||||
if (error instanceof Error) {
|
||||
return error.message;
|
||||
}
|
||||
|
||||
return fallback;
|
||||
}
|
||||
@@ -50,23 +50,27 @@ function json(body: unknown, status = 200): Response {
|
||||
}
|
||||
|
||||
interface FetchOptions {
|
||||
channelOverrides?: Record<string, unknown>;
|
||||
channelStatus?: number;
|
||||
onPut?: (body: unknown) => void;
|
||||
putResponseOverrides?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
function mockApi({ channelStatus = 200, onPut }: FetchOptions = {}) {
|
||||
function mockApi({ channelOverrides = {}, channelStatus = 200, onPut, putResponseOverrides = {} }: FetchOptions = {}) {
|
||||
const loadedChannel = { ...channel, ...channelOverrides };
|
||||
|
||||
return vi.spyOn(window, 'fetch').mockImplementation((input, init) => {
|
||||
const url = typeof input === 'string' ? input : input instanceof URL ? input.toString() : (input as Request).url;
|
||||
const method = (init?.method ?? 'GET').toUpperCase();
|
||||
|
||||
if (url === '/api/channels/5' && method === 'PUT') {
|
||||
onPut?.(JSON.parse(init?.body as string));
|
||||
return Promise.resolve(json({ ...channel, name: 'Renamed' }));
|
||||
return Promise.resolve(json({ ...loadedChannel, name: 'Renamed', ...putResponseOverrides }));
|
||||
}
|
||||
|
||||
if (url === '/api/channels/5') {
|
||||
return channelStatus === 200
|
||||
? Promise.resolve(json(channel))
|
||||
? Promise.resolve(json(loadedChannel))
|
||||
: Promise.resolve(json({ status: channelStatus, title: 'Not Found' }, channelStatus));
|
||||
}
|
||||
|
||||
@@ -86,6 +90,18 @@ function mockApi({ channelStatus = 200, onPut }: FetchOptions = {}) {
|
||||
return Promise.resolve(json([{ id: 5, number: '5', name: 'Cartoons', group: 'ChicoryTV' }]));
|
||||
}
|
||||
|
||||
if (url === '/api/languages') {
|
||||
return Promise.resolve(json([{ code: 'eng', englishName: 'English' }]));
|
||||
}
|
||||
|
||||
if (url === '/api/channels/music-video-credits-templates') {
|
||||
return Promise.resolve(json(['default']));
|
||||
}
|
||||
|
||||
if (url === '/api/channels/stream-selectors') {
|
||||
return Promise.resolve(json(['selector.py']));
|
||||
}
|
||||
|
||||
return Promise.resolve(json({ status: 404, title: 'Not Found' }, 404));
|
||||
});
|
||||
}
|
||||
@@ -158,4 +174,165 @@ describe('ChannelEditScreen', () => {
|
||||
expect(await screen.findByText('Channel not found.')).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'Back to channels' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
describe('external logo URL (Blazor ChannelEditor parity)', () => {
|
||||
it('hydrates the URL field from an external-URL logo and treats the uploaded logo as empty', async () => {
|
||||
mockApi({
|
||||
channelOverrides: { logo: { path: 'https://example.com/old-logo.png', contentType: '', isExternalUrl: true } }
|
||||
});
|
||||
render(<ChannelEditScreen />);
|
||||
|
||||
await screen.findByDisplayValue('Cartoons');
|
||||
fireEvent.click(screen.getByRole('button', { name: /^Branding/ }));
|
||||
|
||||
expect(await screen.findByDisplayValue('https://example.com/old-logo.png')).toBeInTheDocument();
|
||||
// The preview shows the external URL, not an uploaded-logo path.
|
||||
expect(screen.getByRole('img', { name: 'Cartoons' })).toHaveAttribute('src', 'https://example.com/old-logo.png');
|
||||
});
|
||||
|
||||
it('sends an external URL as the logo, winning over any previously uploaded logo, on save', async () => {
|
||||
const puts: unknown[] = [];
|
||||
mockApi({
|
||||
channelOverrides: { logo: { path: 'iptv/logos/uploaded.png', contentType: 'image/png' } },
|
||||
onPut: (body) => puts.push(body)
|
||||
});
|
||||
render(<ChannelEditScreen />);
|
||||
|
||||
await screen.findByDisplayValue('Cartoons');
|
||||
fireEvent.click(screen.getByRole('button', { name: /^Branding/ }));
|
||||
|
||||
const urlInput = screen.getByPlaceholderText('https://example.com/logo.png');
|
||||
fireEvent.change(urlInput, { target: { value: 'https://example.com/new-logo.png' } });
|
||||
|
||||
const saveButton = await screen.findByRole('button', { name: 'Save changes' });
|
||||
fireEvent.click(saveButton);
|
||||
|
||||
await waitFor(() => expect(puts).toHaveLength(1));
|
||||
|
||||
expect(puts[0]).toMatchObject({
|
||||
logo: { path: 'https://example.com/new-logo.png', contentType: '' }
|
||||
});
|
||||
});
|
||||
|
||||
it('shows an inline error and blocks save for a non-http(s) URL', async () => {
|
||||
mockApi();
|
||||
render(<ChannelEditScreen />);
|
||||
|
||||
await screen.findByDisplayValue('Cartoons');
|
||||
fireEvent.click(screen.getByRole('button', { name: /^Branding/ }));
|
||||
|
||||
const urlInput = screen.getByPlaceholderText('https://example.com/logo.png');
|
||||
fireEvent.change(urlInput, { target: { value: 'not-a-url' } });
|
||||
|
||||
expect(await screen.findByText('Enter a valid http(s) URL')).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'Save changes' })).toBeDisabled();
|
||||
});
|
||||
|
||||
it('clears the external URL field when a file is uploaded', async () => {
|
||||
mockApi();
|
||||
vi.spyOn(window, 'fetch').mockImplementation((input, init) => {
|
||||
const url = typeof input === 'string' ? input : input instanceof URL ? input.toString() : (input as Request).url;
|
||||
const method = (init?.method ?? 'GET').toUpperCase();
|
||||
|
||||
if (url === '/api/artwork/uploads' && method === 'POST') {
|
||||
return Promise.resolve(json({ path: 'iptv/logos/new.png', contentType: 'image/png' }));
|
||||
}
|
||||
|
||||
if (url === '/api/channels/5') {
|
||||
return Promise.resolve(json(channel));
|
||||
}
|
||||
|
||||
if (url === '/api/ffmpeg/profiles') {
|
||||
return Promise.resolve(json([{ id: 1, name: 'Default profile' }]));
|
||||
}
|
||||
|
||||
if (url === '/api/watermarks') {
|
||||
return Promise.resolve(json([{ id: 2, name: 'Corner bug' }]));
|
||||
}
|
||||
|
||||
if (url === '/api/filler-presets') {
|
||||
return Promise.resolve(json([{ id: 3, name: 'Bumpers' }]));
|
||||
}
|
||||
|
||||
if (url === '/api/channels') {
|
||||
return Promise.resolve(json([{ id: 5, number: '5', name: 'Cartoons', group: 'ChicoryTV' }]));
|
||||
}
|
||||
|
||||
if (url === '/api/languages') {
|
||||
return Promise.resolve(json([{ code: 'eng', englishName: 'English' }]));
|
||||
}
|
||||
|
||||
if (url === '/api/channels/music-video-credits-templates') {
|
||||
return Promise.resolve(json(['default']));
|
||||
}
|
||||
|
||||
if (url === '/api/channels/stream-selectors') {
|
||||
return Promise.resolve(json(['selector.py']));
|
||||
}
|
||||
|
||||
return Promise.resolve(json({ status: 404, title: 'Not Found' }, 404));
|
||||
});
|
||||
|
||||
render(<ChannelEditScreen />);
|
||||
|
||||
await screen.findByDisplayValue('Cartoons');
|
||||
fireEvent.click(screen.getByRole('button', { name: /^Branding/ }));
|
||||
|
||||
const urlInput = screen.getByPlaceholderText('https://example.com/logo.png');
|
||||
fireEvent.change(urlInput, { target: { value: 'https://example.com/new-logo.png' } });
|
||||
expect(urlInput).toHaveValue('https://example.com/new-logo.png');
|
||||
|
||||
const file = new File(['x'], 'logo.png', { type: 'image/png' });
|
||||
const fileInput = document.querySelector('input[type="file"]') as HTMLInputElement;
|
||||
fireEvent.change(fileInput, { target: { files: [file] } });
|
||||
|
||||
await waitFor(() => expect(urlInput).toHaveValue(''));
|
||||
});
|
||||
});
|
||||
|
||||
describe('picker fields (languages, credits template, stream selector)', () => {
|
||||
it('keeps a preferred audio language selectable even when missing from the language list', async () => {
|
||||
mockApi({ channelOverrides: { preferredAudioLanguageCode: 'spa' } });
|
||||
render(<ChannelEditScreen />);
|
||||
|
||||
await screen.findByDisplayValue('Cartoons');
|
||||
fireEvent.click(screen.getByRole('button', { name: /^Stream selection/ }));
|
||||
|
||||
const select = await screen.findByDisplayValue('spa');
|
||||
expect(select).toBeInTheDocument();
|
||||
expect(select.tagName).toBe('SELECT');
|
||||
});
|
||||
|
||||
it('populates the preferred audio language select from GET /api/languages', async () => {
|
||||
mockApi();
|
||||
render(<ChannelEditScreen />);
|
||||
|
||||
await screen.findByDisplayValue('Cartoons');
|
||||
fireEvent.click(screen.getByRole('button', { name: /^Stream selection/ }));
|
||||
|
||||
// Both the preferred-audio and preferred-subtitle language selects populate from the
|
||||
// same GET /api/languages list.
|
||||
expect((await screen.findAllByRole('option', { name: 'English' })).length).toBe(2);
|
||||
});
|
||||
|
||||
it('keeps a music video credits template selectable even when missing from the template list', async () => {
|
||||
mockApi({ channelOverrides: { musicVideoCreditsMode: 'GenerateSubtitles', musicVideoCreditsTemplate: 'legacy-template' } });
|
||||
render(<ChannelEditScreen />);
|
||||
|
||||
await screen.findByDisplayValue('Cartoons');
|
||||
fireEvent.click(screen.getByRole('button', { name: /^Music video/ }));
|
||||
|
||||
expect(await screen.findByDisplayValue('legacy-template')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('keeps a custom stream selector selectable even when missing from the selector list', async () => {
|
||||
mockApi({ channelOverrides: { streamSelectorMode: 'Custom', streamSelector: 'legacy-selector.py' } });
|
||||
render(<ChannelEditScreen />);
|
||||
|
||||
await screen.findByDisplayValue('Cartoons');
|
||||
fireEvent.click(screen.getByRole('button', { name: /^Stream selection/ }));
|
||||
|
||||
expect(await screen.findByDisplayValue('legacy-selector.py')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17,8 +17,11 @@ import {
|
||||
ApiError,
|
||||
getChannelById,
|
||||
getChannels,
|
||||
getChannelStreamSelectors,
|
||||
getFFmpegProfiles,
|
||||
getFillerPresets,
|
||||
getLanguages,
|
||||
getMusicVideoCreditsTemplates,
|
||||
getWatermarks,
|
||||
messageFromError,
|
||||
updateChannel,
|
||||
@@ -27,6 +30,7 @@ import {
|
||||
type ChannelSummary,
|
||||
type FFmpegProfile,
|
||||
type FillerPreset,
|
||||
type LanguageCode,
|
||||
type UpdateChannelRequest,
|
||||
type Watermark
|
||||
} from '../api';
|
||||
@@ -111,6 +115,12 @@ function channelIdFromPathname(pathname: string): number | null {
|
||||
return Number.isInteger(id) && id > 0 ? id : null;
|
||||
}
|
||||
|
||||
// Blazor parity (ChannelEditor.razor + ChannelEditViewModel.ToUpdate): an external logo URL is
|
||||
// tracked as separate form state from the uploaded-logo ArtworkContentTypeModel, and wins over it
|
||||
// on submit. When hydrating a channel whose logo IS an external URL, the uploaded-logo state is
|
||||
// treated as empty so the two fields never disagree.
|
||||
const EMPTY_LOGO: NonNullable<UpdateChannelRequest['logo']> = { path: '', contentType: '' };
|
||||
|
||||
// The PUT body is the GET response minus the read-only id / playoutCount / webEncodedName
|
||||
// fields, so hydration is a straight field copy.
|
||||
function draftFromChannel(channel: Channel): UpdateChannelRequest {
|
||||
@@ -121,7 +131,7 @@ function draftFromChannel(channel: Channel): UpdateChannelRequest {
|
||||
categories: channel.categories,
|
||||
ffmpegProfileId: channel.ffmpegProfileId,
|
||||
slugSeconds: channel.slugSeconds,
|
||||
logo: channel.logo,
|
||||
logo: channel.logo?.isExternalUrl ? EMPTY_LOGO : channel.logo,
|
||||
streamSelectorMode: channel.streamSelectorMode,
|
||||
streamSelector: channel.streamSelector,
|
||||
preferredAudioLanguageCode: channel.preferredAudioLanguageCode,
|
||||
@@ -149,6 +159,64 @@ function numberOrEmpty(value: null | number | undefined): string {
|
||||
return value == null ? '' : String(value);
|
||||
}
|
||||
|
||||
function externalLogoUrlFromChannel(channel: Channel): string {
|
||||
return channel.logo?.isExternalUrl ? (channel.logo.path ?? '') : '';
|
||||
}
|
||||
|
||||
// Blazor parity: the URL field only needs to look like http(s) when non-blank; blank means
|
||||
// "no external URL" and is always valid.
|
||||
function isValidExternalUrl(value: string): boolean {
|
||||
const trimmed = value.trim();
|
||||
|
||||
if (!trimmed) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
const url = new URL(trimmed);
|
||||
return url.protocol === 'http:' || url.protocol === 'https:';
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
interface StringOption {
|
||||
label: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
// Builds a "(none)" + list Select's options, keeping the channel's currently-stored value
|
||||
// selectable even if it's absent from the reference list (e.g. a language the media library
|
||||
// doesn't use, or a template/selector file that's been removed from disk since save) so loading
|
||||
// an existing channel never silently changes the value.
|
||||
function optionsKeepingCurrent(
|
||||
entries: StringOption[],
|
||||
current: null | string | undefined,
|
||||
noneLabel = '(none)'
|
||||
): StringOption[] {
|
||||
const options: StringOption[] = [{ label: noneLabel, value: '' }, ...entries];
|
||||
|
||||
if (current && !options.some((option) => option.value === current)) {
|
||||
options.push({ label: current, value: current });
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
function languageOptions(languages: LanguageCode[], current: null | string | undefined): StringOption[] {
|
||||
return optionsKeepingCurrent(
|
||||
languages.map((language) => ({ label: language.englishName ?? language.code ?? '', value: language.code ?? '' })),
|
||||
current
|
||||
);
|
||||
}
|
||||
|
||||
function stringListOptions(values: string[], current: null | string | undefined): StringOption[] {
|
||||
return optionsKeepingCurrent(
|
||||
values.map((value) => ({ label: value, value })),
|
||||
current
|
||||
);
|
||||
}
|
||||
|
||||
function sortByChannelNumber(channels: ChannelSummary[]): ChannelSummary[] {
|
||||
return [...channels].sort((left, right) => {
|
||||
const leftNumber = Number.parseFloat(left.number);
|
||||
@@ -207,6 +275,9 @@ interface ReferenceData {
|
||||
fillerPresets: FillerPreset[];
|
||||
watermarks: Watermark[];
|
||||
ffmpegProfiles: FFmpegProfile[];
|
||||
languages: LanguageCode[];
|
||||
musicVideoCreditsTemplates: string[];
|
||||
streamSelectors: string[];
|
||||
}
|
||||
|
||||
/* ---------- panes ---------- */
|
||||
@@ -431,9 +502,11 @@ function StreamingPane({
|
||||
}
|
||||
|
||||
function SelectionPane({
|
||||
data,
|
||||
draft,
|
||||
set
|
||||
}: {
|
||||
data: ReferenceData;
|
||||
draft: UpdateChannelRequest;
|
||||
set: (patch: Partial<UpdateChannelRequest>) => void;
|
||||
}) {
|
||||
@@ -458,13 +531,12 @@ function SelectionPane({
|
||||
</Row>
|
||||
{isDefault ? (
|
||||
<>
|
||||
<Row help="ISO 639-2 code, e.g. eng. Blank keeps the file order." label="Preferred audio language">
|
||||
<Input
|
||||
<Row help="Blank keeps the file order." label="Preferred audio language">
|
||||
<Select
|
||||
fullWidth
|
||||
onChange={(event) => set({ preferredAudioLanguageCode: event.target.value || null })}
|
||||
placeholder="eng"
|
||||
options={languageOptions(data.languages, draft.preferredAudioLanguageCode)}
|
||||
size="sm"
|
||||
style={{ fontFamily: 'var(--font-mono)' }}
|
||||
value={draft.preferredAudioLanguageCode ?? ''}
|
||||
/>
|
||||
</Row>
|
||||
@@ -476,13 +548,12 @@ function SelectionPane({
|
||||
value={draft.preferredAudioTitle ?? ''}
|
||||
/>
|
||||
</Row>
|
||||
<Row help="ISO 639-2 code, e.g. eng. Blank disables preference." label="Preferred subtitle language">
|
||||
<Input
|
||||
<Row help="Blank disables preference." label="Preferred subtitle language">
|
||||
<Select
|
||||
fullWidth
|
||||
onChange={(event) => set({ preferredSubtitleLanguageCode: event.target.value || null })}
|
||||
placeholder="eng"
|
||||
options={languageOptions(data.languages, draft.preferredSubtitleLanguageCode)}
|
||||
size="sm"
|
||||
style={{ fontFamily: 'var(--font-mono)' }}
|
||||
value={draft.preferredSubtitleLanguageCode ?? ''}
|
||||
/>
|
||||
</Row>
|
||||
@@ -503,11 +574,11 @@ function SelectionPane({
|
||||
</>
|
||||
) : (
|
||||
<Row help="Name of a custom stream-selector script in the config folder." label="Stream selector">
|
||||
<Input
|
||||
<Select
|
||||
fullWidth
|
||||
onChange={(event) => set({ streamSelector: event.target.value || null })}
|
||||
options={stringListOptions(data.streamSelectors, draft.streamSelector)}
|
||||
size="sm"
|
||||
style={{ fontFamily: 'var(--font-mono)' }}
|
||||
value={draft.streamSelector ?? ''}
|
||||
/>
|
||||
</Row>
|
||||
@@ -518,9 +589,11 @@ function SelectionPane({
|
||||
}
|
||||
|
||||
function MusicPane({
|
||||
data,
|
||||
draft,
|
||||
set
|
||||
}: {
|
||||
data: ReferenceData;
|
||||
draft: UpdateChannelRequest;
|
||||
set: (patch: Partial<UpdateChannelRequest>) => void;
|
||||
}) {
|
||||
@@ -544,12 +617,12 @@ function MusicPane({
|
||||
/>
|
||||
</Row>
|
||||
<Row help="Name of the credits template. Only used when credits are generated." label="Credits template">
|
||||
<Input
|
||||
<Select
|
||||
disabled={!creditsOn}
|
||||
fullWidth
|
||||
onChange={(event) => set({ musicVideoCreditsTemplate: event.target.value || null })}
|
||||
options={stringListOptions(data.musicVideoCreditsTemplates, draft.musicVideoCreditsTemplate)}
|
||||
size="sm"
|
||||
style={{ fontFamily: 'var(--font-mono)' }}
|
||||
value={draft.musicVideoCreditsTemplate ?? ''}
|
||||
/>
|
||||
</Row>
|
||||
@@ -573,24 +646,31 @@ function MusicPane({
|
||||
function BrandingPane({
|
||||
data,
|
||||
draft,
|
||||
externalLogoUrl,
|
||||
logoPreview,
|
||||
onChangeExternalLogoUrl,
|
||||
onUploadLogo,
|
||||
set,
|
||||
uploadError,
|
||||
uploading
|
||||
uploading,
|
||||
urlError
|
||||
}: {
|
||||
data: ReferenceData;
|
||||
draft: UpdateChannelRequest;
|
||||
externalLogoUrl: string;
|
||||
logoPreview: string | null;
|
||||
onChangeExternalLogoUrl: (value: string) => void;
|
||||
onUploadLogo: (file: File) => void;
|
||||
set: (patch: Partial<UpdateChannelRequest>) => void;
|
||||
uploadError: string | null;
|
||||
uploading: boolean;
|
||||
urlError: string | null;
|
||||
}) {
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
const hlsDirect = draft.streamingMode === 'HttpLiveStreamingDirect';
|
||||
const existingLogo = draft.logo?.urlWithContentType ?? draft.logo?.path ?? null;
|
||||
const previewSrc = logoPreview ?? existingLogo;
|
||||
const trimmedUrl = externalLogoUrl.trim();
|
||||
const previewSrc = trimmedUrl ? externalLogoUrl : (logoPreview ?? existingLogo);
|
||||
|
||||
return (
|
||||
<Pane subtitle="Channel logo and the overlays applied while streaming." title="Branding">
|
||||
@@ -629,6 +709,20 @@ function BrandingPane({
|
||||
/>
|
||||
</div>
|
||||
</Row>
|
||||
<Row
|
||||
control={340}
|
||||
help="An external image URL wins over an uploaded logo when both are set."
|
||||
label="External logo URL"
|
||||
>
|
||||
<Input
|
||||
error={urlError}
|
||||
fullWidth
|
||||
onChange={(event) => onChangeExternalLogoUrl(event.target.value)}
|
||||
placeholder="https://example.com/logo.png"
|
||||
size="sm"
|
||||
value={externalLogoUrl}
|
||||
/>
|
||||
</Row>
|
||||
<Row help={hlsDirect ? 'Not used in HLS Direct mode.' : 'Overlay applied to the channel.'} label="Watermark">
|
||||
<Select
|
||||
disabled={hlsDirect}
|
||||
@@ -681,6 +775,9 @@ export function ChannelEditScreen() {
|
||||
const [saved, setSaved] = useState<UpdateChannelRequest | null>(null);
|
||||
const [section, setSection] = useState<SectionId>('general');
|
||||
|
||||
const [externalLogoUrl, setExternalLogoUrl] = useState('');
|
||||
const [savedExternalLogoUrl, setSavedExternalLogoUrl] = useState('');
|
||||
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [justSaved, setJustSaved] = useState(false);
|
||||
const [saveError, setSaveError] = useState<string | null>(null);
|
||||
@@ -696,18 +793,30 @@ export function ChannelEditScreen() {
|
||||
|
||||
let active = true;
|
||||
|
||||
Promise.all([getChannelById(channelId), getFFmpegProfiles(), getWatermarks(), getFillerPresets(), getChannels()])
|
||||
.then(([channel, ffmpegProfiles, watermarks, fillerPresets, channels]) => {
|
||||
Promise.all([
|
||||
getChannelById(channelId),
|
||||
getFFmpegProfiles(),
|
||||
getWatermarks(),
|
||||
getFillerPresets(),
|
||||
getChannels(),
|
||||
getLanguages(),
|
||||
getMusicVideoCreditsTemplates(),
|
||||
getChannelStreamSelectors()
|
||||
])
|
||||
.then(([channel, ffmpegProfiles, watermarks, fillerPresets, channels, languages, musicVideoCreditsTemplates, streamSelectors]) => {
|
||||
if (!active) {
|
||||
return;
|
||||
}
|
||||
|
||||
const initial = draftFromChannel(channel);
|
||||
const initialExternalLogoUrl = externalLogoUrlFromChannel(channel);
|
||||
setDraft(initial);
|
||||
setSaved(initial);
|
||||
setExternalLogoUrl(initialExternalLogoUrl);
|
||||
setSavedExternalLogoUrl(initialExternalLogoUrl);
|
||||
setLoaded({
|
||||
channelId,
|
||||
data: { channels, ffmpegProfiles, fillerPresets, watermarks },
|
||||
data: { channels, ffmpegProfiles, fillerPresets, languages, musicVideoCreditsTemplates, streamSelectors, watermarks },
|
||||
playoutLocked: channel.playoutSource === 'Generated' && channel.playoutCount > 0
|
||||
});
|
||||
})
|
||||
@@ -770,6 +879,8 @@ export function ChannelEditScreen() {
|
||||
setDraft((current) =>
|
||||
current ? { ...current, logo: { path: uploaded.path, contentType: uploaded.contentType } } : current
|
||||
);
|
||||
// Blazor parity: uploading a file clears any external URL (the last-set field wins).
|
||||
setExternalLogoUrl('');
|
||||
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => setLogoPreview(typeof reader.result === 'string' ? reader.result : null);
|
||||
@@ -781,13 +892,21 @@ export function ChannelEditScreen() {
|
||||
}
|
||||
};
|
||||
|
||||
const changeExternalLogoUrl = (value: string) => {
|
||||
setJustSaved(false);
|
||||
setExternalLogoUrl(value);
|
||||
};
|
||||
|
||||
const nameValid = Boolean(draft.name?.trim());
|
||||
const numberValid = Boolean(draft.number?.trim());
|
||||
const valid = nameValid && numberValid;
|
||||
const dirty = JSON.stringify(draft) !== JSON.stringify(saved);
|
||||
const urlValid = isValidExternalUrl(externalLogoUrl);
|
||||
const valid = nameValid && numberValid && urlValid;
|
||||
const dirty = JSON.stringify(draft) !== JSON.stringify(saved) || externalLogoUrl !== savedExternalLogoUrl;
|
||||
const urlError = urlValid ? null : 'Enter a valid http(s) URL';
|
||||
|
||||
const discard = () => {
|
||||
setDraft(saved);
|
||||
setExternalLogoUrl(savedExternalLogoUrl);
|
||||
setLogoPreview(null);
|
||||
setSaveError(null);
|
||||
};
|
||||
@@ -801,10 +920,18 @@ export function ChannelEditScreen() {
|
||||
setSaveError(null);
|
||||
|
||||
try {
|
||||
const updated = await updateChannel(loaded.channelId, draft);
|
||||
const trimmedUrl = externalLogoUrl.trim();
|
||||
const body: UpdateChannelRequest = {
|
||||
...draft,
|
||||
logo: trimmedUrl ? { path: trimmedUrl, contentType: '' } : draft.logo
|
||||
};
|
||||
const updated = await updateChannel(loaded.channelId, body);
|
||||
const next = draftFromChannel(updated);
|
||||
const nextExternalLogoUrl = externalLogoUrlFromChannel(updated);
|
||||
setSaved(next);
|
||||
setDraft(next);
|
||||
setSavedExternalLogoUrl(nextExternalLogoUrl);
|
||||
setExternalLogoUrl(nextExternalLogoUrl);
|
||||
setLogoPreview(null);
|
||||
setJustSaved(true);
|
||||
window.setTimeout(() => setJustSaved(false), 1800);
|
||||
@@ -850,17 +977,20 @@ export function ChannelEditScreen() {
|
||||
<PlayoutPane channelId={loaded.channelId} data={loaded.data} draft={draft} playoutLocked={loaded.playoutLocked} set={set} />
|
||||
)}
|
||||
{section === 'streaming' && <StreamingPane data={loaded.data} draft={draft} set={set} />}
|
||||
{section === 'selection' && <SelectionPane draft={draft} set={set} />}
|
||||
{section === 'music' && <MusicPane draft={draft} set={set} />}
|
||||
{section === 'selection' && <SelectionPane data={loaded.data} draft={draft} set={set} />}
|
||||
{section === 'music' && <MusicPane data={loaded.data} draft={draft} set={set} />}
|
||||
{section === 'branding' && (
|
||||
<BrandingPane
|
||||
data={loaded.data}
|
||||
draft={draft}
|
||||
externalLogoUrl={externalLogoUrl}
|
||||
logoPreview={logoPreview}
|
||||
onChangeExternalLogoUrl={changeExternalLogoUrl}
|
||||
onUploadLogo={(file) => void uploadLogo(file)}
|
||||
set={set}
|
||||
uploadError={uploadError}
|
||||
uploading={uploading}
|
||||
urlError={urlError}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
@@ -876,7 +1006,8 @@ export function ChannelEditScreen() {
|
||||
) : (
|
||||
<>
|
||||
<span className="ctv-settings-savebar-text">Unsaved changes</span>
|
||||
{!valid && <Badge tone="neutral">Name and number are required</Badge>}
|
||||
{!nameValid || !numberValid ? <Badge tone="neutral">Name and number are required</Badge> : null}
|
||||
{!urlValid && <Badge tone="neutral">Logo URL must be http(s)</Badge>}
|
||||
{saveError && <span className="ctv-settings-savebar-error">{saveError}</span>}
|
||||
<span className="ctv-settings-savebar-divider" />
|
||||
<Button onClick={discard} size="sm" variant="ghost">
|
||||
|
||||
Reference in New Issue
Block a user