mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-09 09:26:14 -08:00
fix(stalker): serialize overlapping edits
This commit is contained in:
1 parent
a7ccdc905b
commit
7c8b94a9ed
7 files changed
+43
-7
No files matched your search
@@ -1167,7 +1167,7 @@ engine` (restart required) or
|
||||
|
||||
- Portal mode (full vs. simple) follows OBSERVED behavior, never a URL substring. The single predicate is `isFullStalkerPortalPlaylist()` / `isFullStalkerPortalUrl()` in `@iptvnator/shared/interfaces` (`stalker-portal-mode.util.ts`): the persisted `Playlist.isFullStalkerPortal` flag is authoritative and the URL shape is a fallback for legacy rows only. Three diverging copies of this rule used to exist and shipped broken configurations (#850/#686/#755) — never re-implement it. A token-enforcing `portal.php` panel is a full portal; a `server/load.php` endpoint that answers without a token is a simple one.
|
||||
- Import requires an explicit HTTP(S) scheme but accepts a bare host, `/c`, or a concrete `.php` address. It probes candidates in order (a pasted `.php` endpoint first, then `<base>/portal.php` → `<base>/server/load.php` → `<base>/stalker_portal/server/load.php`) and classifies each by behavior — a token-less `itv/get_genres` returning data proves a token-free panel; the plain-text auth failure proves a full portal, confirmed by a real handshake + `get_profile`. `StalkerPortalDiscoveryService` (`libs/portal/stalker/data-access`) persists and displays the proven endpoint and mode. An unreachable panel-style import remains allowed with a warning; a bare host falls back to `<base>/portal.php`, while canonical-shaped unreachable addresses still abort.
|
||||
- The playlist-info Edit dialog preserves an unchanged connection byte-for-byte and skips discovery. Changing URL, MAC, credentials, serial, device IDs or signatures blocks duplicate saves and runs the existing discovery service through the app-provided `STALKER_PLAYLIST_CONNECTION_EDITOR` token, keeping Stalker data-access out of `playlist-shared-ui`. Before discovery it reserves the playlist ID, blocks every new authentication (including fingerprint-equivalent URL edits) and repair, drains existing work, and rechecks ownership after every asynchronous drain/rebase; failure releases the reservation without changing the saved or runtime connection. Success uses one awaited write to atomically replace endpoint, mode, normalized identity and session metadata, then feeds its complete merged row into the state-only NgRx update and active `StalkerStore`/session/watchdog replacement before another same-route request can use the old connection. This preserves playback headers and other metadata absent from the form. Runtime session authority may rebase a changed fingerprint only when the persisted row proves that it owns the same playlist ID, so delete/restore and backup merge remain usable. The transient `PlaylistMetaUpdate.stalkerSessionPatch` preserves on absence, clears on `null`, and fully replaces from an object before storage; it is projected onto existing flat playlist fields and never changes the DB or backup shape.
|
||||
- The playlist-info Edit dialog preserves an unchanged connection byte-for-byte and skips discovery. Changing URL, MAC, credentials, serial, device IDs or signatures blocks duplicate saves, disables dialog closure for the validation window, and runs the existing discovery service through the app-provided `STALKER_PLAYLIST_CONNECTION_EDITOR` token, keeping Stalker data-access out of `playlist-shared-ui`. Before discovery it reserves the playlist ID; a second Edit cannot replace that owner. The reservation blocks every new authentication (including fingerprint-equivalent URL edits) and repair, drains existing work, and rechecks ownership after every asynchronous drain/rebase; failure releases it without changing the saved or runtime connection. Success uses one awaited write to atomically replace endpoint, mode, normalized identity and session metadata, then feeds its complete merged row into the state-only NgRx update and active `StalkerStore`/session/watchdog replacement before another same-route request can use the old connection. This preserves playback headers and other metadata absent from the form. Runtime session authority may rebase a changed fingerprint only when the persisted row proves that it owns the same playlist ID, so delete/restore and backup merge remain usable. The transient `PlaylistMetaUpdate.stalkerSessionPatch` preserves on absence, clears on `null`, and fully replaces from an object before storage; it is projected onto existing flat playlist fields and never changes the DB or backup shape.
|
||||
- `executeStalkerRequest()` (`stores/utils/stalker-request.utils.ts`) is the choke point for catalog, content and playback requests: mode routing, the in-session repair override, and retry-once all live there. Four callers are deliberately outside it because they run below or before the thing it routes on — `StalkerAuthApi` (handshake/`get_profile`/`do_auth`, which the full-portal branch is built from; routing them back would recurse), `StalkerPortalDiscoveryService` (probes precede the mode they determine), `StalkerAccountInfoService.fetchViaProfile()`, and `StreamResolverService` for a collection item with no playlist row. They are exempt from the routing, not from the repair it hooks, but only `fetchViaProfile()` wires `StalkerPortalRepairService` itself: discovery is what repair _drives_, the row-less resolver branch has no playlist to repair, and the auth layer needs nothing — a terminal handshake failure propagates out of the full-portal branch into whichever `executeStalkerRequest()` call triggered the authentication, which is why terminal handshake failures are a repair trigger. Anything new that is not auth or discovery belongs on `executeStalkerRequest()`. Existing playlists are repaired LAZILY (`StalkerPortalRepairService`) — only after a request fails with a shape a wrong endpoint/mode produces, at most once per source configuration per playlist per session, persisted through the atomic `PlaylistsService.transformPlaylistMeta`. There is deliberately **no eager one-shot migration**: a portal that works is never re-probed.
|
||||
- Explicit Edit advances the repair generation before installing its resolved session. A lazy repair that started earlier is discarded even if it had already verified its row, so it cannot restore an older endpoint, mode or token after Edit.
|
||||
- Both transports build the wire format from the same shared builders in `@iptvnator/shared/interfaces` — `buildStalkerRequestUrl()`, `buildStalkerIdentityRequestContext()`, `encodeStalkerCmdValue()` — so the Electron and PWA legs cannot drift. The mock's `/stalker` mirror shares the identity builder only — it dispatches in-process, so there is no portal URL to build and it mirrors the `JsHttpRequest` default by hand. Never fork any of them.
|
||||
|
||||
@@ -199,11 +199,13 @@ device IDs and signatures as one connection identity. A metadata-only edit
|
||||
does not run discovery and preserves the stored connection byte-for-byte.
|
||||
Changing any connection field disables the form while the same discovery
|
||||
service validates the draft. Auth rejection or an unreachable portal leaves
|
||||
the dialog open and writes nothing. Before discovery starts, Edit reserves the
|
||||
playlist ID, blocks every new authentication (including a URL edit with the same
|
||||
normalized fingerprint) and repair, and drains any work already in flight.
|
||||
Ownership is rechecked after every asynchronous drain or authority rebase;
|
||||
failure releases that reservation with the previous runtime untouched.
|
||||
the dialog open and writes nothing. Escape/backdrop closure is disabled for the
|
||||
validation window. Before discovery starts, Edit reserves the playlist ID; an
|
||||
overlapping Edit cannot replace that owner. The reservation blocks every new
|
||||
authentication (including a URL edit with the same normalized fingerprint) and
|
||||
repair, and drains any work already in flight. Ownership is rechecked after
|
||||
every asynchronous drain or authority rebase; failure releases that reservation
|
||||
with the previous runtime untouched.
|
||||
Success atomically replaces the endpoint, mode and normalized identity together
|
||||
with session metadata: simple mode
|
||||
clears token/fingerprint/watchdog/account state, while full mode replaces it
|
||||
|
||||
+7
@@ -51,6 +51,7 @@ describe('PlaylistInfoComponent', () => {
|
||||
};
|
||||
let dialogRef: {
|
||||
close: jest.Mock;
|
||||
disableClose: boolean;
|
||||
};
|
||||
let stalkerConnectionEditor: {
|
||||
resolveConnection: jest.Mock;
|
||||
@@ -104,6 +105,7 @@ describe('PlaylistInfoComponent', () => {
|
||||
};
|
||||
dialogRef = {
|
||||
close: jest.fn(),
|
||||
disableClose: false,
|
||||
};
|
||||
stalkerConnectionEditor = {
|
||||
applyResolvedConnection: jest.fn().mockResolvedValue(undefined),
|
||||
@@ -852,6 +854,7 @@ describe('PlaylistInfoComponent', () => {
|
||||
const secondSave = component.saveChanges(value);
|
||||
|
||||
expect(component.isSaving()).toBe(true);
|
||||
expect(dialogRef.disableClose).toBe(true);
|
||||
expect(
|
||||
stalkerConnectionEditor.resolveConnection
|
||||
).toHaveBeenCalledTimes(1);
|
||||
@@ -861,6 +864,7 @@ describe('PlaylistInfoComponent', () => {
|
||||
});
|
||||
await Promise.all([firstSave, secondSave]);
|
||||
expect(store.dispatch).not.toHaveBeenCalled();
|
||||
expect(dialogRef.disableClose).toBe(false);
|
||||
});
|
||||
|
||||
it('accepts a bare HTTP host but rejects an address without a protocol', () => {
|
||||
@@ -872,6 +876,9 @@ describe('PlaylistInfoComponent', () => {
|
||||
|
||||
control?.setValue('https://portal.example.com');
|
||||
expect(control?.valid).toBe(true);
|
||||
|
||||
control?.setValue('HTTP://portal.example.com/c');
|
||||
expect(control?.valid).toBe(true);
|
||||
});
|
||||
|
||||
it('persists a grandfathered MAC untouched on submit', async () => {
|
||||
|
||||
+6
@@ -365,6 +365,9 @@ export class PlaylistInfoComponent {
|
||||
}
|
||||
|
||||
this.isSaving.set(true);
|
||||
if (this.dialogRef) {
|
||||
this.dialogRef.disableClose = true;
|
||||
}
|
||||
try {
|
||||
let resolvedStalkerConnection = false;
|
||||
let normalizedPlaylist: PlaylistMetaUpdate =
|
||||
@@ -446,6 +449,9 @@ export class PlaylistInfoComponent {
|
||||
}
|
||||
);
|
||||
} finally {
|
||||
if (this.dialogRef) {
|
||||
this.dialogRef.disableClose = false;
|
||||
}
|
||||
this.isSaving.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import {
|
||||
type PlaylistMeta,
|
||||
} from '@iptvnator/shared/interfaces';
|
||||
|
||||
export const STALKER_PORTAL_URL_PATTERN = /^\s*https?:\/\/[^ "\s]+\s*$/;
|
||||
export const STALKER_PORTAL_URL_PATTERN = /^\s*https?:\/\/[^ "\s]+\s*$/i;
|
||||
|
||||
const STALKER_CONNECTION_FIELDS = [
|
||||
'portalUrl',
|
||||
|
||||
@@ -129,6 +129,24 @@ describe('Stalker edited-session coordination', () => {
|
||||
service.cancelEditDiscovery(fence);
|
||||
});
|
||||
|
||||
it('rejects an overlapping edit without retiring the first owner', async () => {
|
||||
const firstFence = await service.beginEditDiscovery(oldPlaylist);
|
||||
|
||||
await expect(
|
||||
service.beginEditDiscovery({
|
||||
...oldPlaylist,
|
||||
username: 'second-edit',
|
||||
})
|
||||
).rejects.toThrow(/already in progress/i);
|
||||
|
||||
await expect(
|
||||
service.replaceSessionAfterEdit(
|
||||
{ ...oldPlaylist, stalkerToken: 'FIRST_EDIT_TOKEN' },
|
||||
firstFence
|
||||
)
|
||||
).resolves.toEqual(oldPlaylist);
|
||||
});
|
||||
|
||||
it('prevents late pre-edit auth from restoring a cleared simple session', async () => {
|
||||
const oldAuthentication = service.ensureToken(oldPlaylist);
|
||||
while (authenticate.mock.calls.length === 0) {
|
||||
|
||||
@@ -69,6 +69,9 @@ export class StalkerEditedSessionCoordinator {
|
||||
|
||||
async beginEdit(playlist: Playlist): Promise<StalkerEditFence> {
|
||||
const playlistId = playlist._id;
|
||||
if (this.pendingEdits.has(playlistId)) {
|
||||
throw new Error('Stalker playlist edit already in progress');
|
||||
}
|
||||
const fingerprint = stalkerSessionFingerprint(playlist);
|
||||
const fence = { playlistId, owner: Symbol('stalker-edit') };
|
||||
this.pendingEdits.set(playlistId, {
|
||||
|
||||
Reference in new issue
Block a user