phase 2 rework
This commit is contained in:
1 parent
20054198f3
commit
b397ea9256
44 files changed
+5528
-1377
No files matched your search
@@ -0,0 +1,141 @@
|
||||
# Phase 2 refinements: dashboard, worker activity, naming, and session cache
|
||||
|
||||
Implementation date: 23 October 2026.
|
||||
|
||||
The user confirmed that a series and a single episode completed successfully with the first Phase 2 interface, then requested these refinements. This update is applied over `Proxer-Downloader-phase2-ui-update.zip`. It preserves the confirmed verification-pause/retry behavior and the entire original `scripts/lib/` tree.
|
||||
|
||||
## Interface changes
|
||||
|
||||
`/` is now the Dashboard. The top bar links Dashboard, New download (`/download`), Queue, and Workers. Old `/?mode=series` and `/?mode=video` bookmarks redirect to the corresponding form.
|
||||
|
||||
The Dashboard and Queue begin with a horizontally scrollable card strip showing each managed worker's current claims, filename, source episode/language, start time, elapsed time, and current file size. Empty cards distinguish idle, paused, stopped, and uncertain activity. Existing claims without worker metadata appear in a separate unassigned section. Supervisor failure leaves saved claims visible and marks the live inventory unavailable.
|
||||
|
||||
The Dashboard also provides four clickable state totals and the latest five completed and five failed-attempt records. Failed attempts can remain in history after a retained episode subsequently succeeds. Polls run every ten seconds while visible, without duplicate summary polling. Failed refreshes retain the last results and mark them stale.
|
||||
|
||||
The Queue's danger button is beside Refresh and follows the server-selected state and URL:
|
||||
|
||||
| Selected state | Action |
|
||||
|---|---|
|
||||
| Queued | Clear waiting queue |
|
||||
| Active | No destructive action; active downloads are protected |
|
||||
| Completed | Clear completed history |
|
||||
| Failed attempts | Clear failed history |
|
||||
|
||||
Confirmation states that the action applies to all records in that state, including records outside a search/page. History clearing does not remove media. Waiting-job deletion uses `{processing: {$ne: true}}` atomically, so a job claimed before deletion is preserved. The server accepts only the four known states, rejects active clearing, and requires an acknowledged deletion. Navigation/refresh keeps the action disabled while a new state is loading or a refresh has failed.
|
||||
|
||||
Workers offers **Quick add worker**, with server-assigned names `proxer-worker-1`, `proxer-worker-2`, etc. A MongoDB counter is seeded from the highest existing numbered PM2 name, including unrelated processes, then incremented atomically. Deletion/restart does not recycle numbers; a failed creation may leave a gap. Concurrent quick-add submissions reserve different numbers. An optional custom-name form remains available. Existing managed-script and numeric-ID restrictions remain in effect.
|
||||
|
||||
## Series names
|
||||
|
||||
The series form adds Season, default 1. Season 0 is allowed for specials. The title should not already include a season or episode suffix.
|
||||
|
||||
```text
|
||||
Title: My Series
|
||||
Season: 1
|
||||
Episodes: 9–10
|
||||
Language: engsub
|
||||
|
||||
My SeriesS001E009_engsub.mp4
|
||||
My SeriesS001E010_engsub.mp4
|
||||
```
|
||||
|
||||
Season and episode use a minimum of three digits, following the user's requested `{title}S{XXX}E{XXX}` pattern. Larger values expand rather than truncate. The language suffix stays immediately before `.mp4`. Filename previews and server planning use the same format and enforce the existing 255-byte limit including extension.
|
||||
|
||||
Season is filename metadata only. Proxer episode numbers are used unchanged; this update does not map absolute episode numbers into season-relative numbering. Series and season folders are not created. Single-episode explicit/default names, queued filenames, existing files, standalone Python CLI names, and older direct API requests that omit `season` keep their existing behavior.
|
||||
|
||||
The three-digit format is the requested local convention. Plex's [official TV naming guide](https://support.plex.tv/articles/naming-and-organizing-your-tv-show-files/) illustrates `sXXeXX` and separately discusses folder organization; it does not establish a mandatory three-digit width. Test one imported episode against the library's existing scanner and episode ordering.
|
||||
|
||||
## Session cache and access checks
|
||||
|
||||
A blank token field uses the token saved in the existing MongoDB `settings` collection. A supplied token replaces the cache only after a successful source-access check. The page always renders an empty password field and shows only safe metadata: saved/missing/replacement-needed status and last successful check time. Token values are absent from HTML/JSON responses, browser storage, URLs, raw upstream errors, and logs.
|
||||
|
||||
Every submission is checked, including repeated use on the same day. There is no fixed 24-hour expiration assumption or validation bypass based on cache age. Source/filename/output validation happens before the access probe, and no queue write happens until access succeeds.
|
||||
|
||||
The probe requests the first planned canonical HTTPS Proxer watch page using the configured cookie and `stream_choose=proxer-stream`. It requires positive `"code":"..."` evidence matching the protected resolver's source-access contract. It does not download media or alter `scripts/lib/`. Requests are capped at twelve seconds and one MiB; credentials are never forwarded through redirects or to other hosts.
|
||||
|
||||
| Result | Behavior |
|
||||
|---|---|
|
||||
| Positive source-access evidence | Save/revalidate the token, then enqueue with that verified credential |
|
||||
| No cached token and blank field | Ask for a token; add no jobs |
|
||||
| Explicit rejection | Ask for a current token; invalidate the exact rejected cache revision; add no jobs |
|
||||
| CAPTCHA/verification challenge | Ask for verification and a refreshed token; keep cache; add no jobs |
|
||||
| Missing first source | Ask to check series, episode, and language; keep cache; add no jobs |
|
||||
| Network, timeout, rate limit, server error | Report unavailable validation; keep cache; add no jobs |
|
||||
| Unrecognized source response or redirect | Report that access could not be verified; keep cache; add no jobs |
|
||||
| Cache read/write failure | Report unavailable token storage; add no jobs |
|
||||
|
||||
Concurrent updates use revision comparisons, including rotation after successful revalidation. An older rejected check cannot erase a newer saved or successfully revalidated token. A stale successful request cannot overwrite a newer replacement. Each accepted batch uses the credential actually checked for that submission.
|
||||
|
||||
This is a download-access check, not an assertion of account identity. The configured cookie can serve different purposes; Proxer's [published API documentation](https://proxer.me/wiki/Proxer_API/v1) describes a separate API-key/token mechanism. No new API key or login automation is introduced.
|
||||
|
||||
Existing queued jobs keep their original token. Rotation after enqueueing can still trigger the existing worker pause. The cache is shared by this application's database and is covered by the same MongoDB access and backup protection as queued credentials. There is no multi-user token ownership or encryption-key migration in this refinement.
|
||||
|
||||
## API and data additions
|
||||
|
||||
- `GET /dashboard-data`: `{counts, global, activity, recent: {done, failed}}`.
|
||||
- `GET /status-data`: retains the paginated Phase 2 shape and adds `activity`.
|
||||
- `GET /status-summary`: still only `{counts, global}`; no job, log, token, filesystem, or supervisor reads.
|
||||
- `POST /clear-state`: form body `state=queued|done|failed`; `processing` returns 409. Legacy clear endpoints remain scoped to their named states.
|
||||
- `POST /pm2/quick-add`: accepts an empty body and returns the server-assigned worker name on success.
|
||||
- `POST /queue`: `season` is optional for legacy series clients; a blank/missing token now uses the cache. Submission success is reported only after a confirmed insert/batch result. An uncertain queue write instructs the user to inspect the queue before retrying because partial insertion remains possible.
|
||||
|
||||
Activity includes `workers`, `unassigned`, `available`, `truncated`, and `workersTruncated`. Each worker includes safe identity/status fields and bounded public jobs. At most 51 processing records are read to display 50 and detect truncation; at most 50 worker cards are shown. PM2 inventory is cached for ten seconds with a single shared in-flight read. File metadata is read only for displayed active claims and the existing visible processing/completed queue page. Recent history reads at most five records per history state.
|
||||
|
||||
New claims atomically store `{name,pid,host,run_id,started_at}` under `worker`. A match requires the current host, an unambiguous live PID, and compatible worker/process start times. PID reuse, missing identities, and stopped/replaced processes do not create invented attribution. Claim release removes the metadata. This identity is diagnostic; it is not a lease, recovery lock, or new authority to release a claim.
|
||||
|
||||
Two additive settings records are used:
|
||||
|
||||
- `worker-name-sequence`: the highest reserved quick-add number.
|
||||
- `proxer-session-token`: the credential and internal revision plus safe status timestamps.
|
||||
|
||||
No migration of existing queue or history records is required. No dependency versions, Python entrypoints, streaming code, or environment-variable contract change.
|
||||
|
||||
## Verification
|
||||
|
||||
The final integrated `npm test` run passed **258 tests: 214 Node and 44 Python**, with no failures, skips, or cancellations. The protected-tree guard matched all seven original files before and after the run; `git diff --check` passed. Tests use local fixtures and injected database, process, and network interfaces.
|
||||
|
||||
| Suite | Passed |
|
||||
|---|---:|
|
||||
| Python downloader | 44 |
|
||||
| Node-to-Python integration | 5 |
|
||||
| Protected-library guard | 10 |
|
||||
| Runtime services | 25 |
|
||||
| HTTP and WebSocket services | 19 |
|
||||
| Submission, status, and safe templates | 19 |
|
||||
| Worker lifecycle | 39 |
|
||||
| Status query and form model | 16 |
|
||||
| Worker browser behavior | 11 |
|
||||
| Worker attribution and dashboard reads | 14 |
|
||||
| Numbered quick-add | 10 |
|
||||
| Season naming and clear-state integration | 11 |
|
||||
| Token cache and HTTP probe | 24 |
|
||||
| Token/controller integration | 11 |
|
||||
| **Total** | **258** |
|
||||
|
||||
Token tests cover validation on every submission, cache metadata secrecy, explicit rejection versus challenges/network failures, first-source ordering, no queue writes after failed checks, bounded/no-redirect probes, bodyless/error responses, and concurrent replacement/revalidation/invalidation races. Clear-state tests cover a concurrent claim, allowlisted predicates, acknowledgements, and preservation of media. Worker tests preserve the confirmed pause/retry and result-validation behavior.
|
||||
|
||||
A separate Playwright run in Chrome **151.0.7922.34** passed **42 browser checks** with zero JavaScript errors and no external requests. It used the real Express application, queue/dashboard/PM2 controllers, EJS/browser assets, activity service, and token-cache service with synthetic MongoDB/PM2/probe interfaces. Expected test failures deliberately returned HTTP 400, 409, and 503.
|
||||
|
||||
The browser run exercised real series/single form POSTs, season-zero and three-digit preview agreement, saved-token reuse/replacement/rejection, unavailable validation with cache retention, state-specific clearing with cancellation and active protection, quick-add selection and duplicate-command suppression, focused-link/log preservation, and shared-summary isolation. Worker cards show an overflow cue and can be scrolled with the keyboard.
|
||||
|
||||
Desktop views at 1440 × 1000 and all four pages at **390 × 844** and **320 × 844** were checked without page-level horizontal overflow. Screenshots were visually reviewed; the worker strip intentionally scrolls horizontally within its own container. Local runtimes were Node.js 24.19.0 and Python 3.12.14.
|
||||
|
||||
Live production MongoDB, PM2, authenticated media, and Plex import were not exercised in this workspace. The previous production workflow success was reported by the user. The new live access probe requires a valid cookie on the Debian host for acceptance.
|
||||
|
||||
## Deployment and acceptance
|
||||
|
||||
Use the `UPDATE.md`, manifest, read-only checker, and checksums in the refinement ZIP. Wait until both waiting and active counts reach zero, stop the actual web process and currently online managed workers, back up the application/configuration/database, and apply the complete `files/` overlay. Run preflight before copying and postflight plus the protected check/tests afterward. Restart the web process and the workers that were previously online. Reload open browser tabs.
|
||||
|
||||
The web entrypoint is still `server.js`; the worker entrypoint is still `queue_worker.js`. Run both as the download account. Existing `.env`, virtual environment, dependencies, and `/mnt/media/WIP` files stay in place. This refinement needs no new sudo privilege.
|
||||
|
||||
Recommended production acceptance checks:
|
||||
|
||||
1. Open `/`: the Dashboard is the landing page; worker cards show the newly restarted workers.
|
||||
2. Quick-add two workers and verify their distinct incremented names, selection, and logs.
|
||||
3. Submit a short series with Season 1, checking the filename preview. Submit another request with the token blank and confirm reuse.
|
||||
4. Try a rejected token and confirm a visible warning with no new jobs. Restore a valid token. A connection/challenge warning must not claim definite expiry.
|
||||
5. Check a current download card against its worker logs and file size. Verify the existing pause/manual-resume/retry flow still works.
|
||||
6. Switch queue states: confirm the danger action changes; cancel a clear confirmation once, then clear disposable completed/failed history and verify media remains.
|
||||
7. Import one `TitleS001E009_engsub.mp4` sample into the existing Plex library and confirm its series/season/episode mapping.
|
||||
|
||||
The next planned phase remains the shared execution refactor. Durable recovery, safe drain controls, advanced worker policies, and enforced speed limits remain later roadmap work.
|
||||
Reference in new issue
Block a user