fix(library): a listing poll can no longer put back an older resume point
A poll already out when the player closed answered with the point the server held before the closing beacon, over the row's patch; Continue then opened there and wrote it back. The close now cancels the listings' fetches before patching and reads them again once the beacon has landed.
This commit is contained in:
@@ -288,8 +288,9 @@ export function identityHeaders(): Record<string, string> {
|
||||
// Fire-and-forget POST that survives page unload (keepalive) — shared by the resume-position
|
||||
// beacons (YT + Plex players). A normal fetch is cancelled on unload and React effect cleanup
|
||||
// doesn't run on a full reload, so without keepalive the last position (esp. right after a seek)
|
||||
// would be lost.
|
||||
export function beacon(url: string, body: Record<string, unknown>): void {
|
||||
// would be lost. `onSettled`: the request has been answered (or failed) — for a caller whose cached
|
||||
// view must be read again once the write is on the server.
|
||||
export function beacon(url: string, body: Record<string, unknown>, onSettled?: () => void): void {
|
||||
try {
|
||||
void send(url, {
|
||||
method: "POST",
|
||||
@@ -297,7 +298,10 @@ export function beacon(url: string, body: Record<string, unknown>): void {
|
||||
credentials: "include",
|
||||
headers: { "Content-Type": "application/json", ...identityHeaders() },
|
||||
body: JSON.stringify(body),
|
||||
}).catch(() => {});
|
||||
}).then(
|
||||
() => onSettled?.(),
|
||||
() => onSettled?.(),
|
||||
);
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
|
||||
@@ -299,11 +299,16 @@ export const downloadsApi = {
|
||||
id: number,
|
||||
positionSeconds: number,
|
||||
durationSeconds: number,
|
||||
onSettled?: () => void,
|
||||
): void =>
|
||||
beacon(`/api/downloads/${id}/progress`, {
|
||||
position_seconds: Math.floor(positionSeconds),
|
||||
duration_seconds: Math.floor(durationSeconds),
|
||||
}),
|
||||
beacon(
|
||||
`/api/downloads/${id}/progress`,
|
||||
{
|
||||
position_seconds: Math.floor(positionSeconds),
|
||||
duration_seconds: Math.floor(durationSeconds),
|
||||
},
|
||||
onSettled,
|
||||
),
|
||||
// A plain <a> navigation can't send the X-Siftlode-Account header, so pass the active
|
||||
// account via ?account= (the server honours it only for an account in this browser's wallet) —
|
||||
// otherwise the download resolves to the session-default account and 404s for a per-tab
|
||||
|
||||
Reference in New Issue
Block a user