Files
hyperframes/packages/core/src/runtime/proxyWait.ts
T
Miguel Ángel cbcadbfbd0 fix(studio-server): uncopied HEVC clips no longer stall Studio while their preview copies are made (#4580)
* fix(studio-server): a cold proxy copy answers 202 at once and the preview retries until it lands

* fix(studio): timeline filmstrips wait for a clip's proxy copy instead of failing on the 202

* fix(studio-server): a copy that cannot be made reports its failure instead of answering 202 forever

* test(studio-server): pin that a full queue is not remembered and a reset probe stops waiting

* test(studio-server): pin that a failure outside ffmpeg is remembered too

* style(studio-server): keep comment share at base in the transcoder and decoder

* fix(core): a clip's proxy URL goes on the video only once the copy is served, so every reader of it works

* fix(player): the parent media mirror follows a clip's src, so it plays the preview copy once it lands

* perf(player): the mirror re-points a clip only when the parent takes over playback

* style(core): shorten the sync-state comment in the proxy swap

* fix(studio): the timeline follows a clip re-pointed at its preview copy

* fix(core): a failed readiness check is retried instead of leaving a clip on its original

* fix(studio-server): a composition card rendered while preview copies are made is not cached

* fix(core): frame captures wait for a pending preview copy as long as for a loading video

* fix(studio-server): the preview-copy check uses the shared realpath from main

* fix(player): re-pointing a clip onto another clip's file no longer plays that file twice

* fix(player): a clip that replaces another on the same file keeps its sound
2026-09-28 16:14:29 +00:00

20 lines
873 B
TypeScript

const MAX_FAILED_ASKS = 3;
/** Asks for one byte of a `?hf-proxy=` URL until it is served, after each Retry-After: while the
* server answers 202 (copy being made) or 503 (queue full), and after up to 3 failed asks. */
export async function waitForServedProxy(href: string, live: () => boolean): Promise<boolean> {
let failed = 0;
while (live()) {
const res = await fetch(href, { headers: { Range: "bytes=0-0" }, cache: "no-store" }).catch(
() => null,
);
void res?.body?.cancel().catch(() => {});
const pending = res?.status === 202 || res?.status === 503;
if (!pending && res?.ok) return true;
if (!pending && ++failed > MAX_FAILED_ASKS) return false;
const seconds = Math.min(Number(res?.headers.get("Retry-After")) || 2, 30);
await new Promise((resolveWait) => setTimeout(resolveWait, seconds * 1000));
}
return false;
}