Files
ersatztv/web/src/api/ffmpegProfiles.ts
T
timothy b8c1de3368 fix(807): cover the two LIVE uncovered full-replace PUTs, correct four prose claims
Cold adversarial review returned BLOCKED. All findings confirmed by execution here
before acting on them.

H1 (blocker) — the change shipped with a live instance of the defect it claimed
was latent. `MultiCollectionItemRequest.weight` and
`UpdateFFmpegProfileRequest.qsvPreferNativeDecoder` are absent from their schemas'
`required` arrays, so both emit optional, and both are the body of a full-replace
PUT with a hand-built SPA body that the first commit did not cover. Deleting
`weight: clampWeight(item.weight)` from `MultiCollectionsScreen.toItemRequest`
typechecked CLEAN before this commit; the screen carries a prose comment warning
that this exact drop resets every weight to 1 on save. It now reddens with TS2741.

The bad reasoning is worth naming because it is a shape this repo keeps
recording: "create/update" vs "replace" was sorted on the verb in the wrapper
name rather than on what the endpoint does, and a property verified across the
eleven schemas the six named builders touch was then reported as a property of
the SPA. Coverage extended to `updateMultiCollection`, `updateFFmpegProfile`,
`replaceDeco`, and both `mediaSources` replace wrappers.

The FFmpeg fix surfaced a second instance one level down: the screen's `Draft`
type and the `sampleRequest` test fixture both omitted `qsvPreferNativeDecoder`,
so 30 green tests were exercising only the default. Both now `Complete<…>`.

H3 — "two sites had lost the phantom direction" is five, and the stated cause was
wrong. Measured: a fresh literal returned from a generic `.map` callback accepts a
phantom field even with no spread and no inferred local, because `map<U>` infers
`U` from the callback rather than from the target element type. Three of the five
contain neither a spread nor a local, so the documented rule would have taught a
reader that those are safe.

M4 — the generator was named as the cause of nullable-emits-as-required. It is a
pass-through (`required.has(name) ? '' : '?'`); the determinant is the `required`
array in the ASP.NET-produced `ErsatzTV/wwwroot/openapi/v1.json`. Pointed three
durable places at the right file.

M5 — the guard's header claimed every case reddens under every weakening, which
its own case-4 comment contradicted. Replaced with the measured table.

L6/L7/L8/N10 — record frontmatter now carries #807 so catalog-first lookup finds
it (catalog regenerated); `guard-inventory.md`'s hand-written out-of-population
list gains the third TS guard and now says why such a mirror goes stale silently;
`Complete` exported from the api barrel; §4b moved after §4a.

H2 is not fixed and is not implied closed: this guard proves `Complete<T>`'s
semantics, not that it is APPLIED — reverting one screen leaves it green. Filed
as #820 and named as residue on the record.

Verification: typecheck 0, eslint 0, 1200/1200 web tests, 833 passed 2 skipped in
scripts/tests, catalog regenerates to a zero diff, doc-narrative 0 warnings.

refs #820

Decisions-Edit: yes
2026-08-23 01:36:31 +02:00

45 lines
1.9 KiB
TypeScript

import type { Complete } from './completeRequest';
import { ApiError, request } from './client';
import type { components } from './generated/v1';
// The list endpoint (GET /api/v1/ffmpeg/profiles) is already provided by pickers.ts as
// getFFmpegProfiles() returning FFmpegProfile (= FFmpegFullProfileResponseModel). This
// module adds the by-id read, the mutations, and the hardware-acceleration lookup.
export type FFmpegProfileDetail = components['schemas']['FFmpegFullProfileResponseModel'];
export type CreateFFmpegProfileRequest = components['schemas']['CreateFFmpegProfileRequest'];
export type UpdateFFmpegProfileRequest = components['schemas']['UpdateFFmpegProfileRequest'];
export type HardwareAccelerationKind = components['schemas']['HardwareAccelerationKind'];
export function getFFmpegProfile(id: number): Promise<FFmpegProfileDetail> {
return request<FFmpegProfileDetail>(`/api/v1/ffmpeg/profiles/${id}`);
}
export function createFFmpegProfile(body: CreateFFmpegProfileRequest): Promise<FFmpegProfileDetail> {
return request<FFmpegProfileDetail>('/api/v1/ffmpeg/profiles', { body, method: 'POST' });
}
export function updateFFmpegProfile(id: number, body: Complete<UpdateFFmpegProfileRequest>): Promise<FFmpegProfileDetail> {
return request<FFmpegProfileDetail>(`/api/v1/ffmpeg/profiles/${id}`, { body, method: 'PUT' });
}
export function deleteFFmpegProfile(id: number): Promise<void> {
return request<void>(`/api/v1/ffmpeg/profiles/${id}`, { method: 'DELETE' });
}
export function getHardwareAccelerationKinds(): Promise<HardwareAccelerationKind[]> {
return request<HardwareAccelerationKind[]>('/api/v1/ffmpeg/hardware-acceleration-kinds');
}
export function messageFromFFmpegProfileError(error: unknown, fallback = 'Unable to load FFmpeg profiles'): string {
if (error instanceof ApiError) {
return error.detail ?? error.message;
}
if (error instanceof Error) {
return error.message;
}
return fallback;
}