Compare commits
40
Commits
318a920873
..
v0.2.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b24d391ac | ||
|
|
d94ae52e14 | ||
|
|
d8a552c61e | ||
|
|
bf1fa04f11 | ||
|
|
7b7d31bdfa | ||
|
|
14b0b955f5 | ||
|
|
b378214e9b | ||
|
|
0110b50a07 | ||
|
|
76eb6a6ef4 | ||
|
|
58d348859a | ||
|
|
3359ecf131 | ||
|
|
38a3859a21 | ||
|
|
96e876b8ec | ||
|
|
733e3c9089 | ||
|
|
dc7d6c9720 | ||
|
|
5c5bb6e5d6 | ||
|
|
35db22e3c5 | ||
|
|
b0cdac5483 | ||
|
|
f367bbe298 | ||
|
|
c61d8e9d3f | ||
|
|
78f6d44c73 | ||
|
|
a7f90cd5a7 | ||
|
|
c9575817fe | ||
|
|
b576ff5747 | ||
|
|
6510229b07 | ||
|
|
e61d91418e | ||
|
|
a1c461f6aa | ||
|
|
985c8df2cc | ||
|
|
6eab2eca9c | ||
|
|
eac29c428d | ||
|
|
ce00e3f518 | ||
|
|
c19717402c | ||
|
|
1ec2e81e15 | ||
|
|
bd9cf47ca9 | ||
|
|
6e06d1389c | ||
|
|
8c5f9b6ea0 | ||
|
|
74164b33ec | ||
|
|
75db7a3faa | ||
|
|
ed3cc9bc8a | ||
|
|
e01013ce6a |
@@ -0,0 +1,14 @@
|
|||||||
|
# Copy this file to `.env` and fill in your values. `.env` is git-ignored.
|
||||||
|
|
||||||
|
# Static LAN IP for the API container on Unraid's macvlan bridge (br0).
|
||||||
|
PSP_LAN_IP=192.168.10.100
|
||||||
|
|
||||||
|
# Host paths mounted into the container (Unraid shares).
|
||||||
|
PSP_STORE_HOST=/mnt/user/downloads/Sony - PlayStation Portable
|
||||||
|
PSP_STORE_VIDEOS_HOST=/mnt/user/psp/umd_videos_store
|
||||||
|
PSP_UMD_GAMES_HOST=/mnt/user/psp/umd_games
|
||||||
|
PSP_UMD_VIDEOS_HOST=/mnt/user/psp/umd_videos
|
||||||
|
|
||||||
|
# Initial admin account created on first boot (change the password after login).
|
||||||
|
PSP_ADMIN_USERNAME=admin
|
||||||
|
PSP_ADMIN_PASSWORD=change-me-now
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
name: build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags: ["v*"]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
linux:
|
||||||
|
name: Linux x86_64
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: "3.12"
|
||||||
|
|
||||||
|
- name: Install build dependencies
|
||||||
|
run: |
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
pip install -r requirements-build.txt
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: pyinstaller --clean --noconfirm psppt.spec
|
||||||
|
|
||||||
|
- name: Package tarball
|
||||||
|
run: |
|
||||||
|
cp packaging/install.sh dist/psppt/
|
||||||
|
cp packaging/psppt.desktop dist/psppt/
|
||||||
|
cp img/app-icon.png dist/psppt/
|
||||||
|
tar -czf psppt-linux-x86_64.tar.gz -C dist psppt
|
||||||
|
|
||||||
|
- uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: psppt-linux-x86_64
|
||||||
|
path: psppt-linux-x86_64.tar.gz
|
||||||
|
|
||||||
|
windows:
|
||||||
|
name: Windows x64 (Wine)
|
||||||
|
runs-on: windows
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install build dependencies
|
||||||
|
run: |
|
||||||
|
winpython -m pip install --upgrade pip
|
||||||
|
winpython -m pip install -r requirements-build.txt
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: winpython -m PyInstaller --clean --noconfirm psppt.spec
|
||||||
|
|
||||||
|
- name: Package zip
|
||||||
|
run: |
|
||||||
|
cd dist && zip -rq ../psppt-windows-x64.zip psppt
|
||||||
|
|
||||||
|
- uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: psppt-windows-x64
|
||||||
|
path: psppt-windows-x64.zip
|
||||||
+12
-1
@@ -16,4 +16,15 @@ data/*.pbp
|
|||||||
data/ps1_templates/
|
data/ps1_templates/
|
||||||
|
|
||||||
# nps tsv files
|
# nps tsv files
|
||||||
data/nps/*.tsv
|
data/nps/*.tsv
|
||||||
|
|
||||||
|
# Local environment overrides (LAN paths, secrets). See .env.example
|
||||||
|
.env
|
||||||
|
|
||||||
|
# PyInstaller output
|
||||||
|
build/
|
||||||
|
dist/
|
||||||
|
|
||||||
|
# Offline cover bundles (large; fetched from the project release on first run)
|
||||||
|
data/covers/*.zip
|
||||||
|
/psppt-covers.zip
|
||||||
@@ -3,5 +3,5 @@
|
|||||||
# Port-forward 80 and 443 on your router to this host.
|
# Port-forward 80 and 443 on your router to this host.
|
||||||
|
|
||||||
hostname.com {
|
hostname.com {
|
||||||
reverse_proxy psp-preserve:8000
|
reverse_proxy psppt:8000
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-3
@@ -2,8 +2,11 @@ FROM python:3.13-slim
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# The API is stdlib-only (no pip install needed).
|
COPY requirements-server.txt ./
|
||||||
|
RUN pip install --no-cache-dir -r requirements-server.txt
|
||||||
|
|
||||||
COPY app ./app
|
COPY app ./app
|
||||||
|
COPY server ./server
|
||||||
|
|
||||||
ENV PSP_DATA_DIR=/data \
|
ENV PSP_DATA_DIR=/data \
|
||||||
PSP_DATS_DIR=/data/dats \
|
PSP_DATS_DIR=/data/dats \
|
||||||
@@ -11,8 +14,9 @@ ENV PSP_DATA_DIR=/data \
|
|||||||
PSP_COVERS_DIR=/data/covers \
|
PSP_COVERS_DIR=/data/covers \
|
||||||
PSP_GAMES_ROOTS=/data/umd_games \
|
PSP_GAMES_ROOTS=/data/umd_games \
|
||||||
PSP_VIDEO_ROOTS=/data/umd_videos \
|
PSP_VIDEO_ROOTS=/data/umd_videos \
|
||||||
PSP_STORE_DIR=/data/store
|
PSP_STORE_DIR=/data/store \
|
||||||
|
PSP_STORE_VIDEOS_DIR=/data/store_videos
|
||||||
|
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
||||||
CMD ["python", "-m", "app.api", "--host", "0.0.0.0", "--port", "8000"]
|
CMD ["uvicorn", "server.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||||
|
|||||||
@@ -1,17 +1,22 @@
|
|||||||
# PSP Preservation Tool
|
# psppt
|
||||||
|
|
||||||
|
|
||||||
the name is terrible, i know.
|
the name is terrible, i know.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
Native Linux GUI (PySide6) for preserving PSP UMD **games** and **videos** as
|
A cross-platform (Linux + Windows) desktop GUI — PySide6 — for preserving PSP
|
||||||
`.iso` files. It scans your discs, verifies them against the full Redump catalog
|
UMD **games** and **videos** as `.iso` files. It scans your discs, verifies them
|
||||||
(Redump DATs), reports what's missing, and retags/renames discs to a canonical
|
against the Redump/No-Intro catalogs, reports what's missing, and retags/renames
|
||||||
scheme. It also fetches cover art and metadata, syncs discs and save-data with a
|
discs to a canonical scheme. It fetches cover art and metadata, syncs discs and
|
||||||
real PSP, can pull missing discs from your own Redump 7z archive collection, and
|
save-data with a real PSP, can pull missing discs from a Redump 7z archive
|
||||||
converts PlayStation 1 ISO/CUE/BIN rips into PSP `EBOOT.PBP` homebrew.
|
collection, downloads PSN content from NoPayStation, and converts PlayStation 1
|
||||||
|
ISO/CUE/BIN rips into PSP `EBOOT.PBP` homebrew.
|
||||||
|
|
||||||

|

|
||||||
* Use default app theme for Qt.
|
* Dark theme with a blue accent — the Library tab in cover view. *
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
@@ -35,9 +40,9 @@ converts PlayStation 1 ISO/CUE/BIN rips into PSP `EBOOT.PBP` homebrew.
|
|||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
- Linux + Python 3
|
- Python 3.10+ on Linux or Windows
|
||||||
- `PySide6` + `pycryptodome` (`pip install -r requirements.txt`)
|
- `PySide6`, `curl_cffi`, `pycryptodome` (`pip install -r requirements.txt`)
|
||||||
- `7z` (p7zip) — used to peek/extract disc images from store archives
|
- `7z` (p7zip / 7-Zip) — used to peek/extract disc images from store archives
|
||||||
- PPSSPP (optional) — to launch discs from the details panel
|
- PPSSPP (optional) — to launch discs from the details panel
|
||||||
|
|
||||||
NoPayStation `.pkg` files are decrypted by the bundled **pure-Python
|
NoPayStation `.pkg` files are decrypted by the bundled **pure-Python
|
||||||
@@ -58,6 +63,77 @@ pip install -r requirements.txt
|
|||||||
python3 -m app.main
|
python3 -m app.main
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Building binaries
|
||||||
|
|
||||||
|
The GUI is packaged with PyInstaller into a self-contained folder. Build
|
||||||
|
requirements are pinned in `requirements-build.txt` (PySide6 6.8.3 on purpose —
|
||||||
|
see the note inside).
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 -m venv .venv-build
|
||||||
|
. .venv-build/bin/activate
|
||||||
|
pip install -r requirements-build.txt
|
||||||
|
pyinstaller --clean --noconfirm psppt.spec
|
||||||
|
# output: dist/psppt/ → run dist/psppt/psppt
|
||||||
|
```
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
|
||||||
|
- The build bundles the DATs, PS1 loader, cover templates, and index catalogs
|
||||||
|
(~80 MB total). The large offline cover zips (~850 MB) are **not** bundled —
|
||||||
|
the app fetches them on first run (see
|
||||||
|
[Offline bundles](#offline-bundles--auto-download)).
|
||||||
|
- `7z` (p7zip-full on Linux, 7-Zip on Windows) is a **runtime** dependency for
|
||||||
|
reading store archives — it is not bundled.
|
||||||
|
- User data (credentials, manual covers, PS1 templates, NPS cache, library DB,
|
||||||
|
cover cache) lives in the OS state dir, never next to the binary.
|
||||||
|
|
||||||
|
### CI (Gitea Actions)
|
||||||
|
|
||||||
|
`.gitea/workflows/build.yml` builds Linux and Windows artifacts on version-tag
|
||||||
|
pushes (`v*`) or on manual trigger (**Actions → build → Run workflow**).
|
||||||
|
Artifacts appear on the Actions run page and can be attached to a release.
|
||||||
|
|
||||||
|
Each job needs a [Gitea Actions runner](https://docs.gitea.com/usage/actions/act-runner)
|
||||||
|
registered with the matching label:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Linux runner (Docker mode, run on your server)
|
||||||
|
./act_runner register \
|
||||||
|
--instance https://git.ceaf.dev \
|
||||||
|
--token <registration-token> \
|
||||||
|
--name linux-builder \
|
||||||
|
--labels ubuntu-latest:docker://node:20-bookworm
|
||||||
|
|
||||||
|
# Windows runner (host mode, run on a Windows machine)
|
||||||
|
act_runner.exe register \
|
||||||
|
--instance https://git.ceaf.dev \
|
||||||
|
--token <registration-token> \
|
||||||
|
--name win-builder \
|
||||||
|
--labels windows:host
|
||||||
|
```
|
||||||
|
|
||||||
|
The registration token is generated in Gitea under
|
||||||
|
**Site Administration → Actions → Runners → Create new runner**.
|
||||||
|
|
||||||
|
#### Windows builds without a Windows box (Wine runner)
|
||||||
|
|
||||||
|
The `windows` job targets a runner labelled `windows` that builds under Wine on
|
||||||
|
Linux. Build it from `runner/`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker build -f runner/Dockerfile -t psp-wine-runner .
|
||||||
|
docker run -d --name psp-wine-runner --restart unless-stopped \
|
||||||
|
-e GITEA_INSTANCE_URL=https://git.ceaf.dev \
|
||||||
|
-e GITEA_RUNNER_REGISTRATION_TOKEN=<registration-token> \
|
||||||
|
-v /mnt/user/appdata/psp-wine-runner:/data \
|
||||||
|
psp-wine-runner
|
||||||
|
```
|
||||||
|
|
||||||
|
The image ships Wine + Windows CPython 3.12 + PyInstaller, and registers itself
|
||||||
|
with the `windows:host` label. (If you have a real Windows machine instead,
|
||||||
|
register a native `act_runner.exe` with the same `windows` label.)
|
||||||
|
|
||||||
## First-time setup
|
## First-time setup
|
||||||
|
|
||||||
1. Put your DAT files in `data/dats/`:
|
1. Put your DAT files in `data/dats/`:
|
||||||
@@ -66,14 +142,15 @@ python3 -m app.main
|
|||||||
Redump lacks — keeps serial-based matching working).
|
Redump lacks — keeps serial-based matching working).
|
||||||
- videos: No-Intro `Sony - PlayStation Portable (UMD Video)` (Redump has
|
- videos: No-Intro `Sony - PlayStation Portable (UMD Video)` (Redump has
|
||||||
no UMD Video DAT).
|
no UMD Video DAT).
|
||||||
2. Ingest them into the local SQLite library:
|
2. Start the app — any DATs missing from the library are ingested automatically
|
||||||
|
at startup (no manual step). You can also re-ingest on demand:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python3 -m app.ingest
|
python3 -m app.ingest
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Open the GUI and point **Settings → General → Games/Videos directory** at
|
3. Point **Settings → General → Games/Videos directory** at your disc folders
|
||||||
your disc folders (or set `PSP_GAMES_ROOTS` / `PSP_VIDEO_ROOTS`).
|
(or set `PSP_GAMES_ROOTS` / `PSP_VIDEO_ROOTS`).
|
||||||
4. (Optional) PS1 conversion — copy any PSN PS1 classic `EBOOT.PBP` to
|
4. (Optional) PS1 conversion — copy any PSN PS1 classic `EBOOT.PBP` to
|
||||||
`data/base.PBP` (it supplies Sony's encrypted loader). Then set the **PS1
|
`data/base.PBP` (it supplies Sony's encrypted loader). Then set the **PS1
|
||||||
directory**, **PS1 output directory** and **PS1 base.pbp** in
|
directory**, **PS1 output directory** and **PS1 base.pbp** in
|
||||||
@@ -95,9 +172,10 @@ Discs are matched by hash first (most precise), then serial, then filename.
|
|||||||
- `data/credentials.json` — cover/metadata API keys (IGDB, TheMovieDB,
|
- `data/credentials.json` — cover/metadata API keys (IGDB, TheMovieDB,
|
||||||
ScreenScraper, Google Custom Search). Environment variables take precedence.
|
ScreenScraper, Google Custom Search). Environment variables take precedence.
|
||||||
- `data/manual_covers/games|videos/` — your own cover images.
|
- `data/manual_covers/games|videos/` — your own cover images.
|
||||||
- `data/covers/` — checked-in assets: the UMD video/game cover templates,
|
- `data/covers/` — checked-in assets: the UMD video/game cover templates and
|
||||||
`libretro-index.json` + `openvgdb-index.json` catalogs, `libretro-covers.zip` +
|
the `libretro-index.json` + `openvgdb-index.json` catalogs. The large
|
||||||
`openvgdb-covers.zip` offline cover bundles, and the legacy cover cache.
|
`libretro-covers.zip` + `openvgdb-covers.zip` bundles are git-ignored and
|
||||||
|
distributed as `psppt-covers.zip` (see above).
|
||||||
- `data/base.PBP` — a PSN PS1 classic EBOOT (any game) supplying `STARTDAT`
|
- `data/base.PBP` — a PSN PS1 classic EBOOT (any game) supplying `STARTDAT`
|
||||||
+ a base `PARAM.SFO`/icon for PS1 conversion (git-ignored, copyrighted).
|
+ a base `PARAM.SFO`/icon for PS1 conversion (git-ignored, copyrighted).
|
||||||
- `data/loader/DATA.PSP` + `data/loader/KEYS.BIN` — bundled plain-ELF POPS
|
- `data/loader/DATA.PSP` + `data/loader/KEYS.BIN` — bundled plain-ELF POPS
|
||||||
@@ -105,30 +183,29 @@ Discs are matched by hash first (most precise), then serial, then filename.
|
|||||||
- `data/ps1_templates/` — optional PS1 Classics art templates
|
- `data/ps1_templates/` — optional PS1 Classics art templates
|
||||||
(`ICON0.PNG` case frame, `PIC1.PNG` launch background); the app falls back
|
(`ICON0.PNG` case frame, `PIC1.PNG` launch background); the app falls back
|
||||||
to drawn art when they're absent.
|
to drawn art when they're absent.
|
||||||
- `data/nps/` — NoPayStation TSV lists (cached here on first store scan; drop
|
- `data/nps/` — NoPayStation TSV lists (cached here on first store scan in dev;
|
||||||
`PSP_GAMES.tsv` / `PSX_GAMES.tsv` manually to work offline).
|
a packaged build stores them under the state dir instead).
|
||||||
- `data/bin/pkg2zip.exe` — bundled `pkg2zip` binary (MIT, by mmozeiko) kept
|
- State dir (`~/.local/state/psppt/` on Linux, `%LOCALAPPDATA%\psppt`
|
||||||
only as an optional fallback decryptor; the app normally uses its own
|
on Windows, or `$PSP_STATE_DIR`):
|
||||||
pure-Python decryptor (`app/pkg.py`) and never needs Wine.
|
|
||||||
See `data/bin/ATTRIBUTION.md`.
|
|
||||||
- State dir (`~/.local/state/psp-preserve/` by default, or `$XDG_STATE_HOME/psp-preserve`):
|
|
||||||
- `library.sqlite` — the catalog + library database.
|
- `library.sqlite` — the catalog + library database.
|
||||||
- `covers/` — downloaded cover cache.
|
- `covers/` — downloaded cover cache.
|
||||||
|
- `data/` — user-writable data in packaged builds (credentials, manual
|
||||||
|
covers, PS1 templates, NPS TSV cache).
|
||||||
|
|
||||||
SQLite is kept on a local disk because SQLite locking is unreliable over
|
SQLite is kept on a local disk because SQLite locking is unreliable over
|
||||||
network filesystems; the DATs, manual covers and credentials stay in `data/`
|
network filesystems. Read-only resources (DATs, the POPS loader, icons) are
|
||||||
(which may be a network share).
|
bundled with the app; user-writable data lives in the state dir.
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
Everything is driven by environment variables, with GUI settings (stored in
|
Everything is driven by environment variables, with GUI settings (stored in
|
||||||
QSettings under `PSPPreserve`) taking precedence where noted.
|
QSettings under `psppt`) taking precedence where noted.
|
||||||
|
|
||||||
| Variable | Default | Purpose |
|
| Variable | Default | Purpose |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| `PSP_DATA_DIR` | `./data` | data root (DATs, credentials, manual covers) |
|
| `PSP_DATA_DIR` | `./data` | data root (DATs, credentials, manual covers) |
|
||||||
| `PSP_DATS_DIR` | `$PSP_DATA_DIR/dats` | DAT folder |
|
| `PSP_DATS_DIR` | `$PSP_DATA_DIR/dats` | DAT folder |
|
||||||
| `PSP_STATE_DIR` | `~/.local/state/psp-preserve` | local state root |
|
| `PSP_STATE_DIR` | `~/.local/state/psppt` | local state root |
|
||||||
| `PSP_DB_PATH` | `$PSP_STATE_DIR/library.sqlite` | SQLite library |
|
| `PSP_DB_PATH` | `$PSP_STATE_DIR/library.sqlite` | SQLite library |
|
||||||
| `PSP_COVERS_DIR` | `$PSP_STATE_DIR/covers` | cover cache |
|
| `PSP_COVERS_DIR` | `$PSP_STATE_DIR/covers` | cover cache |
|
||||||
| `PSP_GAMES_ROOTS` | `/data/umd_games` | comma-separated game disc roots |
|
| `PSP_GAMES_ROOTS` | `/data/umd_games` | comma-separated game disc roots |
|
||||||
@@ -136,7 +213,7 @@ QSettings under `PSPPreserve`) taking precedence where noted.
|
|||||||
| `PSP_PS1_ROOTS` | `/data/ps1` | comma-separated PS1 disc roots |
|
| `PSP_PS1_ROOTS` | `/data/ps1` | comma-separated PS1 disc roots |
|
||||||
| `PSP_PS1_OUTPUT_DIR` | `/data/ps1_converted` | converted EBOOT.PBP output folder |
|
| `PSP_PS1_OUTPUT_DIR` | `/data/ps1_converted` | converted EBOOT.PBP output folder |
|
||||||
| `PSP_SCAN_WORKERS` | `1` | parallel hashing workers |
|
| `PSP_SCAN_WORKERS` | `1` | parallel hashing workers |
|
||||||
| `PSP_STORE_DIR` | `/media/downloads/Sony - PlayStation Portable` | local 7z store folder |
|
| `PSP_STORE_DIR` | `/data/store` | local 7z store folder |
|
||||||
| `PSP_STORE_SERVER` | `https://psp.example.com` | store server base URL |
|
| `PSP_STORE_SERVER` | `https://psp.example.com` | store server base URL |
|
||||||
| `PSP_STORE_TOKEN` | *(empty)* | store server bearer token |
|
| `PSP_STORE_TOKEN` | *(empty)* | store server bearer token |
|
||||||
| `PSP_ARCHIVE_ITEM` | `psp-redump-roms321.com` | archive.org item identifier |
|
| `PSP_ARCHIVE_ITEM` | `psp-redump-roms321.com` | archive.org item identifier |
|
||||||
@@ -144,11 +221,12 @@ QSettings under `PSPPreserve`) taking precedence where noted.
|
|||||||
| `PSP_ARCHIVE_LOGGED_IN_USER` | *(empty)* | archive.org `logged-in-user` cookie |
|
| `PSP_ARCHIVE_LOGGED_IN_USER` | *(empty)* | archive.org `logged-in-user` cookie |
|
||||||
| `PSP_NPS_DIR` | `<state>/nps` | NoPayStation output folder |
|
| `PSP_NPS_DIR` | `<state>/nps` | NoPayStation output folder |
|
||||||
| `PSP_NPS_TSV_BASE` | `https://nopaystation.com/tsv/` | NoPayStation TSV base URL |
|
| `PSP_NPS_TSV_BASE` | `https://nopaystation.com/tsv/` | NoPayStation TSV base URL |
|
||||||
| `PSP_PKG2ZIP_PATH` | *(empty)* | pkg2zip binary path (else auto-detected) |
|
|
||||||
| `PSP_API_TOKEN` | *(empty)* | server API bearer token (unset = open) |
|
| `PSP_API_TOKEN` | *(empty)* | server API bearer token (unset = open) |
|
||||||
| `PSP_CREDENTIALS` | `$PSP_DATA_DIR/credentials.json` | credentials file |
|
| `PSP_USER_DATA_DIR` | `<state>/data` (packaged) / `./data` (dev) | user-writable data (credentials, manual covers, PS1 templates, NPS cache) |
|
||||||
|
| `PSP_CREDENTIALS` | `$PSP_USER_DATA_DIR/credentials.json` | credentials file |
|
||||||
| `PSP_LIBRETRO_COVERS_URL` | *(empty)* | direct URL for `libretro-covers.zip` (else derived from store server) |
|
| `PSP_LIBRETRO_COVERS_URL` | *(empty)* | direct URL for `libretro-covers.zip` (else derived from store server) |
|
||||||
| `PSP_OVGDB_COVERS_URL` | *(empty)* | direct URL for `openvgdb-covers.zip` (else derived from store server) |
|
| `PSP_OVGDB_COVERS_URL` | *(empty)* | direct URL for `openvgdb-covers.zip` (else derived from store server) |
|
||||||
|
| `PSP_COVERS_BUNDLE_URL` | Gitea `covers` release asset | combined `psppt-covers.zip` download URL |
|
||||||
|
|
||||||
Cover/metadata keys can also be set as env vars: `IGDB_CLIENT_ID`,
|
Cover/metadata keys can also be set as env vars: `IGDB_CLIENT_ID`,
|
||||||
`IGDB_CLIENT_SECRET`, `TMDB_API_KEY`, `GOOGLE_API_KEY`, `GOOGLE_CX`,
|
`IGDB_CLIENT_SECRET`, `TMDB_API_KEY`, `GOOGLE_API_KEY`, `GOOGLE_CX`,
|
||||||
@@ -181,12 +259,23 @@ Manual covers in `data/manual_covers/videos/` always win.
|
|||||||
|
|
||||||
### Offline bundles & auto-download
|
### Offline bundles & auto-download
|
||||||
|
|
||||||
The two bundles (`libretro-covers.zip`, `openvgdb-covers.zip`) are shipped in
|
The two bundles (`libretro-covers.zip`, `openvgdb-covers.zip`) are packaged
|
||||||
`data/covers/`, so a fresh install works with **no internet and no API keys**.
|
into one `psppt-covers.zip` (~850 MB) and attached to the repo's `covers`
|
||||||
If either is missing at startup, the app downloads it from the store server's
|
release — **not** bundled into the app binary.
|
||||||
`/api/covers/<name>.zip` endpoint (see [Server setup](#server-setup)).
|
|
||||||
|
|
||||||
Rebuild them yourself:
|
On first launch, if the bundle isn't installed, the app asks whether to
|
||||||
|
download it (with a progress bar). Covers keep working online via libretro /
|
||||||
|
OpenVGDB / ScreenScraper / IGDB without it — the bundle just makes them instant
|
||||||
|
and offline. "Don't ask again" is remembered, and you can re-download from
|
||||||
|
**Settings → Cover sources → Download offline cover bundle…**.
|
||||||
|
|
||||||
|
Build the bundle yourself:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 scripts/make-covers-bundle.py # -> psppt-covers.zip
|
||||||
|
```
|
||||||
|
|
||||||
|
Rebuild the inner zips:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python3 -m app.libretro # libretro-thumbnails -> libretro-covers.zip
|
python3 -m app.libretro # libretro-thumbnails -> libretro-covers.zip
|
||||||
@@ -235,7 +324,7 @@ Configure the folders in **Settings → General** (or `PSP_PS1_ROOTS` /
|
|||||||
`PSP_PS1_OUTPUT_DIR`). Current limits: single-disc games only (no multi-disc
|
`PSP_PS1_OUTPUT_DIR`). Current limits: single-disc games only (no multi-disc
|
||||||
PBP); disc data is DEFLATE-compressed (level 1 by default, `--complevel 0-9`).
|
PBP); disc data is DEFLATE-compressed (level 1 by default, `--complevel 0-9`).
|
||||||
|
|
||||||
## Store — archive.org and local folder
|
## Store — four sources
|
||||||
|
|
||||||
The **Store** tab downloads missing discs from a Redump 7z archive collection
|
The **Store** tab downloads missing discs from a Redump 7z archive collection
|
||||||
(`Name (Region) (tags).7z`, containing the `.iso`/`.cso` inside). It has three
|
(`Name (Region) (tags).7z`, containing the `.iso`/`.cso` inside). It has three
|
||||||
@@ -287,8 +376,7 @@ Requirements & behaviour:
|
|||||||
|
|
||||||
1. `.pkg` files are decrypted by the built-in **pure-Python decryptor**
|
1. `.pkg` files are decrypted by the built-in **pure-Python decryptor**
|
||||||
(`app/pkg.py`, powered by `pycryptodome` for speed) — no Wine and no
|
(`app/pkg.py`, powered by `pycryptodome` for speed) — no Wine and no
|
||||||
`pkg2zip` install needed. A bundled `pkg2zip.exe` is kept as a fallback
|
`pkg2zip` needed.
|
||||||
only, and only runs if Python decryption fails and Wine is present.
|
|
||||||
2. Set **NoPayStation output dir** in **Settings → Store** (default
|
2. Set **NoPayStation output dir** in **Settings → Store** (default
|
||||||
`$PSP_STATE_DIR/nps`).
|
`$PSP_STATE_DIR/nps`).
|
||||||
3. Downloads land in the NPS folder and appear in the **Library**:
|
3. Downloads land in the NPS folder and appear in the **Library**:
|
||||||
@@ -316,51 +404,68 @@ Requirements & behaviour:
|
|||||||
|
|
||||||
## Server setup
|
## Server setup
|
||||||
|
|
||||||
The catalog + store API is a single-file, stdlib-only HTTP server
|
The server is a **FastAPI** app (`server/`) with an admin **WebUI** and a
|
||||||
(`app/api.py`) — no pip install needed on the server.
|
JSON API. It owns the catalog, metadata, covers, and the game/video store
|
||||||
|
archives, and serves them to the desktop app. Users log in with a username +
|
||||||
|
password; the app holds a **per-user API token** (roles: `admin`, `editor`,
|
||||||
|
`user`).
|
||||||
|
|
||||||
|
Run it directly (dev):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
PSP_DATA_DIR=/data \
|
pip install -r requirements-server.txt
|
||||||
PSP_DATS_DIR=/data/dats \
|
|
||||||
PSP_DB_PATH=/data/library.sqlite \
|
PSP_DB_PATH=/data/library.sqlite \
|
||||||
PSP_COVERS_DIR=/data/covers \
|
PSP_COVERS_DIR=/data/covers \
|
||||||
PSP_GAMES_ROOTS=/data/umd_games \
|
|
||||||
PSP_VIDEO_ROOTS=/data/umd_videos \
|
|
||||||
PSP_STORE_DIR=/data/store \
|
PSP_STORE_DIR=/data/store \
|
||||||
PSP_API_TOKEN=<long-random-secret> \
|
PSP_STORE_VIDEOS_DIR=/data/store_videos \
|
||||||
python3 -m app.api --host 0.0.0.0 --port 8000
|
PSP_ADMIN_USERNAME=admin \
|
||||||
|
PSP_ADMIN_PASSWORD=<change-me> \
|
||||||
|
uvicorn server.main:app --host 0.0.0.0 --port 8000
|
||||||
```
|
```
|
||||||
|
|
||||||
Endpoints:
|
On first boot it creates the `PSP_ADMIN_USERNAME` account (log in and change
|
||||||
|
the password). The admin WebUI lives at `/`:
|
||||||
|
|
||||||
|
- **Dashboard** — storage, catalog counts, recent downloads.
|
||||||
|
- **Games & Videos** — browse the catalog, edit metadata, upload covers.
|
||||||
|
- **Store** — upload/delete game and video archives.
|
||||||
|
- **Users** — create users, assign roles, reset passwords.
|
||||||
|
|
||||||
|
API endpoints:
|
||||||
|
|
||||||
| Endpoint | Description |
|
| Endpoint | Description |
|
||||||
|---|---|
|
|---|---|
|
||||||
| `GET /api/summary` | release counts per system |
|
| `POST /api/auth/login` | username/password → API token |
|
||||||
|
| `GET /api/auth/me` | current user |
|
||||||
|
| `GET /api/users`, `POST`, `PATCH`, `DELETE` | user management *(admin)* |
|
||||||
| `GET /api/releases?system=&q=&limit=&offset=` | search the catalog |
|
| `GET /api/releases?system=&q=&limit=&offset=` | search the catalog |
|
||||||
| `GET /api/releases/<id>` | one release + its rom hashes |
|
| `GET /api/releases/<id>` | release detail + metadata + rom hashes |
|
||||||
| `GET /api/library?system=&refresh=` | your scanned library |
|
| `PATCH /api/releases/<id>` | edit metadata *(editor+)* |
|
||||||
| `GET /api/cover/<id>` | cover image (fetched on demand) |
|
| `GET /api/cover/<id>` | cover image |
|
||||||
| `GET /api/covers/<name>.zip` | offline cover bundle (public) |
|
| `POST /api/cover/<id>` | upload/replace cover *(editor+)* |
|
||||||
| `GET /api/store` | list store archives *(token)* |
|
| `GET /api/store?system=games|videos` | list store archives |
|
||||||
| `GET /api/store/download/<name>` | stream one archive *(token)* |
|
| `GET /api/store/download/<system>/<name>` | stream an archive *(user+)* |
|
||||||
|
| `POST /api/store/upload`, `DELETE /api/store/<system>/<name>` | manage archives *(editor+)* |
|
||||||
|
| `GET /api/stats` | dashboard numbers *(admin)* |
|
||||||
|
|
||||||
Token protection: set `PSP_API_TOKEN`; the client sends
|
Authentication is `Authorization: Bearer <token>` for the API and a session
|
||||||
`Authorization: Bearer <token>`. Leave it unset to allow anonymous access
|
cookie for the WebUI.
|
||||||
(not recommended).
|
|
||||||
|
|
||||||
### Docker (Unraid)
|
### Docker (Unraid)
|
||||||
|
|
||||||
`docker-compose.yml` builds the API image and attaches it to Unraid's `br0`
|
`docker-compose.yml` builds the server image and attaches it to Unraid's `br0`
|
||||||
macvlan bridge so it gets its own LAN IP (e.g. `192.168.1.100`, plain HTTP on 8000):
|
macvlan bridge so it gets its own LAN IP:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# in /path/to/psp-preserve/ — adjust the volume paths for your shares
|
# in /path/to/psppt/
|
||||||
printf 'PSP_API_TOKEN=<long-random-secret>\n' > .env
|
cp .env.example .env # then edit: LAN IP, share paths, admin password
|
||||||
docker compose up -d --build
|
docker compose up -d --build
|
||||||
```
|
```
|
||||||
|
|
||||||
The compose file mounts your Unraid shares into `/data/store`, `/data/umd_games`
|
The compose file reads the LAN IP and Unraid share paths from `.env` and mounts
|
||||||
and `/data/umd_videos` (the store is mounted read-only).
|
them into `/data/store`, `/data/store_videos`, `/data/umd_games` and
|
||||||
|
`/data/umd_videos` (the store mounts are writable so the WebUI can manage
|
||||||
|
archives).
|
||||||
|
|
||||||
### TLS (optional)
|
### TLS (optional)
|
||||||
|
|
||||||
@@ -371,10 +476,13 @@ ports 80/443 on your router to it.
|
|||||||
|
|
||||||
### Client
|
### Client
|
||||||
|
|
||||||
In the GUI: **Settings → Store** → enter the **Server URL** (e.g.
|
In the GUI: **Settings → Store** → enter the **Server URL**, **Server
|
||||||
`http://<server-ip>:8000` or `https://psp.example.com`) and the same **API
|
username**, and **Server password**, then **Save settings** (the app logs in
|
||||||
token**, then pick **Server** in the Store tab's source selector. Use
|
and stores the per-user token). Pick **Server** in the Store tab's source
|
||||||
**Archive.org** or **Local folder** the same way.
|
selector. When a server is configured it is authoritative for covers and
|
||||||
|
metadata — if it's unreachable the app shows an error instead of falling back
|
||||||
|
to public sources. Use **Archive.org**, **Local folder**, or **NoPayStation**
|
||||||
|
the same way as before.
|
||||||
|
|
||||||
## PSP Sync
|
## PSP Sync
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
"""PSP Preservation Tool application package."""
|
"""psppt application package."""
|
||||||
|
|||||||
+2
-2
@@ -251,7 +251,7 @@ def _library(conn, system=None, refresh=False):
|
|||||||
|
|
||||||
|
|
||||||
class Handler(BaseHTTPRequestHandler):
|
class Handler(BaseHTTPRequestHandler):
|
||||||
server_version = "PSPPreserve/0.1"
|
server_version = "psppt/0.1"
|
||||||
|
|
||||||
def do_GET(self):
|
def do_GET(self):
|
||||||
parsed = urlparse(self.path)
|
parsed = urlparse(self.path)
|
||||||
@@ -262,7 +262,7 @@ class Handler(BaseHTTPRequestHandler):
|
|||||||
try:
|
try:
|
||||||
if path == "/":
|
if path == "/":
|
||||||
_json(self, {
|
_json(self, {
|
||||||
"name": "PSP Preservation Tool API",
|
"name": "psppt API",
|
||||||
"endpoints": [
|
"endpoints": [
|
||||||
"/api/summary",
|
"/api/summary",
|
||||||
"/api/releases?system=games|videos&q=&limit=&offset=",
|
"/api/releases?system=games|videos&q=&limit=&offset=",
|
||||||
|
|||||||
+56
-9
@@ -1,8 +1,33 @@
|
|||||||
"""Central configuration, driven by environment variables."""
|
"""Central configuration, driven by environment variables."""
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
PROJECT_ROOT = Path(__file__).resolve().parent.parent
|
# PyInstaller sets ``sys.frozen`` and unpacks bundled files to ``sys._MEIPASS``.
|
||||||
|
# Read-only resources (DATs, loader, icons) then live in the bundle; otherwise
|
||||||
|
# they live in the project checkout.
|
||||||
|
IS_FROZEN = getattr(sys, "frozen", False)
|
||||||
|
_BUNDLE_DIR = getattr(sys, "_MEIPASS", None)
|
||||||
|
|
||||||
|
PROJECT_ROOT = Path(_BUNDLE_DIR).resolve() if _BUNDLE_DIR else Path(__file__).resolve().parent.parent
|
||||||
|
|
||||||
|
# Frozen bundles don't ship the system CA store, so Python's urllib would fail
|
||||||
|
# TLS verification against the store server / NoPayStation / TMDB / archive.org.
|
||||||
|
# Point OpenSSL at the certifi bundle (a curl_cffi dependency) when frozen only;
|
||||||
|
# source runs keep using the OS CA store.
|
||||||
|
if IS_FROZEN:
|
||||||
|
try:
|
||||||
|
import certifi
|
||||||
|
_CA_BUNDLE = certifi.where()
|
||||||
|
os.environ.setdefault("SSL_CERT_FILE", _CA_BUNDLE)
|
||||||
|
os.environ.setdefault("REQUESTS_CA_BUNDLE", _CA_BUNDLE)
|
||||||
|
except Exception: # noqa: BLE001
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def resource_path(*parts):
|
||||||
|
"""Absolute path to a read-only bundled resource (works when frozen)."""
|
||||||
|
return PROJECT_ROOT.joinpath(*parts)
|
||||||
|
|
||||||
DATA_DIR = Path(os.environ.get("PSP_DATA_DIR", str(PROJECT_ROOT / "data")))
|
DATA_DIR = Path(os.environ.get("PSP_DATA_DIR", str(PROJECT_ROOT / "data")))
|
||||||
DATS_DIR = Path(os.environ.get("PSP_DATS_DIR", str(DATA_DIR / "dats")))
|
DATS_DIR = Path(os.environ.get("PSP_DATS_DIR", str(DATA_DIR / "dats")))
|
||||||
@@ -12,25 +37,38 @@ def _default_state_dir():
|
|||||||
"""Local state directory (fast, reliable local disk).
|
"""Local state directory (fast, reliable local disk).
|
||||||
|
|
||||||
SQLite locking is unreliable over network filesystems (SMB/FUSE), so the
|
SQLite locking is unreliable over network filesystems (SMB/FUSE), so the
|
||||||
library DB and the cover cache live on local storage while DATs, manual
|
library DB and the cover cache live on local storage while read-only DATs
|
||||||
covers and credentials stay in ``DATA_DIR`` (which may be a network share).
|
stay bundled with the app.
|
||||||
"""
|
"""
|
||||||
|
if os.name == "nt":
|
||||||
|
base = os.environ.get("LOCALAPPDATA") or os.environ.get("APPDATA") or str(Path.home())
|
||||||
|
return Path(base) / "psppt"
|
||||||
xdg = os.environ.get("XDG_STATE_HOME")
|
xdg = os.environ.get("XDG_STATE_HOME")
|
||||||
base = Path(xdg) if xdg else Path.home() / ".local" / "state"
|
base = Path(xdg) if xdg else Path.home() / ".local" / "state"
|
||||||
return base / "psp-preserve"
|
return base / "psppt"
|
||||||
|
|
||||||
|
|
||||||
STATE_DIR = Path(os.environ.get("PSP_STATE_DIR", str(_default_state_dir())))
|
STATE_DIR = Path(os.environ.get("PSP_STATE_DIR", str(_default_state_dir())))
|
||||||
DB_PATH = Path(os.environ.get("PSP_DB_PATH", str(STATE_DIR / "library.sqlite")))
|
DB_PATH = Path(os.environ.get("PSP_DB_PATH", str(STATE_DIR / "library.sqlite")))
|
||||||
COVERS_DIR = Path(os.environ.get("PSP_COVERS_DIR", str(STATE_DIR / "covers")))
|
COVERS_DIR = Path(os.environ.get("PSP_COVERS_DIR", str(STATE_DIR / "covers")))
|
||||||
|
# User-writable data (credentials, manual covers, PS1 templates, NPS TSV cache).
|
||||||
|
# In dev this is the checkout's ``data/``; when frozen the bundle is read-only,
|
||||||
|
# so it points at local state that survives app upgrades.
|
||||||
|
USER_DATA_DIR = Path(os.environ.get(
|
||||||
|
"PSP_USER_DATA_DIR", str(DATA_DIR if not IS_FROZEN else STATE_DIR / "data")))
|
||||||
LEGACY_DB_PATH = DATA_DIR / "library.sqlite"
|
LEGACY_DB_PATH = DATA_DIR / "library.sqlite"
|
||||||
LEGACY_COVERS_DIR = DATA_DIR / "covers"
|
LEGACY_COVERS_DIR = DATA_DIR / "covers"
|
||||||
|
|
||||||
|
|
||||||
|
def user_data_path(*parts):
|
||||||
|
"""Absolute path to a user-writable data file/folder (works when frozen)."""
|
||||||
|
return USER_DATA_DIR.joinpath(*parts)
|
||||||
|
|
||||||
# Redump 7z store (browsable in the Store tab). Env override; GUI setting wins.
|
# Redump 7z store (browsable in the Store tab). Env override; GUI setting wins.
|
||||||
STORE_ROOT = Path(os.environ.get("PSP_STORE_DIR", "/media/downloads/Sony - PlayStation Portable"))
|
STORE_ROOT = Path(os.environ.get("PSP_STORE_DIR", "/data/store"))
|
||||||
|
|
||||||
# Remote store server (HTTPS). Used by the Store tab as the primary source.
|
# Remote store server (HTTPS). Used by the Store tab as the primary source.
|
||||||
STORE_SERVER_URL = os.environ.get("PSP_STORE_SERVER", "https://psp.ceaf.dev")
|
STORE_SERVER_URL = os.environ.get("PSP_STORE_SERVER", "https://psp.example.com")
|
||||||
STORE_TOKEN = os.environ.get("PSP_STORE_TOKEN", "")
|
STORE_TOKEN = os.environ.get("PSP_STORE_TOKEN", "")
|
||||||
|
|
||||||
# Optional direct URLs for the offline cover bundle zips. When unset, the GUI
|
# Optional direct URLs for the offline cover bundle zips. When unset, the GUI
|
||||||
@@ -38,9 +76,21 @@ STORE_TOKEN = os.environ.get("PSP_STORE_TOKEN", "")
|
|||||||
LIBRETRO_COVERS_URL = os.environ.get("PSP_LIBRETRO_COVERS_URL", "")
|
LIBRETRO_COVERS_URL = os.environ.get("PSP_LIBRETRO_COVERS_URL", "")
|
||||||
OVGDB_COVERS_URL = os.environ.get("PSP_OVGDB_COVERS_URL", "")
|
OVGDB_COVERS_URL = os.environ.get("PSP_OVGDB_COVERS_URL", "")
|
||||||
|
|
||||||
|
# Combined offline cover bundle (both inner zips) fetched on first run when the
|
||||||
|
# user opts in. Defaults to the project's Gitea release asset.
|
||||||
|
COVERS_BUNDLE_URL = os.environ.get(
|
||||||
|
"PSP_COVERS_BUNDLE_URL",
|
||||||
|
"https://git.ceaf.dev/quoije/psp-preservation-tool/releases/download/covers/psppt-covers.zip",
|
||||||
|
)
|
||||||
|
|
||||||
# archive.org item hosting the same Redump 7z set (identifier or full URL).
|
# archive.org item hosting the same Redump 7z set (identifier or full URL).
|
||||||
ARCHIVE_ITEM = os.environ.get("PSP_ARCHIVE_ITEM", "psp-redump-roms321.com")
|
ARCHIVE_ITEM = os.environ.get("PSP_ARCHIVE_ITEM", "psp-redump-roms321.com")
|
||||||
|
|
||||||
|
# UMD video store: a second archive root (mirrors STORE_ROOT) and the
|
||||||
|
# archive.org item hosting UMD video rips.
|
||||||
|
STORE_VIDEOS_ROOT = Path(os.environ.get("PSP_STORE_VIDEOS_DIR", "/data/store_videos"))
|
||||||
|
ARCHIVE_VIDEOS_ITEM = os.environ.get("PSP_ARCHIVE_VIDEOS_ITEM", "the-psp-movie-collection-so-far_202607")
|
||||||
|
|
||||||
# Optional archive.org login cookies (for items whose files are "private" /
|
# Optional archive.org login cookies (for items whose files are "private" /
|
||||||
# login-required). Grab these from a logged-in browser session on archive.org.
|
# login-required). Grab these from a logged-in browser session on archive.org.
|
||||||
ARCHIVE_LOGGED_IN_SIG = os.environ.get("PSP_ARCHIVE_LOGGED_IN_SIG", "")
|
ARCHIVE_LOGGED_IN_SIG = os.environ.get("PSP_ARCHIVE_LOGGED_IN_SIG", "")
|
||||||
@@ -51,9 +101,6 @@ ARCHIVE_LOGGED_IN_USER = os.environ.get("PSP_ARCHIVE_LOGGED_IN_USER", "")
|
|||||||
NPS_OUTPUT_DIR = Path(os.environ.get("PSP_NPS_DIR", str(STATE_DIR / "nps")))
|
NPS_OUTPUT_DIR = Path(os.environ.get("PSP_NPS_DIR", str(STATE_DIR / "nps")))
|
||||||
NPS_TSV_BASE = os.environ.get("PSP_NPS_TSV_BASE", "https://nopaystation.com/tsv/")
|
NPS_TSV_BASE = os.environ.get("PSP_NPS_TSV_BASE", "https://nopaystation.com/tsv/")
|
||||||
|
|
||||||
# pkg2zip binary used to decrypt/extract NPS .pkg files (blank = auto-detect).
|
|
||||||
PKG2ZIP_PATH = os.environ.get("PSP_PKG2ZIP_PATH", "")
|
|
||||||
|
|
||||||
# Scan roots (used by the scanner phase). Comma-separated in env.
|
# Scan roots (used by the scanner phase). Comma-separated in env.
|
||||||
GAMES_ROOTS = [Path(p) for p in os.environ.get("PSP_GAMES_ROOTS", "/data/umd_games").split(",") if p.strip()]
|
GAMES_ROOTS = [Path(p) for p in os.environ.get("PSP_GAMES_ROOTS", "/data/umd_games").split(",") if p.strip()]
|
||||||
VIDEO_ROOTS = [Path(p) for p in os.environ.get("PSP_VIDEO_ROOTS", "/data/umd_videos").split(",") if p.strip()]
|
VIDEO_ROOTS = [Path(p) for p in os.environ.get("PSP_VIDEO_ROOTS", "/data/umd_videos").split(",") if p.strip()]
|
||||||
|
|||||||
+129
-56
@@ -19,7 +19,7 @@ import urllib.request
|
|||||||
import zipfile
|
import zipfile
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from . import config, sources
|
from . import config, server_client, sources
|
||||||
from .db import get_connection
|
from .db import get_connection
|
||||||
|
|
||||||
log = logging.getLogger("covers")
|
log = logging.getLogger("covers")
|
||||||
@@ -52,9 +52,21 @@ _IGDB_IMAGE = "https://images.igdb.com/igdb/image/upload/"
|
|||||||
_TMDB_SEARCH = "https://api.themoviedb.org/3/search/movie"
|
_TMDB_SEARCH = "https://api.themoviedb.org/3/search/movie"
|
||||||
_TMDB_IMAGE = "https://image.tmdb.org/t/p/"
|
_TMDB_IMAGE = "https://image.tmdb.org/t/p/"
|
||||||
_GOOGLE_CSE_API = "https://www.googleapis.com/customsearch/v1"
|
_GOOGLE_CSE_API = "https://www.googleapis.com/customsearch/v1"
|
||||||
_MANUAL_DIR = config.DATA_DIR / "manual_covers"
|
_MANUAL_DIR = config.USER_DATA_DIR / "manual_covers"
|
||||||
_OVGDB_ZIP = config.DATA_DIR / "covers" / "openvgdb-covers.zip"
|
# Offline cover bundles live in the writable cover dir (downloaded on demand),
|
||||||
_LIBRETRO_ZIP = config.DATA_DIR / "covers" / "libretro-covers.zip"
|
# not the read-only app bundle. A source checkout keeps them in data/covers/.
|
||||||
|
_OVGDB_ZIP = config.COVERS_DIR / "openvgdb-covers.zip"
|
||||||
|
_LIBRETRO_ZIP = config.COVERS_DIR / "libretro-covers.zip"
|
||||||
|
_BUNDLE_ZIP = config.COVERS_DIR / "psppt-covers.zip"
|
||||||
|
|
||||||
|
|
||||||
|
def _bundle_zip_path(name):
|
||||||
|
"""Resolve a cover bundle zip: writable dir first, legacy checkout second."""
|
||||||
|
for base in (config.COVERS_DIR, config.LEGACY_COVERS_DIR):
|
||||||
|
p = base / name
|
||||||
|
if p.exists():
|
||||||
|
return p
|
||||||
|
return config.COVERS_DIR / name
|
||||||
|
|
||||||
_WIKI_SEARCH = "https://en.wikipedia.org/w/api.php"
|
_WIKI_SEARCH = "https://en.wikipedia.org/w/api.php"
|
||||||
_WIKI_SUMMARY = "https://en.wikipedia.org/api/rest_v1/page/summary/"
|
_WIKI_SUMMARY = "https://en.wikipedia.org/api/rest_v1/page/summary/"
|
||||||
@@ -62,7 +74,7 @@ _WIKI_SUMMARY = "https://en.wikipedia.org/api/rest_v1/page/summary/"
|
|||||||
_PNG_MAGIC = b"\x89PNG\r\n\x1a\n"
|
_PNG_MAGIC = b"\x89PNG\r\n\x1a\n"
|
||||||
_JPEG_MAGIC = b"\xff\xd8\xff"
|
_JPEG_MAGIC = b"\xff\xd8\xff"
|
||||||
_MAX_HOPS = 3 # follow libretro symlink text bodies at most this many times
|
_MAX_HOPS = 3 # follow libretro symlink text bodies at most this many times
|
||||||
_UA = {"User-Agent": "psp-preserve/0.1 (https://github.com; local tool)"}
|
_UA = {"User-Agent": "psppt/0.1 (https://github.com; local tool)"}
|
||||||
_igdb_token_state = {"token": "", "expires": 0.0} # IGDB OAuth2 token cache
|
_igdb_token_state = {"token": "", "expires": 0.0} # IGDB OAuth2 token cache
|
||||||
_igdb_lock = threading.Lock()
|
_igdb_lock = threading.Lock()
|
||||||
_igdb_last = 0.0 # monotonic clock of the last IGDB API call
|
_igdb_last = 0.0 # monotonic clock of the last IGDB API call
|
||||||
@@ -158,48 +170,74 @@ def clear_cover_cache():
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def _download_file(url, dest, timeout=600):
|
def _download_file(url, dest, timeout=600, progress_cb=None, cancel_event=None):
|
||||||
"""Stream `url` to `dest` (atomic); returns True on success."""
|
"""Stream `url` to `dest` (atomic); returns True on success.
|
||||||
|
|
||||||
|
``progress_cb(done, total)`` is called with bytes so far (total is 0 when
|
||||||
|
the server doesn't report a content length). ``cancel_event`` aborts the
|
||||||
|
download when set.
|
||||||
|
"""
|
||||||
req = urllib.request.Request(url, headers=_UA)
|
req = urllib.request.Request(url, headers=_UA)
|
||||||
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
||||||
if resp.status != 200:
|
if resp.status != 200:
|
||||||
return False
|
return False
|
||||||
|
total = int(resp.headers.get("Content-Length") or 0)
|
||||||
tmp = dest.with_name(dest.name + ".tmp")
|
tmp = dest.with_name(dest.name + ".tmp")
|
||||||
|
done = 0
|
||||||
with open(tmp, "wb") as f:
|
with open(tmp, "wb") as f:
|
||||||
while True:
|
while True:
|
||||||
|
if cancel_event is not None and cancel_event.is_set():
|
||||||
|
raise InterruptedError("download cancelled")
|
||||||
chunk = resp.read(1 << 20)
|
chunk = resp.read(1 << 20)
|
||||||
if not chunk:
|
if not chunk:
|
||||||
break
|
break
|
||||||
f.write(chunk)
|
f.write(chunk)
|
||||||
|
done += len(chunk)
|
||||||
|
if progress_cb is not None:
|
||||||
|
progress_cb(done, total)
|
||||||
os.replace(tmp, dest)
|
os.replace(tmp, dest)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def ensure_cover_bundles(server_url=""):
|
def covers_bundle_present():
|
||||||
"""Download missing offline cover bundle zips from the store server.
|
"""True when the offline cover bundle is installed (both inner zips)."""
|
||||||
|
return (_bundle_zip_path("libretro-covers.zip").exists()
|
||||||
|
and _bundle_zip_path("openvgdb-covers.zip").exists())
|
||||||
|
|
||||||
``server_url`` is the base URL (e.g. ``http://192.168.10.100:8000``); the
|
|
||||||
zips are fetched from ``<base>/api/covers/<name>.zip`` unless a direct URL
|
def download_covers_bundle(url=None, progress_cb=None, cancel_event=None):
|
||||||
is set in config. Returns the names of bundles downloaded.
|
"""Download and extract the combined cover bundle into the cover dir.
|
||||||
|
|
||||||
|
``url`` defaults to ``config.COVERS_BUNDLE_URL``. Raises on failure; the
|
||||||
|
caller decides whether to surface the error.
|
||||||
"""
|
"""
|
||||||
base = (server_url or config.STORE_SERVER_URL or "").rstrip("/")
|
url = (url or config.COVERS_BUNDLE_URL or "").strip()
|
||||||
downloaded = []
|
if not url:
|
||||||
for name, path, direct in (
|
raise ValueError("no cover bundle URL configured")
|
||||||
("libretro-covers.zip", _LIBRETRO_ZIP, config.LIBRETRO_COVERS_URL),
|
config.COVERS_DIR.mkdir(parents=True, exist_ok=True)
|
||||||
("openvgdb-covers.zip", _OVGDB_ZIP, config.OVGDB_COVERS_URL),
|
_download_file(url, _BUNDLE_ZIP, timeout=3600,
|
||||||
):
|
progress_cb=progress_cb, cancel_event=cancel_event)
|
||||||
if path.exists():
|
inner = ("libretro-covers.zip", "openvgdb-covers.zip")
|
||||||
continue
|
with zipfile.ZipFile(_BUNDLE_ZIP) as z:
|
||||||
url = direct or (f"{base}/api/covers/{name}" if base else "")
|
missing = [n for n in inner if n not in z.namelist()]
|
||||||
if not url:
|
if missing:
|
||||||
continue
|
raise ValueError(f"cover bundle is missing: {', '.join(missing)}")
|
||||||
try:
|
with zipfile.ZipFile(_BUNDLE_ZIP) as z:
|
||||||
if _download_file(url, path):
|
for name in inner:
|
||||||
downloaded.append(name)
|
out = config.COVERS_DIR / name
|
||||||
log.info("downloaded offline cover bundle %s", name)
|
tmp = out.with_name(out.name + ".tmp")
|
||||||
except Exception as exc: # noqa: BLE001
|
with z.open(name) as src, open(tmp, "wb") as dst:
|
||||||
log.warning("could not download cover bundle %s: %s", name, exc)
|
while True:
|
||||||
return downloaded
|
chunk = src.read(1 << 20)
|
||||||
|
if not chunk:
|
||||||
|
break
|
||||||
|
dst.write(chunk)
|
||||||
|
os.replace(tmp, out)
|
||||||
|
# Invalidate cached namelists so lookups pick up the freshly extracted zips.
|
||||||
|
global _libretro_names, _ovgdb_names
|
||||||
|
_libretro_names = None
|
||||||
|
_ovgdb_names = None
|
||||||
|
return config.COVERS_DIR
|
||||||
|
|
||||||
|
|
||||||
def cover_url(name, kind="Named_Boxarts", system="games"):
|
def cover_url(name, kind="Named_Boxarts", system="games"):
|
||||||
@@ -411,6 +449,9 @@ def _fetch_libretro(name, timeout, system="games", indexed_only=False):
|
|||||||
data = fetch_libretro_local(name)
|
data = fetch_libretro_local(name)
|
||||||
if data is not None:
|
if data is not None:
|
||||||
return data
|
return data
|
||||||
|
# Theme/DLC share the PSP thumbnails repo, so reuse the games index instead
|
||||||
|
# of downloading a duplicate copy of the same tree under a new system key.
|
||||||
|
idx_system = system if system in _PLATFORMS else "games"
|
||||||
if not indexed_only:
|
if not indexed_only:
|
||||||
# 1. Cheap: exact + progressively stripped names (no index needed).
|
# 1. Cheap: exact + progressively stripped names (no index needed).
|
||||||
for kind in _LIBRETRO_KINDS:
|
for kind in _LIBRETRO_KINDS:
|
||||||
@@ -421,7 +462,7 @@ def _fetch_libretro(name, timeout, system="games", indexed_only=False):
|
|||||||
# 2. Fuzzy/exact via the precomputed index (covers exact names too, so the
|
# 2. Fuzzy/exact via the precomputed index (covers exact names too, so the
|
||||||
# bulk loader skips the wasteful exact pass entirely).
|
# bulk loader skips the wasteful exact pass entirely).
|
||||||
for kind in _LIBRETRO_KINDS:
|
for kind in _LIBRETRO_KINDS:
|
||||||
best = _index_best(name, kind, system)
|
best = _index_best(name, kind, idx_system)
|
||||||
if best:
|
if best:
|
||||||
data = _fetch_png(best, kind, timeout, system)
|
data = _fetch_png(best, kind, timeout, system)
|
||||||
if data is not None:
|
if data is not None:
|
||||||
@@ -479,9 +520,10 @@ def _ovgdb_name_list():
|
|||||||
global _ovgdb_names
|
global _ovgdb_names
|
||||||
if _ovgdb_names is None:
|
if _ovgdb_names is None:
|
||||||
_ovgdb_names = set()
|
_ovgdb_names = set()
|
||||||
if _OVGDB_ZIP.exists():
|
path = _bundle_zip_path("openvgdb-covers.zip")
|
||||||
|
if path.exists():
|
||||||
try:
|
try:
|
||||||
with zipfile.ZipFile(_OVGDB_ZIP) as z:
|
with zipfile.ZipFile(path) as z:
|
||||||
_ovgdb_names = {n[:-4] for n in z.namelist() if n.endswith(".jpg")}
|
_ovgdb_names = {n[:-4] for n in z.namelist() if n.endswith(".jpg")}
|
||||||
except Exception: # noqa: BLE001
|
except Exception: # noqa: BLE001
|
||||||
pass
|
pass
|
||||||
@@ -532,7 +574,7 @@ def fetch_openvgdb_local(name):
|
|||||||
if entry is None:
|
if entry is None:
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
with zipfile.ZipFile(_OVGDB_ZIP) as z:
|
with zipfile.ZipFile(_bundle_zip_path("openvgdb-covers.zip")) as z:
|
||||||
data = z.read(entry)
|
data = z.read(entry)
|
||||||
return data if _is_image(data) else None
|
return data if _is_image(data) else None
|
||||||
except Exception: # noqa: BLE001
|
except Exception: # noqa: BLE001
|
||||||
@@ -556,7 +598,7 @@ def fetch_libretro_local(name):
|
|||||||
if entry is None:
|
if entry is None:
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
with zipfile.ZipFile(_LIBRETRO_ZIP) as z:
|
with zipfile.ZipFile(_bundle_zip_path("libretro-covers.zip")) as z:
|
||||||
data = z.read(entry)
|
data = z.read(entry)
|
||||||
return data if _is_image(data) else None
|
return data if _is_image(data) else None
|
||||||
except Exception: # noqa: BLE001
|
except Exception: # noqa: BLE001
|
||||||
@@ -567,9 +609,10 @@ def _libretro_name_list():
|
|||||||
global _libretro_names
|
global _libretro_names
|
||||||
if _libretro_names is None:
|
if _libretro_names is None:
|
||||||
_libretro_names = set()
|
_libretro_names = set()
|
||||||
if _LIBRETRO_ZIP.exists():
|
path = _bundle_zip_path("libretro-covers.zip")
|
||||||
|
if path.exists():
|
||||||
try:
|
try:
|
||||||
with zipfile.ZipFile(_LIBRETRO_ZIP) as z:
|
with zipfile.ZipFile(path) as z:
|
||||||
_libretro_names = {n[:-4] for n in z.namelist() if n.endswith(".png")}
|
_libretro_names = {n[:-4] for n in z.namelist() if n.endswith(".png")}
|
||||||
except Exception: # noqa: BLE001
|
except Exception: # noqa: BLE001
|
||||||
pass
|
pass
|
||||||
@@ -607,7 +650,7 @@ def _fetch_screenscraper(name, timeout, system="games"):
|
|||||||
params = {
|
params = {
|
||||||
"devid": devid,
|
"devid": devid,
|
||||||
"devpassword": devpassword,
|
"devpassword": devpassword,
|
||||||
"softname": creds.get("screenscraper_softname") or "psp-preserve",
|
"softname": creds.get("screenscraper_softname") or "psppt",
|
||||||
"output": "json",
|
"output": "json",
|
||||||
"systemeid": _platform(system)["ss_id"],
|
"systemeid": _platform(system)["ss_id"],
|
||||||
"romtype": "rom",
|
"romtype": "rom",
|
||||||
@@ -808,7 +851,7 @@ def compose_game_cover(key_art_bytes):
|
|||||||
return bytes(ba)
|
return bytes(ba)
|
||||||
|
|
||||||
|
|
||||||
_PS1_TEMPLATE_DIR = config.DATA_DIR / "ps1_templates"
|
_PS1_TEMPLATE_DIR = config.USER_DATA_DIR / "ps1_templates"
|
||||||
|
|
||||||
|
|
||||||
def _ps1_template_bytes(name):
|
def _ps1_template_bytes(name):
|
||||||
@@ -934,25 +977,28 @@ def _make_pic0(title, description, esrb, QImage, QPainter, QPainterPath, QColor,
|
|||||||
QRectF, Qt, _save):
|
QRectF, Qt, _save):
|
||||||
W, H = 310, 180
|
W, H = 310, 180
|
||||||
img = QImage(W, H, QImage.Format_ARGB32)
|
img = QImage(W, H, QImage.Format_ARGB32)
|
||||||
|
img.fill(QColor(0, 0, 0, 0))
|
||||||
|
|
||||||
# Dark gradient backdrop.
|
# Dark gradient backdrop clipped to a rounded card (transparent corners).
|
||||||
grad = QLinearGradient(0, 0, 0, H)
|
grad = QLinearGradient(0, 0, 0, H)
|
||||||
grad.setColorAt(0.0, QColor(38, 38, 40))
|
grad.setColorAt(0.0, QColor(38, 38, 40))
|
||||||
grad.setColorAt(1.0, QColor(12, 12, 14))
|
grad.setColorAt(1.0, QColor(12, 12, 14))
|
||||||
|
card = QPainterPath()
|
||||||
|
card.addRoundedRect(QRectF(0, 0, W, H), 12, 12)
|
||||||
|
|
||||||
p = QPainter(img)
|
p = QPainter(img)
|
||||||
p.setRenderHint(QPainter.Antialiasing, True)
|
p.setRenderHint(QPainter.Antialiasing, True)
|
||||||
p.setRenderHint(QPainter.TextAntialiasing, True)
|
p.setRenderHint(QPainter.TextAntialiasing, True)
|
||||||
p.fillRect(0, 0, W, H, grad)
|
p.fillPath(card, grad)
|
||||||
|
|
||||||
# Rounded border.
|
# Rounded card border.
|
||||||
p.setPen(QPen(QColor(110, 110, 115), 1))
|
p.setPen(QPen(QColor(110, 110, 115), 1))
|
||||||
p.setBrush(Qt.NoBrush)
|
p.setBrush(Qt.NoBrush)
|
||||||
p.drawRoundedRect(QRectF(4, 4, W - 8, H - 8), 9, 9)
|
p.drawPath(card)
|
||||||
|
|
||||||
# PlayStation button glyphs, top-right.
|
# PlayStation button glyphs, top-right.
|
||||||
_draw_ps_glyphs(p, W - 34, 12, 22, QColor(200, 200, 205), QRectF, QPointF,
|
_draw_ps_glyphs(p, W - 34, 12, 22, QRectF, QPointF, QPolygonF, QPen, Qt,
|
||||||
QPolygonF, QPen, Qt)
|
QColor)
|
||||||
|
|
||||||
# Title (bold, upper-left). Shrink the font until the whole title fits, so
|
# Title (bold, upper-left). Shrink the font until the whole title fits, so
|
||||||
# long names are shown in full instead of being cut with an ellipsis.
|
# long names are shown in full instead of being cut with an ellipsis.
|
||||||
@@ -974,6 +1020,10 @@ def _make_pic0(title, description, esrb, QImage, QPainter, QPainterPath, QColor,
|
|||||||
p.drawText(QRectF(18, 16, title_width, 28), Qt.AlignLeft | Qt.AlignVCenter,
|
p.drawText(QRectF(18, 16, title_width, 28), Qt.AlignLeft | Qt.AlignVCenter,
|
||||||
title_text)
|
title_text)
|
||||||
|
|
||||||
|
# Thin divider under the title (like the original PSN info board).
|
||||||
|
p.setPen(QPen(QColor(255, 255, 255, 55), 1))
|
||||||
|
p.drawLine(QPointF(18, 46), QPointF(W - 18, 46))
|
||||||
|
|
||||||
# Description (wrapped to at most 3 lines, last line elided).
|
# Description (wrapped to at most 3 lines, last line elided).
|
||||||
if description:
|
if description:
|
||||||
f_desc = QFont("DejaVu Sans")
|
f_desc = QFont("DejaVu Sans")
|
||||||
@@ -982,7 +1032,7 @@ def _make_pic0(title, description, esrb, QImage, QPainter, QPainterPath, QColor,
|
|||||||
p.setPen(QColor(215, 215, 215))
|
p.setPen(QColor(215, 215, 215))
|
||||||
fm = QFontMetrics(f_desc)
|
fm = QFontMetrics(f_desc)
|
||||||
lines = _wrap_elided(fm, description.strip(), W - 36, 3, Qt)
|
lines = _wrap_elided(fm, description.strip(), W - 36, 3, Qt)
|
||||||
y = 46
|
y = 52
|
||||||
for line in lines:
|
for line in lines:
|
||||||
p.drawText(QRectF(18, y, W - 36, 16), Qt.AlignLeft | Qt.AlignVCenter, line)
|
p.drawText(QRectF(18, y, W - 36, 16), Qt.AlignLeft | Qt.AlignVCenter, line)
|
||||||
y += 16
|
y += 16
|
||||||
@@ -1024,23 +1074,31 @@ def _wrap_elided(fm, text, width, max_lines, Qt):
|
|||||||
return lines[:max_lines]
|
return lines[:max_lines]
|
||||||
|
|
||||||
|
|
||||||
def _draw_ps_glyphs(p, x, y, size, color, QRectF, QPointF, QPolygonF, QPen, Qt):
|
def _draw_ps_glyphs(p, x, y, size, QRectF, QPointF, QPolygonF, QPen, Qt, QColor):
|
||||||
"""Draw the four PlayStation face-button glyphs in a 2x2 grid."""
|
"""Draw the four PlayStation face-button glyphs in a 2x2 grid, using the
|
||||||
|
official button colours (green triangle, red circle, blue cross, pink square)."""
|
||||||
cell = size / 2.0
|
cell = size / 2.0
|
||||||
pen = QPen(color, max(1.0, size / 14.0))
|
|
||||||
pen.setCapStyle(Qt.RoundCap)
|
|
||||||
pen.setJoinStyle(Qt.RoundJoin)
|
|
||||||
p.setPen(pen)
|
|
||||||
p.setBrush(Qt.NoBrush)
|
p.setBrush(Qt.NoBrush)
|
||||||
# Triangle (top-left).
|
|
||||||
|
def _pen(color):
|
||||||
|
pen = QPen(color, max(1.0, size / 14.0))
|
||||||
|
pen.setCapStyle(Qt.RoundCap)
|
||||||
|
pen.setJoinStyle(Qt.RoundJoin)
|
||||||
|
return pen
|
||||||
|
|
||||||
|
# Triangle (top-left, green).
|
||||||
|
p.setPen(_pen(QColor("#3F9B0F")))
|
||||||
tri = QPolygonF([QPointF(x, y + cell), QPointF(x + cell, y), QPointF(x + cell, y + cell)])
|
tri = QPolygonF([QPointF(x, y + cell), QPointF(x + cell, y), QPointF(x + cell, y + cell)])
|
||||||
p.drawPolygon(tri)
|
p.drawPolygon(tri)
|
||||||
# Circle (top-right).
|
# Circle (top-right, red).
|
||||||
|
p.setPen(_pen(QColor("#DE1C18")))
|
||||||
p.drawEllipse(QRectF(x + cell, y, cell, cell))
|
p.drawEllipse(QRectF(x + cell, y, cell, cell))
|
||||||
# Cross (bottom-left).
|
# Cross (bottom-left, blue).
|
||||||
|
p.setPen(_pen(QColor("#287FC1")))
|
||||||
p.drawLine(QPointF(x + 1, y + cell + 1), QPointF(x + cell - 1, y + size - 1))
|
p.drawLine(QPointF(x + 1, y + cell + 1), QPointF(x + cell - 1, y + size - 1))
|
||||||
p.drawLine(QPointF(x + cell - 1, y + cell + 1), QPointF(x + 1, y + size - 1))
|
p.drawLine(QPointF(x + cell - 1, y + cell + 1), QPointF(x + 1, y + size - 1))
|
||||||
# Square (bottom-right).
|
# Square (bottom-right, pink).
|
||||||
|
p.setPen(_pen(QColor("#C94E9B")))
|
||||||
p.drawRect(QRectF(x + cell, y + cell, cell, cell))
|
p.drawRect(QRectF(x + cell, y + cell, cell, cell))
|
||||||
|
|
||||||
|
|
||||||
@@ -1162,6 +1220,21 @@ def fetch_cover(name, release_id, system, timeout=10, quick=False):
|
|||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# Server is authoritative for game/video covers when configured — no
|
||||||
|
# libretro/IGDB fallback; if the server is unreachable the cover just
|
||||||
|
# stays empty. PS1/theme art stays client-side (the server catalog only
|
||||||
|
# covers games and videos).
|
||||||
|
if server_client.configured() and system in ("games", "videos"):
|
||||||
|
try:
|
||||||
|
data = server_client.fetch_cover(system, name)
|
||||||
|
except Exception as exc: # noqa: BLE001
|
||||||
|
log.warning("server cover fetch failed for %r: %s", name, exc)
|
||||||
|
return None
|
||||||
|
if data is not None and _is_image(data):
|
||||||
|
_write_atomic(dest, data)
|
||||||
|
return dest
|
||||||
|
return None
|
||||||
|
|
||||||
key = str(release_id)
|
key = str(release_id)
|
||||||
# In-memory + persistent negative caches: skip the network for recent misses.
|
# In-memory + persistent negative caches: skip the network for recent misses.
|
||||||
last = _neg_cache.get(key)
|
last = _neg_cache.get(key)
|
||||||
|
|||||||
@@ -115,6 +115,37 @@ CREATE TABLE IF NOT EXISTS ps1_entries (
|
|||||||
error TEXT,
|
error TEXT,
|
||||||
updated_at TEXT NOT NULL
|
updated_at TEXT NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
username TEXT NOT NULL UNIQUE,
|
||||||
|
password_hash TEXT NOT NULL,
|
||||||
|
role TEXT NOT NULL DEFAULT 'user', -- admin / editor / user
|
||||||
|
is_active INTEGER NOT NULL DEFAULT 1,
|
||||||
|
created_at TEXT NOT NULL,
|
||||||
|
last_login_at TEXT
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS api_tokens (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
token_hash TEXT NOT NULL UNIQUE,
|
||||||
|
label TEXT,
|
||||||
|
kind TEXT NOT NULL DEFAULT 'api', -- api / session
|
||||||
|
created_at TEXT NOT NULL,
|
||||||
|
last_used_at TEXT,
|
||||||
|
expires_at TEXT,
|
||||||
|
revoked_at TEXT
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS download_events (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
user_id INTEGER REFERENCES users(id) ON DELETE SET NULL,
|
||||||
|
system TEXT NOT NULL,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
bytes INTEGER NOT NULL DEFAULT 0,
|
||||||
|
created_at TEXT NOT NULL
|
||||||
|
);
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+871
-220
File diff suppressed because it is too large
Load Diff
+16
-1
@@ -12,7 +12,7 @@ import json
|
|||||||
import sqlite3
|
import sqlite3
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from . import config, covers
|
from . import config, covers, server_client
|
||||||
from .db import get_connection
|
from .db import get_connection
|
||||||
|
|
||||||
_failed = {} # (release_id, system) -> time.time() of last failed fetch
|
_failed = {} # (release_id, system) -> time.time() of last failed fetch
|
||||||
@@ -199,6 +199,21 @@ def get_or_fetch(release_id, system, fetch_title):
|
|||||||
info = load(release_id, system)
|
info = load(release_id, system)
|
||||||
if info is not None:
|
if info is not None:
|
||||||
return info
|
return info
|
||||||
|
# Server is authoritative for game/video metadata when configured — no
|
||||||
|
# IGDB/TMDB fallback; an unreachable server just leaves metadata empty.
|
||||||
|
# PS1 metadata stays client-side (the server catalog only covers games
|
||||||
|
# and videos).
|
||||||
|
if server_client.configured() and system in ("games", "videos"):
|
||||||
|
try:
|
||||||
|
meta = server_client.fetch_metadata(system, fetch_title)
|
||||||
|
except Exception as exc: # noqa: BLE001
|
||||||
|
log.warning("server metadata fetch failed for %r: %s", fetch_title, exc)
|
||||||
|
return None
|
||||||
|
if meta:
|
||||||
|
save(release_id, system, meta, manual=False)
|
||||||
|
meta["manual"] = False
|
||||||
|
return meta
|
||||||
|
return None
|
||||||
key = (str(release_id), system)
|
key = (str(release_id), system)
|
||||||
last = _failed.get(key)
|
last = _failed.get(key)
|
||||||
if last is not None and time.time() - last < _FAIL_TTL:
|
if last is not None and time.time() - last < _FAIL_TTL:
|
||||||
|
|||||||
@@ -88,6 +88,42 @@ def ingest_dat(conn, path):
|
|||||||
return dat_name, system, release_count, rom_count
|
return dat_name, system, release_count, rom_count
|
||||||
|
|
||||||
|
|
||||||
|
def ensure_catalog(dats_dir=None, conn=None):
|
||||||
|
"""Ingest any DAT files missing from the DB (idempotent, cheap when current).
|
||||||
|
|
||||||
|
Called once at startup so a fresh/reset database still has the catalog and
|
||||||
|
scanning produces matches instead of everything coming back ``unknown``.
|
||||||
|
Returns the number of DATs ingested.
|
||||||
|
"""
|
||||||
|
dats_dir = Path(dats_dir) if dats_dir else config.DATS_DIR
|
||||||
|
if not dats_dir.is_dir():
|
||||||
|
return 0
|
||||||
|
files = sorted(p for p in dats_dir.glob("*.dat") if p.is_file())
|
||||||
|
if not files:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
own = conn is None
|
||||||
|
if own:
|
||||||
|
conn = get_connection(config.DB_PATH)
|
||||||
|
try:
|
||||||
|
known = {r["source_path"] for r in conn.execute("SELECT source_path FROM dats")}
|
||||||
|
count = 0
|
||||||
|
for path in files:
|
||||||
|
if str(path) in known:
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
ingest_dat(conn, path)
|
||||||
|
except Exception as exc: # noqa: BLE001 - a bad DAT shouldn't block startup
|
||||||
|
print(f"warning: could not ingest {path.name}: {exc}", file=sys.stderr)
|
||||||
|
continue
|
||||||
|
count += 1
|
||||||
|
conn.commit()
|
||||||
|
return count
|
||||||
|
finally:
|
||||||
|
if own:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
def main(argv=None):
|
def main(argv=None):
|
||||||
parser = argparse.ArgumentParser(description="Ingest clrmamepro DAT files into SQLite")
|
parser = argparse.ArgumentParser(description="Ingest clrmamepro DAT files into SQLite")
|
||||||
parser.add_argument("--dats", help="directory containing .dat files (default: data/dats)")
|
parser.add_argument("--dats", help="directory containing .dat files (default: data/dats)")
|
||||||
|
|||||||
+4
-2
@@ -48,8 +48,10 @@ def launch_ppsspp(iso, exe=""):
|
|||||||
else:
|
else:
|
||||||
return False, "PPSSPP not found. Install it or set its path in Settings → Saves."
|
return False, "PPSSPP not found. Install it or set its path in Settings → Saves."
|
||||||
try:
|
try:
|
||||||
subprocess.Popen(cmd, start_new_session=True, env=_env(),
|
kwargs = {"env": _env(), "stdout": subprocess.DEVNULL, "stderr": subprocess.DEVNULL}
|
||||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
if os.name != "nt":
|
||||||
|
kwargs["start_new_session"] = True # POSIX-only: detach from our process group
|
||||||
|
subprocess.Popen(cmd, **kwargs)
|
||||||
return True, ""
|
return True, ""
|
||||||
except OSError as exc:
|
except OSError as exc:
|
||||||
return False, str(exc)
|
return False, str(exc)
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
"""PSP Preservation Tool entry point (native GUI).
|
"""psppt entry point (native GUI).
|
||||||
|
|
||||||
Run with::
|
Run with::
|
||||||
|
|
||||||
|
|||||||
+35
-1
@@ -111,6 +111,36 @@ def normalize_name(name):
|
|||||||
return _normalize(name)
|
return _normalize(name)
|
||||||
|
|
||||||
|
|
||||||
|
_EUROPEAN_REGIONS = {
|
||||||
|
"europe", "germany", "france", "spain", "italy", "russia", "netherlands",
|
||||||
|
"portugal", "poland", "united kingdom", "greece", "norway", "sweden",
|
||||||
|
"denmark", "finland", "austria", "belgium", "switzerland",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def region_matches(region, prefer):
|
||||||
|
"""True if ``region`` satisfies the user's preferred-region hint."""
|
||||||
|
if not prefer or not region:
|
||||||
|
return False
|
||||||
|
tokens = {t.strip().lower() for t in str(region).split(",") if t.strip()}
|
||||||
|
if not tokens:
|
||||||
|
return False
|
||||||
|
prefer = prefer.strip().lower()
|
||||||
|
if prefer in tokens:
|
||||||
|
return True
|
||||||
|
if prefer == "europe":
|
||||||
|
return bool(tokens & _EUROPEAN_REGIONS)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def apply_region_preference(candidates, prefer):
|
||||||
|
"""Narrow ``candidates`` to the preferred region (fall back to all)."""
|
||||||
|
if not prefer:
|
||||||
|
return candidates
|
||||||
|
filtered = [c for c in candidates if region_matches(c.get("region"), prefer)]
|
||||||
|
return filtered or candidates
|
||||||
|
|
||||||
|
|
||||||
def serial_candidates(conn, record):
|
def serial_candidates(conn, record):
|
||||||
"""Return all catalog releases matching the disc's serial (size-narrowed)."""
|
"""Return all catalog releases matching the disc's serial (size-narrowed)."""
|
||||||
serial = record.get("serial")
|
serial = record.get("serial")
|
||||||
@@ -131,7 +161,7 @@ def serial_candidates(conn, record):
|
|||||||
return _narrow(conn, [dict(r) for r in rows], record.get("size"))
|
return _narrow(conn, [dict(r) for r in rows], record.get("size"))
|
||||||
|
|
||||||
|
|
||||||
def match(conn, record):
|
def match(conn, record, prefer_region=None):
|
||||||
size = record.get("size")
|
size = record.get("size")
|
||||||
|
|
||||||
# 1. Hash is the most precise key; serials are shared across revisions.
|
# 1. Hash is the most precise key; serials are shared across revisions.
|
||||||
@@ -171,6 +201,10 @@ def match(conn, record):
|
|||||||
for cand in candidates:
|
for cand in candidates:
|
||||||
if cand["id"] == saved["release_id"]:
|
if cand["id"] == saved["release_id"]:
|
||||||
return "choice", cand
|
return "choice", cand
|
||||||
|
if prefer_region:
|
||||||
|
filtered = [c for c in candidates if region_matches(c.get("region"), prefer_region)]
|
||||||
|
if len(filtered) == 1:
|
||||||
|
return "region", filtered[0]
|
||||||
return "unknown", None
|
return "unknown", None
|
||||||
|
|
||||||
# 4. Fuzzy fallback (filename + PARAM.SFO title), size-disambiguated.
|
# 4. Fuzzy fallback (filename + PARAM.SFO title), size-disambiguated.
|
||||||
|
|||||||
+6
-93
@@ -9,14 +9,12 @@ folder — no Wine or ``pkg2zip`` required.
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import urllib.request
|
import urllib.request
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Optional
|
from typing import List
|
||||||
|
|
||||||
from . import config
|
from . import config
|
||||||
|
|
||||||
@@ -56,7 +54,7 @@ def tsv_url(content_type: str, base: str = "") -> str:
|
|||||||
|
|
||||||
|
|
||||||
def _tsv_dir() -> Path:
|
def _tsv_dir() -> Path:
|
||||||
d = config.DATA_DIR / "nps"
|
d = config.USER_DATA_DIR / "nps"
|
||||||
d.mkdir(parents=True, exist_ok=True)
|
d.mkdir(parents=True, exist_ok=True)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
@@ -153,7 +151,7 @@ def fetch_items(content_type: str, url: str = "", timeout: int = 60, force: bool
|
|||||||
return items
|
return items
|
||||||
|
|
||||||
try:
|
try:
|
||||||
req = urllib.request.Request(url, headers={"User-Agent": "psp-preserve/0.1"})
|
req = urllib.request.Request(url, headers={"User-Agent": "psppt/0.1"})
|
||||||
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
||||||
data = resp.read()
|
data = resp.read()
|
||||||
text = data.decode("utf-8", errors="replace")
|
text = data.decode("utf-8", errors="replace")
|
||||||
@@ -167,31 +165,6 @@ def fetch_items(content_type: str, url: str = "", timeout: int = 60, force: bool
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
def find_pkg2zip(configured_path: str = "") -> Optional[Path]:
|
|
||||||
"""Locate pkg2zip: configured path, then the bundled binary, then PATH."""
|
|
||||||
if configured_path:
|
|
||||||
p = Path(configured_path)
|
|
||||||
return p if p.is_file() else None
|
|
||||||
bundled = config.DATA_DIR / "bin" / "pkg2zip.exe"
|
|
||||||
if bundled.is_file():
|
|
||||||
return bundled
|
|
||||||
found = shutil.which("pkg2zip")
|
|
||||||
return Path(found) if found else None
|
|
||||||
|
|
||||||
|
|
||||||
def _pkg2zip_cmd(pkg2zip: Path) -> List[str]:
|
|
||||||
"""Command prefix for pkg2zip, wrapping the bundled .exe in Wine on Linux."""
|
|
||||||
if pkg2zip.suffix.lower() == ".exe" and os.name != "nt":
|
|
||||||
wine = shutil.which("wine") or shutil.which("wine64")
|
|
||||||
if not wine:
|
|
||||||
raise RuntimeError(
|
|
||||||
"The bundled pkg2zip is a Windows binary and Wine is not installed — "
|
|
||||||
"install Wine (or point Settings → Store at a native pkg2zip)."
|
|
||||||
)
|
|
||||||
return [wine, str(pkg2zip)]
|
|
||||||
return [str(pkg2zip)]
|
|
||||||
|
|
||||||
|
|
||||||
def _safe_folder(value: str) -> str:
|
def _safe_folder(value: str) -> str:
|
||||||
import re
|
import re
|
||||||
cleaned = re.sub(r"[^A-Za-z0-9]", "", value or "").upper()
|
cleaned = re.sub(r"[^A-Za-z0-9]", "", value or "").upper()
|
||||||
@@ -211,12 +184,11 @@ def _ensure_keys_bin(folder, kind):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def extract_pkg(pkg_path, title_id: str, dest_dir, pkg2zip: Path = None,
|
def extract_pkg(pkg_path, title_id: str, dest_dir,
|
||||||
kind_hint: str = None, progress_cb=None, cancel_event=None) -> Path:
|
kind_hint: str = None, progress_cb=None, cancel_event=None) -> Path:
|
||||||
"""Decrypt/extract a ``.pkg`` into ``dest_dir/<TITLE_ID>/``.
|
"""Decrypt/extract a ``.pkg`` into ``dest_dir/<TITLE_ID>/``.
|
||||||
|
|
||||||
Uses the bundled pure-Python decryptor (no Wine / pkg2zip needed); falls
|
Uses the bundled pure-Python decryptor (no Wine or pkg2zip). Returns the
|
||||||
back to pkg2zip only if that fails and a binary is available. Returns the
|
|
||||||
destination game folder path.
|
destination game folder path.
|
||||||
"""
|
"""
|
||||||
from . import pkg as pkgmod
|
from . import pkg as pkgmod
|
||||||
@@ -227,7 +199,6 @@ def extract_pkg(pkg_path, title_id: str, dest_dir, pkg2zip: Path = None,
|
|||||||
if dest.is_dir() and any(dest.iterdir()):
|
if dest.is_dir() and any(dest.iterdir()):
|
||||||
return dest
|
return dest
|
||||||
|
|
||||||
# 1. Pure-Python decryptor (primary).
|
|
||||||
try:
|
try:
|
||||||
_kind, _tid, folder = pkgmod.extract(pkg_path, dest_dir, kind_hint,
|
_kind, _tid, folder = pkgmod.extract(pkg_path, dest_dir, kind_hint,
|
||||||
progress_cb, cancel_event)
|
progress_cb, cancel_event)
|
||||||
@@ -236,62 +207,4 @@ def extract_pkg(pkg_path, title_id: str, dest_dir, pkg2zip: Path = None,
|
|||||||
except TransferCancelled:
|
except TransferCancelled:
|
||||||
raise
|
raise
|
||||||
except Exception as exc: # noqa: BLE001
|
except Exception as exc: # noqa: BLE001
|
||||||
py_exc = exc
|
raise RuntimeError(f"could not decrypt {pkg_path.name}: {exc}") from exc
|
||||||
log.warning("python pkg decrypt failed (%s); trying pkg2zip fallback", exc)
|
|
||||||
|
|
||||||
# 2. pkg2zip fallback (needs a binary; usually Wine + the bundled .exe).
|
|
||||||
if pkg2zip is None:
|
|
||||||
pkg2zip = find_pkg2zip()
|
|
||||||
if pkg2zip is None:
|
|
||||||
raise RuntimeError(
|
|
||||||
f"could not decrypt {pkg_path.name} (no pkg2zip available): {py_exc}"
|
|
||||||
)
|
|
||||||
|
|
||||||
folder_name = _safe_folder(title_id)
|
|
||||||
tmp = Path(dest_dir).with_name(".nps-tmp-" + folder_name)
|
|
||||||
if tmp.exists():
|
|
||||||
shutil.rmtree(tmp, ignore_errors=True)
|
|
||||||
tmp.mkdir(parents=True, exist_ok=True)
|
|
||||||
|
|
||||||
if progress_cb is not None:
|
|
||||||
progress_cb("Extracting", 0.0, "")
|
|
||||||
try:
|
|
||||||
cmd = _pkg2zip_cmd(Path(pkg2zip)) + ["-x", str(pkg_path)]
|
|
||||||
env = dict(os.environ)
|
|
||||||
env["WINEDEBUG"] = "-all" # silence Wine's console chatter
|
|
||||||
proc = subprocess.Popen(
|
|
||||||
cmd,
|
|
||||||
cwd=str(tmp), stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
|
||||||
text=True, bufsize=1, env=env,
|
|
||||||
)
|
|
||||||
assert proc.stdout is not None
|
|
||||||
for _line in proc.stdout:
|
|
||||||
if cancel_event is not None and cancel_event.is_set():
|
|
||||||
proc.kill()
|
|
||||||
raise TransferCancelled()
|
|
||||||
proc.wait()
|
|
||||||
if proc.returncode != 0:
|
|
||||||
raise RuntimeError(f"pkg2zip failed (exit {proc.returncode}) for {pkg_path.name}")
|
|
||||||
finally:
|
|
||||||
if cancel_event is not None and cancel_event.is_set():
|
|
||||||
shutil.rmtree(tmp, ignore_errors=True)
|
|
||||||
raise TransferCancelled()
|
|
||||||
|
|
||||||
eboots = list(tmp.rglob("EBOOT.PBP"))
|
|
||||||
if not eboots:
|
|
||||||
shutil.rmtree(tmp, ignore_errors=True)
|
|
||||||
raise RuntimeError(f"pkg2zip produced no EBOOT.PBP from {pkg_path.name}")
|
|
||||||
src_folder = eboots[0].parent
|
|
||||||
|
|
||||||
dest.mkdir(parents=True, exist_ok=True)
|
|
||||||
for p in sorted(src_folder.rglob("*")):
|
|
||||||
if not p.is_file():
|
|
||||||
continue
|
|
||||||
rel = p.relative_to(src_folder)
|
|
||||||
target = dest / rel
|
|
||||||
target.parent.mkdir(parents=True, exist_ok=True)
|
|
||||||
shutil.copy2(p, target)
|
|
||||||
if progress_cb is not None:
|
|
||||||
progress_cb("Extracting", 1.0, "")
|
|
||||||
shutil.rmtree(tmp, ignore_errors=True)
|
|
||||||
return dest
|
|
||||||
|
|||||||
+1
-1
@@ -155,7 +155,7 @@ def scrape(limit=None, workers=8, rate=3.0):
|
|||||||
log.info("downloading OpenVGDB dump (%s)…", OVGDB_ZIP_URL)
|
log.info("downloading OpenVGDB dump (%s)…", OVGDB_ZIP_URL)
|
||||||
tmpdir = Path(tempfile.mkdtemp(prefix="openvgdb-"))
|
tmpdir = Path(tempfile.mkdtemp(prefix="openvgdb-"))
|
||||||
dump_zip = tmpdir / "openvgdb.zip"
|
dump_zip = tmpdir / "openvgdb.zip"
|
||||||
req = urllib.request.Request(OVGDB_ZIP_URL, headers={"User-Agent": "psp-preserve/0.1"})
|
req = urllib.request.Request(OVGDB_ZIP_URL, headers={"User-Agent": "psppt/0.1"})
|
||||||
with urllib.request.urlopen(req, timeout=60) as r, open(dump_zip, "wb") as f:
|
with urllib.request.urlopen(req, timeout=60) as r, open(dump_zip, "wb") as f:
|
||||||
f.write(r.read())
|
f.write(r.read())
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -2,9 +2,9 @@
|
|||||||
from . import iso_reader, matcher, namer
|
from . import iso_reader, matcher, namer
|
||||||
|
|
||||||
|
|
||||||
def identify(conn, record):
|
def identify(conn, record, prefer_region=None):
|
||||||
"""Return ``{method, release, serial, canonical}`` for a scanned disc record."""
|
"""Return ``{method, release, serial, canonical}`` for a scanned disc record."""
|
||||||
method, release = matcher.match(conn, record)
|
method, release = matcher.match(conn, record, prefer_region=prefer_region)
|
||||||
return identify_with_release(record, release, method)
|
return identify_with_release(record, release, method)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -40,6 +40,7 @@ import io
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import struct
|
import struct
|
||||||
|
import sys
|
||||||
import zlib
|
import zlib
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -88,7 +89,9 @@ SYNC_PATTERN = b"\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00"
|
|||||||
# (ARK/PRO/ME) loads this ELF directly as the DATA.PSP section, sidestepping
|
# (ARK/PRO/ME) loads this ELF directly as the DATA.PSP section, sidestepping
|
||||||
# the base PBP's encrypted ~PSP loader which frequently fails to link on
|
# the base PBP's encrypted ~PSP loader which frequently fails to link on
|
||||||
# 6.60/6.61 (error 80020148 "game could not be started").
|
# 6.60/6.61 (error 80020148 "game could not be started").
|
||||||
_LOADER_DIR = Path(__file__).resolve().parent.parent / "data" / "loader"
|
_BUNDLE_DIR = getattr(sys, "_MEIPASS", None)
|
||||||
|
_APP_ROOT = Path(_BUNDLE_DIR).resolve() if _BUNDLE_DIR else Path(__file__).resolve().parent.parent
|
||||||
|
_LOADER_DIR = _APP_ROOT / "data" / "loader"
|
||||||
BUNDLED_DATA_PSP = _LOADER_DIR / "DATA.PSP"
|
BUNDLED_DATA_PSP = _LOADER_DIR / "DATA.PSP"
|
||||||
BUNDLED_KEYS_BIN = _LOADER_DIR / "KEYS.BIN"
|
BUNDLED_KEYS_BIN = _LOADER_DIR / "KEYS.BIN"
|
||||||
|
|
||||||
|
|||||||
+39
-36
@@ -79,13 +79,13 @@ class TransferQueue(QObject):
|
|||||||
job_finished = Signal(dict)
|
job_finished = Signal(dict)
|
||||||
job_removed = Signal(int)
|
job_removed = Signal(int)
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None, max_concurrent=3):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
self.max_concurrent = max(1, int(max_concurrent))
|
||||||
self.jobs = []
|
self.jobs = []
|
||||||
self._pending = []
|
self._pending = []
|
||||||
self._current = None
|
# job_id -> (QThread, JobWorker) for jobs currently running in parallel.
|
||||||
self._thread = None
|
self._running = {}
|
||||||
self._worker = None
|
|
||||||
# Keep strong references to every worker/thread for their full lifetime.
|
# Keep strong references to every worker/thread for their full lifetime.
|
||||||
# Dropping a Python ref to a QObject that was moved to another thread
|
# Dropping a Python ref to a QObject that was moved to another thread
|
||||||
# deletes it directly and crashes (bus error).
|
# deletes it directly and crashes (bus error).
|
||||||
@@ -115,8 +115,10 @@ class TransferQueue(QObject):
|
|||||||
self.job_updated.emit(job.to_dict())
|
self.job_updated.emit(job.to_dict())
|
||||||
self.job_finished.emit(job.to_dict())
|
self.job_finished.emit(job.to_dict())
|
||||||
return
|
return
|
||||||
if job.status == "running" and self._worker is not None:
|
if job.status == "running":
|
||||||
self._worker.cancel()
|
pair = self._running.get(job_id)
|
||||||
|
if pair is not None:
|
||||||
|
pair[1].cancel()
|
||||||
job.status = "cancelling"
|
job.status = "cancelling"
|
||||||
self.job_updated.emit(job.to_dict())
|
self.job_updated.emit(job.to_dict())
|
||||||
|
|
||||||
@@ -140,8 +142,8 @@ class TransferQueue(QObject):
|
|||||||
self.remove(jid)
|
self.remove(jid)
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
if self._worker is not None:
|
for _t, worker in self._running.values():
|
||||||
self._worker.cancel()
|
worker.cancel()
|
||||||
for t in self._threads:
|
for t in self._threads:
|
||||||
try:
|
try:
|
||||||
if t.isRunning():
|
if t.isRunning():
|
||||||
@@ -157,30 +159,29 @@ class TransferQueue(QObject):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def _start_next(self):
|
def _start_next(self):
|
||||||
if self._current is not None or not self._pending:
|
while len(self._running) < self.max_concurrent and self._pending:
|
||||||
return
|
job = self._pending.pop(0)
|
||||||
job = self._pending.pop(0)
|
job.status = "running"
|
||||||
self._current = job
|
log.info("starting job #%d: %s (%s)", job.id, job.title, job.kind)
|
||||||
job.status = "running"
|
self.job_updated.emit(job.to_dict())
|
||||||
log.info("starting job #%d: %s (%s)", job.id, job.title, job.kind)
|
|
||||||
self.job_updated.emit(job.to_dict())
|
|
||||||
|
|
||||||
self._thread = QThread(self)
|
thread = QThread(self)
|
||||||
self._worker = JobWorker(job.source, job.dest_dir, job)
|
worker = JobWorker(job.source, job.dest_dir, job)
|
||||||
self._worker.moveToThread(self._thread)
|
worker.moveToThread(thread)
|
||||||
self._thread.started.connect(self._worker.run)
|
thread.started.connect(worker.run)
|
||||||
self._worker.progress.connect(self._on_progress)
|
worker.progress.connect(self._on_progress)
|
||||||
self._worker.finished.connect(self._on_finished)
|
worker.finished.connect(self._on_finished)
|
||||||
self._worker.skipped.connect(self._on_skipped)
|
worker.skipped.connect(self._on_skipped)
|
||||||
self._worker.cancelled.connect(self._on_cancelled)
|
worker.cancelled.connect(self._on_cancelled)
|
||||||
self._worker.failed.connect(self._on_failed)
|
worker.failed.connect(self._on_failed)
|
||||||
for sig in (self._worker.finished, self._worker.skipped,
|
for sig in (worker.finished, worker.skipped,
|
||||||
self._worker.cancelled, self._worker.failed):
|
worker.cancelled, worker.failed):
|
||||||
sig.connect(self._thread.quit)
|
sig.connect(thread.quit)
|
||||||
self._thread.finished.connect(self._on_thread_finished)
|
thread.finished.connect(self._on_thread_finished)
|
||||||
self._threads.append(self._thread)
|
self._running[job.id] = (thread, worker)
|
||||||
self._workers.append(self._worker)
|
self._threads.append(thread)
|
||||||
self._thread.start()
|
self._workers.append(worker)
|
||||||
|
thread.start()
|
||||||
|
|
||||||
def _on_progress(self, job_id, stage, fraction, detail):
|
def _on_progress(self, job_id, stage, fraction, detail):
|
||||||
job = self._find(job_id)
|
job = self._find(job_id)
|
||||||
@@ -218,10 +219,12 @@ class TransferQueue(QObject):
|
|||||||
self.job_finished.emit(job.to_dict())
|
self.job_finished.emit(job.to_dict())
|
||||||
|
|
||||||
def _on_thread_finished(self):
|
def _on_thread_finished(self):
|
||||||
# Queued to the main thread once the worker thread has fully stopped,
|
# Queued to the main thread once a worker thread has fully stopped, so
|
||||||
# so it is now safe to drop the "current" pointers and advance.
|
# it is now safe to drop its pointers and advance the queue.
|
||||||
self._current = None
|
thread = self.sender()
|
||||||
self._thread = None
|
for jid, pair in list(self._running.items()):
|
||||||
self._worker = None
|
if pair[0] is thread:
|
||||||
|
del self._running[jid]
|
||||||
|
break
|
||||||
self._start_next()
|
self._start_next()
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,112 @@
|
|||||||
|
"""Client-side HTTP access to the psppt server (auth + content fetches).
|
||||||
|
|
||||||
|
The server is authoritative for covers and metadata. When a server is
|
||||||
|
configured (URL + per-user token), the cover/metadata paths use it and show an
|
||||||
|
error rather than falling back to libretro/IGDB/etc.
|
||||||
|
"""
|
||||||
|
import json
|
||||||
|
import logging
|
||||||
|
import urllib.error
|
||||||
|
import urllib.parse
|
||||||
|
import urllib.request
|
||||||
|
|
||||||
|
from . import config
|
||||||
|
|
||||||
|
log = logging.getLogger("server_client")
|
||||||
|
|
||||||
|
_CFG_FILE = config.STATE_DIR / "server.json"
|
||||||
|
_cache = {"loaded": False, "cfg": {}}
|
||||||
|
|
||||||
|
|
||||||
|
def _load():
|
||||||
|
if not _cache["loaded"]:
|
||||||
|
cfg = {}
|
||||||
|
try:
|
||||||
|
cfg = json.loads(_CFG_FILE.read_text(encoding="utf-8"))
|
||||||
|
except (OSError, ValueError):
|
||||||
|
cfg = {}
|
||||||
|
_cache["cfg"] = cfg
|
||||||
|
_cache["loaded"] = True
|
||||||
|
return _cache["cfg"]
|
||||||
|
|
||||||
|
|
||||||
|
def _save(cfg):
|
||||||
|
_CFG_FILE.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
_CFG_FILE.write_text(json.dumps(cfg, indent=2), encoding="utf-8")
|
||||||
|
_cache["cfg"] = cfg
|
||||||
|
_cache["loaded"] = True
|
||||||
|
|
||||||
|
|
||||||
|
def configured():
|
||||||
|
cfg = _load()
|
||||||
|
return bool(cfg.get("url") and cfg.get("token"))
|
||||||
|
|
||||||
|
|
||||||
|
def url():
|
||||||
|
return (_load().get("url") or config.STORE_SERVER_URL or "").rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def token():
|
||||||
|
return _load().get("token") or config.STORE_TOKEN or ""
|
||||||
|
|
||||||
|
|
||||||
|
def username():
|
||||||
|
return _load().get("username") or ""
|
||||||
|
|
||||||
|
|
||||||
|
def logout():
|
||||||
|
_save({"url": url(), "token": "", "username": ""})
|
||||||
|
|
||||||
|
|
||||||
|
def login(server_url, user, password):
|
||||||
|
"""Authenticate against the server and store the per-user token."""
|
||||||
|
base = (server_url or "").rstrip("/")
|
||||||
|
req = urllib.request.Request(
|
||||||
|
f"{base}/api/auth/login",
|
||||||
|
data=json.dumps({"username": user, "password": password}).encode("utf-8"),
|
||||||
|
headers={"Content-Type": "application/json", "User-Agent": "psppt/0.1"},
|
||||||
|
method="POST",
|
||||||
|
)
|
||||||
|
with urllib.request.urlopen(req, timeout=15) as resp:
|
||||||
|
data = json.loads(resp.read())
|
||||||
|
_save({"url": base, "token": data.get("token") or "", "username": data.get("username") or user})
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
def _get(path, timeout=15):
|
||||||
|
req = urllib.request.Request(
|
||||||
|
f"{url()}{path}",
|
||||||
|
headers={"Authorization": f"Bearer {token()}", "User-Agent": "psppt/0.1"},
|
||||||
|
)
|
||||||
|
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
||||||
|
return resp.read()
|
||||||
|
|
||||||
|
|
||||||
|
def _lookup_id(system, name):
|
||||||
|
"""Return the server release id for a name (first match), or None."""
|
||||||
|
q = urllib.parse.quote(name or "")
|
||||||
|
data = json.loads(_get(f"/api/releases?system={system}&q={q}&limit=1", timeout=15))
|
||||||
|
items = data.get("items") or []
|
||||||
|
return items[0]["id"] if items else None
|
||||||
|
|
||||||
|
|
||||||
|
def fetch_cover(system, name):
|
||||||
|
"""Return cover bytes for a release, or None (no cover on the server)."""
|
||||||
|
rid = _lookup_id(system, name)
|
||||||
|
if rid is None:
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
return _get(f"/api/cover/{rid}", timeout=30)
|
||||||
|
except urllib.error.HTTPError as exc:
|
||||||
|
if exc.code == 404:
|
||||||
|
return None
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
def fetch_metadata(system, name):
|
||||||
|
"""Return metadata dict for a release, or None."""
|
||||||
|
rid = _lookup_id(system, name)
|
||||||
|
if rid is None:
|
||||||
|
return None
|
||||||
|
detail = json.loads(_get(f"/api/releases/{rid}", timeout=15))
|
||||||
|
return detail.get("meta") or {}
|
||||||
+1
-1
@@ -11,7 +11,7 @@ from pathlib import Path
|
|||||||
from . import config
|
from . import config
|
||||||
|
|
||||||
CREDENTIALS_PATH = Path(
|
CREDENTIALS_PATH = Path(
|
||||||
os.environ.get("PSP_CREDENTIALS", str(config.DATA_DIR / "credentials.json"))
|
os.environ.get("PSP_CREDENTIALS", str(config.USER_DATA_DIR / "credentials.json"))
|
||||||
)
|
)
|
||||||
|
|
||||||
FIELDS = [
|
FIELDS = [
|
||||||
|
|||||||
+316
@@ -0,0 +1,316 @@
|
|||||||
|
"""Global dark theme for the GUI (Fusion style + palette + stylesheet).
|
||||||
|
|
||||||
|
Applied once at startup from ``gui.main``. The per-widget ``setStyleSheet``
|
||||||
|
colors sprinkled through ``gui.py`` (``#999`` secondary text, ``#e06c6c`` delete
|
||||||
|
buttons, ``#14151a`` preview panels) were written for a dark background, so a
|
||||||
|
single cohesive dark theme here makes the whole UI consistent.
|
||||||
|
"""
|
||||||
|
from PySide6.QtGui import QColor, QPalette
|
||||||
|
|
||||||
|
from . import config
|
||||||
|
|
||||||
|
# Design tokens
|
||||||
|
BG = "#1e1f24" # window background
|
||||||
|
SURFACE = "#26272e" # cards, inputs, table headers
|
||||||
|
RAISED = "#2d2e36" # buttons, combos, menus
|
||||||
|
BORDER = "#3a3b44"
|
||||||
|
BORDER_SOFT = "#33343d"
|
||||||
|
TEXT = "#e6e6ea"
|
||||||
|
TEXT_DIM = "#9a9ba5"
|
||||||
|
TEXT_FAINT = "#6f7079"
|
||||||
|
ACCENT = "#4a9eff"
|
||||||
|
ACCENT_HOVER = "#6bb0ff"
|
||||||
|
|
||||||
|
|
||||||
|
_STYLESHEET = f"""
|
||||||
|
QMainWindow {{
|
||||||
|
background: {BG};
|
||||||
|
}}
|
||||||
|
QWidget {{
|
||||||
|
color: {TEXT};
|
||||||
|
}}
|
||||||
|
|
||||||
|
/* --- Tabs --- */
|
||||||
|
QTabWidget::pane {{
|
||||||
|
border: 1px solid {BORDER};
|
||||||
|
border-radius: 6px;
|
||||||
|
top: -1px;
|
||||||
|
}}
|
||||||
|
QTabBar::tab {{
|
||||||
|
background: transparent;
|
||||||
|
color: {TEXT_DIM};
|
||||||
|
padding: 8px 18px;
|
||||||
|
border: none;
|
||||||
|
border-bottom: 2px solid transparent;
|
||||||
|
margin-right: 2px;
|
||||||
|
}}
|
||||||
|
QTabBar::tab:hover:!selected {{
|
||||||
|
color: {TEXT};
|
||||||
|
}}
|
||||||
|
QTabBar::tab:selected {{
|
||||||
|
color: {TEXT};
|
||||||
|
border-bottom: 2px solid {ACCENT};
|
||||||
|
}}
|
||||||
|
|
||||||
|
/* --- Buttons --- */
|
||||||
|
QPushButton {{
|
||||||
|
background: {RAISED};
|
||||||
|
border: 1px solid {BORDER};
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 6px 12px;
|
||||||
|
}}
|
||||||
|
QPushButton:hover {{
|
||||||
|
background: #343640;
|
||||||
|
border-color: {ACCENT_HOVER};
|
||||||
|
}}
|
||||||
|
QPushButton:pressed {{
|
||||||
|
background: {SURFACE};
|
||||||
|
}}
|
||||||
|
QPushButton:disabled {{
|
||||||
|
color: {TEXT_FAINT};
|
||||||
|
background: {SURFACE};
|
||||||
|
border-color: {BORDER_SOFT};
|
||||||
|
}}
|
||||||
|
QPushButton:checked {{
|
||||||
|
background: {ACCENT};
|
||||||
|
border-color: {ACCENT};
|
||||||
|
color: #101116;
|
||||||
|
}}
|
||||||
|
|
||||||
|
/* --- Inputs --- */
|
||||||
|
QLineEdit, QSpinBox, QPlainTextEdit, QTextEdit {{
|
||||||
|
background: {SURFACE};
|
||||||
|
border: 1px solid {BORDER};
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 5px 8px;
|
||||||
|
selection-background-color: {ACCENT};
|
||||||
|
selection-color: #101116;
|
||||||
|
}}
|
||||||
|
QLineEdit:focus, QSpinBox:focus, QPlainTextEdit:focus, QTextEdit:focus {{
|
||||||
|
border-color: {ACCENT};
|
||||||
|
}}
|
||||||
|
QLineEdit:disabled, QSpinBox:disabled {{
|
||||||
|
color: {TEXT_FAINT};
|
||||||
|
}}
|
||||||
|
|
||||||
|
/* --- Combo boxes --- */
|
||||||
|
QComboBox {{
|
||||||
|
background: {RAISED};
|
||||||
|
border: 1px solid {BORDER};
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 4px 10px;
|
||||||
|
}}
|
||||||
|
QComboBox:hover {{
|
||||||
|
border-color: {ACCENT_HOVER};
|
||||||
|
}}
|
||||||
|
QComboBox::drop-down {{
|
||||||
|
border: none;
|
||||||
|
width: 22px;
|
||||||
|
}}
|
||||||
|
QComboBox::down-arrow {{
|
||||||
|
image: url(__CHEVRON__);
|
||||||
|
width: 12px;
|
||||||
|
height: 8px;
|
||||||
|
margin-right: 6px;
|
||||||
|
}}
|
||||||
|
QComboBox QAbstractItemView {{
|
||||||
|
background: {RAISED};
|
||||||
|
border: 1px solid {BORDER};
|
||||||
|
border-radius: 6px;
|
||||||
|
selection-background-color: rgba(74, 158, 255, 0.25);
|
||||||
|
selection-color: {TEXT};
|
||||||
|
outline: 0;
|
||||||
|
}}
|
||||||
|
|
||||||
|
/* --- Tables --- */
|
||||||
|
QTableWidget {{
|
||||||
|
background: transparent;
|
||||||
|
border: none;
|
||||||
|
gridline-color: {BORDER_SOFT};
|
||||||
|
}}
|
||||||
|
QHeaderView::section {{
|
||||||
|
background: {SURFACE};
|
||||||
|
color: {TEXT_DIM};
|
||||||
|
border: none;
|
||||||
|
border-bottom: 1px solid {BORDER};
|
||||||
|
padding: 6px 8px;
|
||||||
|
}}
|
||||||
|
QTableWidget::item {{
|
||||||
|
padding: 4px 6px;
|
||||||
|
}}
|
||||||
|
QTableWidget::item:selected {{
|
||||||
|
background: rgba(74, 158, 255, 0.22);
|
||||||
|
color: {TEXT};
|
||||||
|
}}
|
||||||
|
QTableCornerButton::section {{
|
||||||
|
background: {SURFACE};
|
||||||
|
border: none;
|
||||||
|
border-bottom: 1px solid {BORDER};
|
||||||
|
}}
|
||||||
|
|
||||||
|
/* --- Cover grid / lists --- */
|
||||||
|
QListWidget {{
|
||||||
|
background: transparent;
|
||||||
|
border: none;
|
||||||
|
}}
|
||||||
|
QListWidget::item {{
|
||||||
|
border-radius: 6px;
|
||||||
|
}}
|
||||||
|
QListWidget::item:hover:!selected {{
|
||||||
|
background: rgba(255, 255, 255, 0.04);
|
||||||
|
}}
|
||||||
|
QListWidget::item:selected {{
|
||||||
|
background: rgba(74, 158, 255, 0.22);
|
||||||
|
}}
|
||||||
|
|
||||||
|
/* --- Cards (details panels use QScrollArea) --- */
|
||||||
|
QScrollArea {{
|
||||||
|
background: {SURFACE};
|
||||||
|
border: none;
|
||||||
|
}}
|
||||||
|
|
||||||
|
/* --- Menus --- */
|
||||||
|
QMenu {{
|
||||||
|
background: {RAISED};
|
||||||
|
border: 1px solid {BORDER};
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 4px;
|
||||||
|
}}
|
||||||
|
QMenu::item {{
|
||||||
|
padding: 6px 26px 6px 12px;
|
||||||
|
border-radius: 4px;
|
||||||
|
}}
|
||||||
|
QMenu::item:selected {{
|
||||||
|
background: rgba(74, 158, 255, 0.25);
|
||||||
|
}}
|
||||||
|
QMenu::separator {{
|
||||||
|
height: 1px;
|
||||||
|
background: {BORDER};
|
||||||
|
margin: 4px 8px;
|
||||||
|
}}
|
||||||
|
|
||||||
|
/* --- Scrollbars --- */
|
||||||
|
QScrollBar:vertical {{
|
||||||
|
background: transparent;
|
||||||
|
width: 10px;
|
||||||
|
margin: 0;
|
||||||
|
}}
|
||||||
|
QScrollBar::handle:vertical {{
|
||||||
|
background: {BORDER};
|
||||||
|
border-radius: 5px;
|
||||||
|
min-height: 30px;
|
||||||
|
}}
|
||||||
|
QScrollBar::handle:vertical:hover {{
|
||||||
|
background: {ACCENT};
|
||||||
|
}}
|
||||||
|
QScrollBar:horizontal {{
|
||||||
|
background: transparent;
|
||||||
|
height: 10px;
|
||||||
|
margin: 0;
|
||||||
|
}}
|
||||||
|
QScrollBar::handle:horizontal {{
|
||||||
|
background: {BORDER};
|
||||||
|
border-radius: 5px;
|
||||||
|
min-width: 30px;
|
||||||
|
}}
|
||||||
|
QScrollBar::handle:horizontal:hover {{
|
||||||
|
background: {ACCENT};
|
||||||
|
}}
|
||||||
|
QScrollBar::add-line, QScrollBar::sub-line {{
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
}}
|
||||||
|
QScrollBar::add-page, QScrollBar::sub-page {{
|
||||||
|
background: transparent;
|
||||||
|
}}
|
||||||
|
|
||||||
|
/* --- Splitter --- */
|
||||||
|
QSplitter::handle {{
|
||||||
|
background: transparent;
|
||||||
|
}}
|
||||||
|
QSplitter::handle:horizontal {{
|
||||||
|
width: 1px;
|
||||||
|
}}
|
||||||
|
QSplitter::handle:vertical {{
|
||||||
|
height: 1px;
|
||||||
|
}}
|
||||||
|
|
||||||
|
/* --- Misc --- */
|
||||||
|
QToolTip {{
|
||||||
|
background: {RAISED};
|
||||||
|
color: {TEXT};
|
||||||
|
border: 1px solid {BORDER};
|
||||||
|
padding: 4px 6px;
|
||||||
|
}}
|
||||||
|
QStatusBar {{
|
||||||
|
background: {SURFACE};
|
||||||
|
color: {TEXT_DIM};
|
||||||
|
border-top: 1px solid {BORDER};
|
||||||
|
}}
|
||||||
|
QProgressBar {{
|
||||||
|
background: {SURFACE};
|
||||||
|
border: 1px solid {BORDER};
|
||||||
|
border-radius: 6px;
|
||||||
|
text-align: center;
|
||||||
|
}}
|
||||||
|
QProgressBar::chunk {{
|
||||||
|
background: {ACCENT};
|
||||||
|
border-radius: 5px;
|
||||||
|
}}
|
||||||
|
QCheckBox {{
|
||||||
|
spacing: 8px;
|
||||||
|
}}
|
||||||
|
QCheckBox::indicator {{
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
border: 1px solid {BORDER};
|
||||||
|
border-radius: 4px;
|
||||||
|
background: {SURFACE};
|
||||||
|
}}
|
||||||
|
QCheckBox::indicator:checked {{
|
||||||
|
background: {ACCENT};
|
||||||
|
border-color: {ACCENT};
|
||||||
|
}}
|
||||||
|
QGroupBox {{
|
||||||
|
border: 1px solid {BORDER};
|
||||||
|
border-radius: 6px;
|
||||||
|
margin-top: 10px;
|
||||||
|
}}
|
||||||
|
QGroupBox::title {{
|
||||||
|
subcontrol-origin: margin;
|
||||||
|
left: 10px;
|
||||||
|
padding: 0 4px;
|
||||||
|
color: {TEXT_DIM};
|
||||||
|
}}
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def _dark_palette():
|
||||||
|
p = QPalette()
|
||||||
|
p.setColor(QPalette.Window, QColor(BG))
|
||||||
|
p.setColor(QPalette.WindowText, QColor(TEXT))
|
||||||
|
p.setColor(QPalette.Base, QColor(SURFACE))
|
||||||
|
p.setColor(QPalette.AlternateBase, QColor(RAISED))
|
||||||
|
p.setColor(QPalette.ToolTipBase, QColor(RAISED))
|
||||||
|
p.setColor(QPalette.ToolTipText, QColor(TEXT))
|
||||||
|
p.setColor(QPalette.Text, QColor(TEXT))
|
||||||
|
p.setColor(QPalette.Button, QColor(RAISED))
|
||||||
|
p.setColor(QPalette.ButtonText, QColor(TEXT))
|
||||||
|
p.setColor(QPalette.BrightText, QColor("#ff5c5c"))
|
||||||
|
p.setColor(QPalette.Link, QColor(ACCENT))
|
||||||
|
p.setColor(QPalette.Highlight, QColor(ACCENT))
|
||||||
|
p.setColor(QPalette.HighlightedText, QColor("#101116"))
|
||||||
|
p.setColor(QPalette.PlaceholderText, QColor(TEXT_FAINT))
|
||||||
|
|
||||||
|
faint = QColor(TEXT_FAINT)
|
||||||
|
for role in (QPalette.WindowText, QPalette.Text, QPalette.ButtonText):
|
||||||
|
p.setColor(QPalette.Disabled, role, faint)
|
||||||
|
return p
|
||||||
|
|
||||||
|
|
||||||
|
def apply_theme(app):
|
||||||
|
"""Apply the dark Fusion theme to ``app`` (call once before showing UI)."""
|
||||||
|
app.setStyle("Fusion")
|
||||||
|
app.setPalette(_dark_palette())
|
||||||
|
chevron = str(config.resource_path("img", "chevron.png"))
|
||||||
|
app.setStyleSheet(_STYLESHEET.replace("__CHEVRON__", chevron))
|
||||||
+53
-16
@@ -175,6 +175,33 @@ class Source:
|
|||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
|
class CoversBundleSource:
|
||||||
|
"""Download the combined offline cover bundle (runs as a queue job)."""
|
||||||
|
label = "psppt-covers.zip"
|
||||||
|
|
||||||
|
def __init__(self, url=""):
|
||||||
|
self.url = url
|
||||||
|
|
||||||
|
def download(self, item, dest_dir, progress_cb=None, cancel_event=None):
|
||||||
|
from . import covers
|
||||||
|
|
||||||
|
def on_progress(done, total):
|
||||||
|
if progress_cb is None:
|
||||||
|
return
|
||||||
|
frac = (done / total) if total else 0.0
|
||||||
|
detail = (f"{done / (1 << 20):.0f} / {total / (1 << 20):.0f} MB"
|
||||||
|
if total else "")
|
||||||
|
progress_cb("Downloading", frac, detail)
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = covers.download_covers_bundle(self.url,
|
||||||
|
progress_cb=on_progress,
|
||||||
|
cancel_event=cancel_event)
|
||||||
|
except InterruptedError:
|
||||||
|
raise TransferCancelled() from None
|
||||||
|
return str(result)
|
||||||
|
|
||||||
|
|
||||||
class FileCopySource(Source):
|
class FileCopySource(Source):
|
||||||
"""Copy a single local file (library -> PSP or PSP -> library).
|
"""Copy a single local file (library -> PSP or PSP -> library).
|
||||||
|
|
||||||
@@ -279,12 +306,13 @@ class RemoteStoreSource(Source):
|
|||||||
|
|
||||||
label = "Remote store"
|
label = "Remote store"
|
||||||
|
|
||||||
def __init__(self, base_url, token=""):
|
def __init__(self, base_url, token="", system="games"):
|
||||||
self.base_url = (base_url or "").rstrip("/")
|
self.base_url = (base_url or "").rstrip("/")
|
||||||
self.token = token or ""
|
self.token = token or ""
|
||||||
|
self.system = system or "games"
|
||||||
|
|
||||||
def _headers(self):
|
def _headers(self):
|
||||||
headers = {"User-Agent": "psp-preserve/0.1"}
|
headers = {"User-Agent": "psppt/0.1"}
|
||||||
if self.token:
|
if self.token:
|
||||||
headers["Authorization"] = f"Bearer {self.token}"
|
headers["Authorization"] = f"Bearer {self.token}"
|
||||||
return headers
|
return headers
|
||||||
@@ -292,10 +320,13 @@ class RemoteStoreSource(Source):
|
|||||||
def scan(self, root=None):
|
def scan(self, root=None):
|
||||||
if not self.base_url:
|
if not self.base_url:
|
||||||
return []
|
return []
|
||||||
req = urllib.request.Request(f"{self.base_url}/api/store", headers=self._headers())
|
req = urllib.request.Request(f"{self.base_url}/api/store?system={self.system}", headers=self._headers())
|
||||||
with urllib.request.urlopen(req, timeout=30) as resp:
|
with urllib.request.urlopen(req, timeout=30) as resp:
|
||||||
data = json.loads(resp.read())
|
data = json.loads(resp.read())
|
||||||
return data.get("items", []) if isinstance(data, dict) else []
|
items = data.get("items", []) if isinstance(data, dict) else []
|
||||||
|
for it in items:
|
||||||
|
it["system"] = it.get("system") or self.system
|
||||||
|
return items
|
||||||
|
|
||||||
def download(self, item, dest_dir, progress_cb=None, cancel_event=None):
|
def download(self, item, dest_dir, progress_cb=None, cancel_event=None):
|
||||||
dest_dir = Path(dest_dir)
|
dest_dir = Path(dest_dir)
|
||||||
@@ -303,10 +334,11 @@ class RemoteStoreSource(Source):
|
|||||||
# The listing's "name" has no extension; "filename" carries the real
|
# The listing's "name" has no extension; "filename" carries the real
|
||||||
# archive filename (e.g. "Game (USA).7z") used for the download URL.
|
# archive filename (e.g. "Game (USA).7z") used for the download URL.
|
||||||
name = item.get("filename") or item["name"]
|
name = item.get("filename") or item["name"]
|
||||||
|
system = item.get("system") or self.system
|
||||||
tmp = Path(tempfile.mkdtemp(prefix="psp-store-"))
|
tmp = Path(tempfile.mkdtemp(prefix="psp-store-"))
|
||||||
archive = tmp / name
|
archive = tmp / name
|
||||||
try:
|
try:
|
||||||
url = f"{self.base_url}/api/store/download/{urllib.parse.quote(name, safe='')}"
|
url = f"{self.base_url}/api/store/download/{system}/{urllib.parse.quote(name, safe='')}"
|
||||||
download_url(url, archive, self._headers(), progress_cb, cancel_event)
|
download_url(url, archive, self._headers(), progress_cb, cancel_event)
|
||||||
iso_name = peek_archive(archive, cancel_event)
|
iso_name = peek_archive(archive, cancel_event)
|
||||||
if not iso_name:
|
if not iso_name:
|
||||||
@@ -347,7 +379,7 @@ class ArchiveOrgSource(Source):
|
|||||||
return f"https://archive.org/download/{self.item}"
|
return f"https://archive.org/download/{self.item}"
|
||||||
|
|
||||||
def _headers(self):
|
def _headers(self):
|
||||||
headers = {"User-Agent": "psp-preserve/0.1"}
|
headers = {"User-Agent": "psppt/0.1"}
|
||||||
cookie = "; ".join(
|
cookie = "; ".join(
|
||||||
p for p in (
|
p for p in (
|
||||||
f"logged-in-sig={self.sig}" if self.sig else "",
|
f"logged-in-sig={self.sig}" if self.sig else "",
|
||||||
@@ -476,15 +508,22 @@ class NoPayStationSource(Source):
|
|||||||
|
|
||||||
label = "NoPayStation"
|
label = "NoPayStation"
|
||||||
|
|
||||||
def __init__(self, content_type, tsv_url="", pkg2zip_path="", force=False):
|
def __init__(self, content_type, tsv_url="", force=False):
|
||||||
from . import nopaystation
|
from . import nopaystation
|
||||||
self.content_type = content_type
|
self.content_type = content_type
|
||||||
self.tsv_url = tsv_url or nopaystation.tsv_url(content_type)
|
self.tsv_url = tsv_url or ("" if content_type == "all" else nopaystation.tsv_url(content_type))
|
||||||
self.pkg2zip = pkg2zip_path or ""
|
|
||||||
self.force = force
|
self.force = force
|
||||||
|
|
||||||
def scan(self, root=None):
|
def scan(self, root=None):
|
||||||
from . import nopaystation
|
from . import nopaystation
|
||||||
|
if self.content_type == "all":
|
||||||
|
items = []
|
||||||
|
for ct in ("psp", "psx", "theme", "dlc"):
|
||||||
|
try:
|
||||||
|
items.extend(nopaystation.fetch_items(ct, force=self.force))
|
||||||
|
except Exception: # noqa: BLE001 - skip a source that fails
|
||||||
|
log.warning("could not fetch NoPayStation %s list", ct)
|
||||||
|
return items
|
||||||
return nopaystation.fetch_items(self.content_type, self.tsv_url, force=self.force)
|
return nopaystation.fetch_items(self.content_type, self.tsv_url, force=self.force)
|
||||||
|
|
||||||
def download(self, item, dest_dir, progress_cb=None, cancel_event=None):
|
def download(self, item, dest_dir, progress_cb=None, cancel_event=None):
|
||||||
@@ -492,11 +531,9 @@ class NoPayStationSource(Source):
|
|||||||
dest_dir = Path(dest_dir)
|
dest_dir = Path(dest_dir)
|
||||||
dest_dir.mkdir(parents=True, exist_ok=True)
|
dest_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
# The bundled Python decryptor handles PSP/PSX/themes/DLC directly;
|
# The bundled Python decryptor handles PSP/PSX/themes/DLC directly.
|
||||||
# pkg2zip is only an optional fallback if a binary happens to be
|
|
||||||
# configured (and only supports games/PSX).
|
|
||||||
pkg2zip = nopaystation.find_pkg2zip(self.pkg2zip)
|
|
||||||
title_id = item.get("title_id") or item.get("content_id") or ""
|
title_id = item.get("title_id") or item.get("content_id") or ""
|
||||||
|
item_ct = item.get("content_type") or self.content_type
|
||||||
pkg_name = re.sub(r"[^A-Za-z0-9_-]", "", title_id) or "pkg"
|
pkg_name = re.sub(r"[^A-Za-z0-9_-]", "", title_id) or "pkg"
|
||||||
tmp = Path(tempfile.mkdtemp(prefix="nps-download-"))
|
tmp = Path(tempfile.mkdtemp(prefix="nps-download-"))
|
||||||
pkg = tmp / f"{pkg_name}.pkg"
|
pkg = tmp / f"{pkg_name}.pkg"
|
||||||
@@ -504,10 +541,10 @@ class NoPayStationSource(Source):
|
|||||||
if progress_cb is not None:
|
if progress_cb is not None:
|
||||||
progress_cb("Downloading", 0.0, "")
|
progress_cb("Downloading", 0.0, "")
|
||||||
download_url(item["pkg_url"], pkg, None, progress_cb, cancel_event)
|
download_url(item["pkg_url"], pkg, None, progress_cb, cancel_event)
|
||||||
kind_hint = self.content_type if self.content_type in ("theme", "dlc") else None
|
kind_hint = item_ct if item_ct in ("theme", "dlc") else None
|
||||||
folder = nopaystation.extract_pkg(pkg, title_id, dest_dir, pkg2zip,
|
folder = nopaystation.extract_pkg(pkg, title_id, dest_dir,
|
||||||
kind_hint, progress_cb, cancel_event)
|
kind_hint, progress_cb, cancel_event)
|
||||||
if self.content_type in ("theme", "dlc"):
|
if item_ct in ("theme", "dlc"):
|
||||||
_write_sidecar(folder, item)
|
_write_sidecar(folder, item)
|
||||||
return folder
|
return folder
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
# pkg2zip
|
|
||||||
|
|
||||||
The `pkg2zip.exe` binary in this folder is kept as an optional fallback for
|
|
||||||
decrypting NoPayStation `.pkg` files (PSP / PSX / PS3 / PSVita content). The
|
|
||||||
app normally uses its own pure-Python decryptor (`app/pkg.py`) and only runs
|
|
||||||
this binary if that fails.
|
|
||||||
|
|
||||||
- Project: <https://github.com/mmozeiko/pkg2zip>
|
|
||||||
- Author: Marcin Mikołajczak (mmozeiko)
|
|
||||||
- Version: v1.8 (bundled)
|
|
||||||
- License: MIT
|
|
||||||
|
|
||||||
The Windows binary is run through Wine on Linux/macOS (see
|
|
||||||
`app/nopaystation.py`).
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2017 Marcin Mikołajczak (mmozeiko)
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
+11
-10
@@ -1,12 +1,12 @@
|
|||||||
services:
|
services:
|
||||||
psp-preserve:
|
psppt:
|
||||||
build: .
|
build: .
|
||||||
container_name: psp-preserve
|
container_name: psppt
|
||||||
# Attach to Unraid's macvlan bridge so the API gets its own LAN IP.
|
# Attach to Unraid's macvlan bridge so the API gets its own LAN IP.
|
||||||
# Plain HTTP for now; see Caddyfile to add Let's Encrypt TLS later.
|
# Plain HTTP for now; see Caddyfile to add Let's Encrypt TLS later.
|
||||||
networks:
|
networks:
|
||||||
br0:
|
br0:
|
||||||
ipv4_address: 192.168.10.100
|
ipv4_address: ${PSP_LAN_IP}
|
||||||
environment:
|
environment:
|
||||||
PSP_DATA_DIR: /data
|
PSP_DATA_DIR: /data
|
||||||
PSP_DATS_DIR: /data/dats
|
PSP_DATS_DIR: /data/dats
|
||||||
@@ -15,15 +15,16 @@ services:
|
|||||||
PSP_GAMES_ROOTS: /data/umd_games
|
PSP_GAMES_ROOTS: /data/umd_games
|
||||||
PSP_VIDEO_ROOTS: /data/umd_videos
|
PSP_VIDEO_ROOTS: /data/umd_videos
|
||||||
PSP_STORE_DIR: /data/store
|
PSP_STORE_DIR: /data/store
|
||||||
# Secret token the desktop app sends as `Authorization: Bearer <token>`.
|
PSP_STORE_VIDEOS_DIR: /data/store_videos
|
||||||
# Set via a .env file next to this compose file.
|
PSP_ADMIN_USERNAME: ${PSP_ADMIN_USERNAME:-admin}
|
||||||
PSP_API_TOKEN: ${PSP_API_TOKEN:-}
|
PSP_ADMIN_PASSWORD: ${PSP_ADMIN_PASSWORD:-admin}
|
||||||
volumes:
|
volumes:
|
||||||
- ./data:/data
|
- ./data:/data
|
||||||
# Adjust host paths to your Unraid share layout:
|
# Host paths come from .env (see .env.example):
|
||||||
- /mnt/user/downloads/Sony - PlayStation Portable:/data/store:ro
|
- ${PSP_STORE_HOST}:/data/store
|
||||||
- /mnt/user/psp/umd_games:/data/umd_games:ro
|
- ${PSP_STORE_VIDEOS_HOST}:/data/store_videos
|
||||||
- /mnt/user/psp/umd_videos:/data/umd_videos:ro
|
- ${PSP_UMD_GAMES_HOST}:/data/umd_games:ro
|
||||||
|
- ${PSP_UMD_VIDEOS_HOST}:/data/umd_videos:ro
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 273 B |
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 689 KiB After Width: | Height: | Size: 683 KiB |
Executable
+81
@@ -0,0 +1,81 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Install psppt to a system prefix.
|
||||||
|
#
|
||||||
|
# FHS-friendly layout:
|
||||||
|
# $PREFIX/bin/psppt symlink -> payload binary
|
||||||
|
# $PREFIX/lib/psppt/ app payload (binary + lib/)
|
||||||
|
# $PREFIX/share/applications/ desktop entry
|
||||||
|
# $PREFIX/share/icons/hicolor/256x256/apps/ app icon
|
||||||
|
#
|
||||||
|
# The PyInstaller onedir build keeps the executable and its `lib/` contents
|
||||||
|
# directory side by side, so both live under $PREFIX/lib/psppt/ and a
|
||||||
|
# symlink exposes the binary at $PREFIX/bin/psppt.
|
||||||
|
#
|
||||||
|
# Usage (run from inside the extracted tarball):
|
||||||
|
# sudo ./install.sh # install to /usr/local (default)
|
||||||
|
# sudo ./install.sh --prefix=/usr # install to /usr
|
||||||
|
# sudo ./install.sh --uninstall # remove from the default prefix
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
PREFIX=/usr/local
|
||||||
|
MODE=install
|
||||||
|
|
||||||
|
for arg in "$@"; do
|
||||||
|
case "$arg" in
|
||||||
|
--prefix=*) PREFIX=${arg#--prefix=} ;;
|
||||||
|
--uninstall) MODE=uninstall ;;
|
||||||
|
*) echo "unknown argument: $arg" >&2; exit 2 ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
SRC_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||||
|
LIBDIR="$PREFIX/lib/psppt"
|
||||||
|
BINDIR="$PREFIX/bin"
|
||||||
|
APPDIR="$PREFIX/share/applications"
|
||||||
|
ICONDIR="$PREFIX/share/icons/hicolor/256x256/apps"
|
||||||
|
APP_BIN="$LIBDIR/psppt"
|
||||||
|
|
||||||
|
require_root() {
|
||||||
|
if [ "$(id -u)" -ne 0 ]; then
|
||||||
|
echo "run as root (e.g. sudo)" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
uninstall() {
|
||||||
|
rm -f "$BINDIR/psppt"
|
||||||
|
rm -f "$APPDIR/psppt.desktop"
|
||||||
|
rm -f "$ICONDIR/psppt.png"
|
||||||
|
rm -rf "$LIBDIR"
|
||||||
|
echo "Uninstalled from $PREFIX"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ "$MODE" = uninstall ]; then
|
||||||
|
require_root
|
||||||
|
uninstall
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
require_root
|
||||||
|
|
||||||
|
# The tarball ships these next to this script.
|
||||||
|
for f in psppt lib psppt.desktop app-icon.png; do
|
||||||
|
if [ ! -e "$SRC_DIR/$f" ]; then
|
||||||
|
echo "missing $f (run install.sh from inside the extracted tarball)" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
mkdir -p "$LIBDIR" "$BINDIR" "$APPDIR" "$ICONDIR"
|
||||||
|
rm -rf "$LIBDIR"
|
||||||
|
mkdir -p "$LIBDIR"
|
||||||
|
cp -a "$SRC_DIR/psppt" "$LIBDIR/psppt"
|
||||||
|
cp -a "$SRC_DIR/lib" "$LIBDIR/lib"
|
||||||
|
install -m 0644 "$SRC_DIR/psppt.desktop" "$APPDIR/psppt.desktop"
|
||||||
|
install -m 0644 "$SRC_DIR/app-icon.png" "$ICONDIR/psppt.png"
|
||||||
|
ln -sfn "$APP_BIN" "$BINDIR/psppt"
|
||||||
|
|
||||||
|
echo "Installed to $PREFIX"
|
||||||
|
echo " binary: $BINDIR/psppt -> $APP_BIN"
|
||||||
|
echo " payload: $LIBDIR"
|
||||||
|
echo " desktop: $APPDIR/psppt.desktop"
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
[Desktop Entry]
|
||||||
|
Type=Application
|
||||||
|
Name=psppt
|
||||||
|
Comment=Preserve and manage your PSP library
|
||||||
|
Exec=psppt
|
||||||
|
Icon=psppt
|
||||||
|
Terminal=false
|
||||||
|
Categories=Utility;AudioVideo;
|
||||||
|
StartupWMClass=psppt
|
||||||
+65
@@ -0,0 +1,65 @@
|
|||||||
|
# -*- mode: python ; coding: utf-8 -*-
|
||||||
|
"""PyInstaller spec: build psppt (onedir).
|
||||||
|
|
||||||
|
Bundles the read-only resources (DATs, PS1 loader, cover templates, index
|
||||||
|
catalogs, icons) under ``lib/`` next to the executable. User-writable data
|
||||||
|
(credentials, manual covers, PS1 templates, NPS cache, library DB, cover
|
||||||
|
cache) lives in the OS state dir at runtime — see ``app/config.py``.
|
||||||
|
|
||||||
|
Usage: pyinstaller --clean --noconfirm psppt.spec
|
||||||
|
Output: dist/psppt/
|
||||||
|
"""
|
||||||
|
from PyInstaller.utils.hooks import collect_dynamic_libs, collect_submodules
|
||||||
|
|
||||||
|
datas = [
|
||||||
|
("data/dats", "data/dats"),
|
||||||
|
("data/loader", "data/loader"),
|
||||||
|
("data/supplement.json", "data"),
|
||||||
|
("data/covers/libretro-index.json", "data/covers"),
|
||||||
|
("data/covers/openvgdb-index.json", "data/covers"),
|
||||||
|
("data/covers/UMD_COVER_TEMPLATE.png", "data/covers"),
|
||||||
|
("data/covers/UMD_COVER_TEMPLATE_FEATURE.png", "data/covers"),
|
||||||
|
("data/covers/UMD_GAME_COVER_TEMPLATE.png", "data/covers"),
|
||||||
|
("img/app-icon.png", "img"),
|
||||||
|
("img/chevron.png", "img"),
|
||||||
|
("packaging/psppt.desktop", "."),
|
||||||
|
]
|
||||||
|
|
||||||
|
a = Analysis(
|
||||||
|
["run.py"],
|
||||||
|
pathex=[],
|
||||||
|
binaries=collect_dynamic_libs("curl_cffi"),
|
||||||
|
datas=datas,
|
||||||
|
hiddenimports=collect_submodules("curl_cffi"),
|
||||||
|
hookspath=[],
|
||||||
|
hooksconfig={},
|
||||||
|
runtime_hooks=[],
|
||||||
|
excludes=["tkinter", "unittest", "pydoc"],
|
||||||
|
noarchive=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
pyz = PYZ(a.pure)
|
||||||
|
|
||||||
|
exe = EXE(
|
||||||
|
pyz,
|
||||||
|
a.scripts,
|
||||||
|
[],
|
||||||
|
exclude_binaries=True,
|
||||||
|
name="psppt",
|
||||||
|
debug=False,
|
||||||
|
bootloader_ignore_signals=False,
|
||||||
|
strip=False,
|
||||||
|
upx=False,
|
||||||
|
console=False,
|
||||||
|
disable_windowed_traceback=False,
|
||||||
|
contents_directory="lib",
|
||||||
|
)
|
||||||
|
|
||||||
|
coll = COLLECT(
|
||||||
|
exe,
|
||||||
|
a.binaries,
|
||||||
|
a.datas,
|
||||||
|
strip=False,
|
||||||
|
upx=False,
|
||||||
|
name="psppt",
|
||||||
|
)
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# Build dependencies (pinned for reproducible CI builds).
|
||||||
|
# PySide6 is pinned to 6.8.3: newer 6.11.x bundles a Qt6Core.dll that imports
|
||||||
|
# icuuc.dll on Windows, which is not shipped and crashes at startup.
|
||||||
|
pyinstaller>=6.11
|
||||||
|
PySide6==6.8.3
|
||||||
|
curl_cffi>=0.7
|
||||||
|
pycryptodome>=3.20
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fastapi>=0.110
|
||||||
|
uvicorn[standard]>=0.29
|
||||||
|
jinja2>=3.1
|
||||||
|
python-multipart>=0.0.9
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
"""PyInstaller entry point.
|
||||||
|
|
||||||
|
Runs the GUI the same way ``python -m app.main`` does, but as a plain script
|
||||||
|
so PyInstaller can build it (relative imports inside ``app`` won't resolve when
|
||||||
|
a module file is executed directly, hence this top-level launcher).
|
||||||
|
"""
|
||||||
|
from app.main import main
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
raise SystemExit(main())
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
# Wine-based Gitea Actions runner: builds Windows binaries on a Linux host.
|
||||||
|
#
|
||||||
|
# Jobs run in "host" mode inside this container, where a Windows CPython 3.12
|
||||||
|
# (running under Wine) plus PyInstaller produce the .exe. Node.js and git are
|
||||||
|
# included so the stock JS actions (actions/checkout, actions/upload-artifact)
|
||||||
|
# work as-is.
|
||||||
|
FROM debian:bookworm-slim
|
||||||
|
|
||||||
|
ENV DEBIAN_FRONTEND=noninteractive \
|
||||||
|
WINEPREFIX=/root/.wine \
|
||||||
|
WINEDEBUG=-all \
|
||||||
|
WINEDLLOVERRIDES="mscoree,mshtml=" \
|
||||||
|
PYTHON_VERSION=3.12.8
|
||||||
|
|
||||||
|
# WineHQ wine-staging (newer than Debian's 8.0, needed for Python 3.12),
|
||||||
|
# node + git for JS actions, and build/package tooling.
|
||||||
|
RUN dpkg --add-architecture i386 \
|
||||||
|
&& apt-get update \
|
||||||
|
&& apt-get install -y --no-install-recommends ca-certificates curl wget gnupg2 \
|
||||||
|
&& mkdir -p /etc/apt/keyrings \
|
||||||
|
&& wget -qO- https://dl.winehq.org/wine-builds/winehq.key | gpg --dearmor -o /etc/apt/keyrings/winehq.gpg \
|
||||||
|
&& echo "deb [signed-by=/etc/apt/keyrings/winehq.gpg] https://dl.winehq.org/wine-builds/debian/ bookworm main" > /etc/apt/sources.list.d/winehq.list \
|
||||||
|
&& apt-get update \
|
||||||
|
&& apt-get install -y --install-recommends winehq-staging \
|
||||||
|
&& apt-get install -y --no-install-recommends unzip zip xvfb xauth cabextract nodejs git \
|
||||||
|
&& apt-get clean && rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# winetricks (standalone script; not packaged in Debian main).
|
||||||
|
RUN wget -qO /usr/local/bin/winetricks \
|
||||||
|
"https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks" \
|
||||||
|
&& chmod +x /usr/local/bin/winetricks
|
||||||
|
|
||||||
|
# Gitea Actions runner (linux-amd64 binary).
|
||||||
|
RUN wget -qO /usr/local/bin/act_runner \
|
||||||
|
"https://gitea.com/gitea/act_runner/releases/download/v0.6.1/act_runner-0.6.1-linux-amd64" \
|
||||||
|
&& chmod +x /usr/local/bin/act_runner
|
||||||
|
|
||||||
|
# MSVC runtime required by PySide6's Qt DLLs (also initializes the Wine prefix).
|
||||||
|
RUN xvfb-run -a winetricks --unattended vcrun2022
|
||||||
|
|
||||||
|
# Windows CPython 3.12 (embeddable zip) + pip.
|
||||||
|
RUN wget -qO /tmp/pyembed.zip \
|
||||||
|
"https://www.python.org/ftp/python/${PYTHON_VERSION}/python-${PYTHON_VERSION}-embed-amd64.zip" \
|
||||||
|
&& mkdir -p /root/.wine/drive_c/Python312 \
|
||||||
|
&& cd /root/.wine/drive_c/Python312 \
|
||||||
|
&& unzip -q /tmp/pyembed.zip \
|
||||||
|
&& rm -f /tmp/pyembed.zip \
|
||||||
|
&& printf 'python312.zip\n.\nimport site\nLib\\site-packages\n' > python312._pth \
|
||||||
|
&& wine "C:\\Python312\\python.exe" --version
|
||||||
|
|
||||||
|
# Convenience wrapper: winpython -> wine C:\Python312\python.exe
|
||||||
|
RUN printf '#!/bin/sh\nexec wine "C:\\Python312\\python.exe" "$@"\n' > /usr/local/bin/winpython \
|
||||||
|
&& chmod +x /usr/local/bin/winpython
|
||||||
|
|
||||||
|
# Bootstrap pip, then pre-install the Windows build deps so CI jobs start fast.
|
||||||
|
RUN wget -qO /tmp/get-pip.py https://bootstrap.pypa.io/get-pip.py \
|
||||||
|
&& wine "C:\\Python312\\python.exe" /tmp/get-pip.py \
|
||||||
|
&& rm -f /tmp/get-pip.py
|
||||||
|
COPY requirements-build.txt /tmp/requirements-build.txt
|
||||||
|
RUN winpython -m pip install --upgrade pip \
|
||||||
|
&& winpython -m pip install -r /tmp/requirements-build.txt \
|
||||||
|
&& rm -f /tmp/requirements-build.txt
|
||||||
|
|
||||||
|
COPY runner/entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||||
|
RUN chmod +x /usr/local/bin/entrypoint.sh
|
||||||
|
|
||||||
|
WORKDIR /data
|
||||||
|
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Register on first run, then run the daemon (host mode).
|
||||||
|
if [ ! -f /data/.runner ]; then
|
||||||
|
echo "Registering Wine runner with Gitea…"
|
||||||
|
act_runner register --no-interactive \
|
||||||
|
--instance "${GITEA_INSTANCE_URL:?GITEA_INSTANCE_URL is required}" \
|
||||||
|
--token "${GITEA_RUNNER_REGISTRATION_TOKEN:?GITEA_RUNNER_REGISTRATION_TOKEN is required}" \
|
||||||
|
--name "${RUNNER_NAME:-windows-builder}" \
|
||||||
|
--labels "${RUNNER_LABELS:-windows:host}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec act_runner daemon
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Package the offline cover zips into a single distributable bundle.
|
||||||
|
|
||||||
|
Outputs ``psppt-covers.zip`` containing ``libretro-covers.zip`` and
|
||||||
|
``openvgdb-covers.zip``. Attach it to the Gitea ``covers`` release; the app
|
||||||
|
downloads it on first run when the user opts in.
|
||||||
|
|
||||||
|
Usage: python3 scripts/make-covers-bundle.py [out-path]
|
||||||
|
"""
|
||||||
|
import sys
|
||||||
|
import zipfile
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
ROOT = Path(__file__).resolve().parent.parent
|
||||||
|
COVERS = ROOT / "data" / "covers"
|
||||||
|
INNER = ("libretro-covers.zip", "openvgdb-covers.zip")
|
||||||
|
|
||||||
|
|
||||||
|
def main(argv):
|
||||||
|
out = Path(argv[1]) if len(argv) > 1 else ROOT / "psppt-covers.zip"
|
||||||
|
missing = [n for n in INNER if not (COVERS / n).exists()]
|
||||||
|
if missing:
|
||||||
|
print(f"missing: {', '.join(missing)} in {COVERS}", file=sys.stderr)
|
||||||
|
return 2
|
||||||
|
# Inner zips are already compressed; store them to avoid recompressing.
|
||||||
|
with zipfile.ZipFile(out, "w", zipfile.ZIP_STORED) as z:
|
||||||
|
for n in INNER:
|
||||||
|
print(f"adding {n} …")
|
||||||
|
z.write(COVERS / n, arcname=n)
|
||||||
|
size = out.stat().st_size / (1 << 20)
|
||||||
|
print(f"wrote {out} ({size:.0f} MB)")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
raise SystemExit(main(sys.argv))
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
"""psppt server package (FastAPI + admin WebUI)."""
|
||||||
+491
@@ -0,0 +1,491 @@
|
|||||||
|
"""REST API for the psppt server (JSON, token-authenticated).
|
||||||
|
|
||||||
|
Endpoints:
|
||||||
|
POST /api/auth/login -> {token, username, role}
|
||||||
|
GET /api/auth/me -> current user
|
||||||
|
POST /api/auth/logout -> revoke current token
|
||||||
|
GET /api/users -> list (admin)
|
||||||
|
POST /api/users -> create (admin)
|
||||||
|
PATCH /api/users/{id} -> update role/password/active (admin)
|
||||||
|
DELETE /api/users/{id} -> delete (admin)
|
||||||
|
GET /api/users/{id}/tokens -> list API tokens (admin or self)
|
||||||
|
DELETE /api/users/{id}/tokens/{tid} -> revoke a token (admin or self)
|
||||||
|
GET /api/releases?system=&q=&limit= -> catalog list
|
||||||
|
GET /api/releases/{id} -> detail + metadata + roms
|
||||||
|
PATCH /api/releases/{id} -> edit metadata (editor+)
|
||||||
|
GET /api/cover/{id} -> cover image
|
||||||
|
POST /api/cover/{id} -> upload/replace cover (editor+)
|
||||||
|
DELETE /api/cover/{id} -> delete cover (editor+)
|
||||||
|
GET /api/store?system=games|videos -> archive list
|
||||||
|
GET /api/store/download/{system}/{name} -> stream archive
|
||||||
|
POST /api/store/upload?system= -> upload archive (editor+)
|
||||||
|
DELETE /api/store/{system}/{name} -> delete archive (editor+)
|
||||||
|
GET /api/stats -> dashboard numbers (admin)
|
||||||
|
"""
|
||||||
|
import json
|
||||||
|
import re
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from fastapi import APIRouter, Depends, File, Header, HTTPException, Query, Request, UploadFile
|
||||||
|
from fastapi.responses import FileResponse, JSONResponse
|
||||||
|
|
||||||
|
from app import covers, store
|
||||||
|
from app.db import get_connection
|
||||||
|
|
||||||
|
from . import config
|
||||||
|
from .security import now_iso, require_role, revoke_token, get_current_user, hash_password, verify_password, issue_token
|
||||||
|
|
||||||
|
router = APIRouter(prefix="/api")
|
||||||
|
|
||||||
|
_META_FIELDS = ("release_date", "developer", "publisher", "genre", "synopsis", "title")
|
||||||
|
_SAFE_NAME_RE = re.compile(r"[^A-Za-z0-9._()\- ]")
|
||||||
|
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
# helpers
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
def _conn():
|
||||||
|
return get_connection()
|
||||||
|
|
||||||
|
|
||||||
|
def _release_system(conn, release_id):
|
||||||
|
row = conn.execute(
|
||||||
|
"SELECT d.system FROM releases r JOIN dats d ON d.id = r.dat_id WHERE r.id = ?",
|
||||||
|
(release_id,),
|
||||||
|
).fetchone()
|
||||||
|
return row["system"] if row else None
|
||||||
|
|
||||||
|
|
||||||
|
def _metadata(conn, release_id, system):
|
||||||
|
row = conn.execute(
|
||||||
|
"SELECT title, meta_json, manual FROM item_info WHERE release_id = ? AND system = ?",
|
||||||
|
(str(release_id), system),
|
||||||
|
).fetchone()
|
||||||
|
meta = {}
|
||||||
|
if row and row["meta_json"]:
|
||||||
|
try:
|
||||||
|
meta = json.loads(row["meta_json"])
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
meta = {}
|
||||||
|
if row:
|
||||||
|
meta["title"] = row["title"]
|
||||||
|
meta["manual"] = bool(row["manual"])
|
||||||
|
return meta
|
||||||
|
|
||||||
|
|
||||||
|
def _save_metadata(conn, release_id, system, fields):
|
||||||
|
key = str(release_id)
|
||||||
|
row = conn.execute(
|
||||||
|
"SELECT meta_json FROM item_info WHERE release_id = ? AND system = ?", (key, system)
|
||||||
|
).fetchone()
|
||||||
|
meta = {}
|
||||||
|
if row and row["meta_json"]:
|
||||||
|
try:
|
||||||
|
meta = json.loads(row["meta_json"])
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
meta = {}
|
||||||
|
meta.update(fields)
|
||||||
|
title = fields.get("title") or meta.get("title") or ""
|
||||||
|
conn.execute(
|
||||||
|
"INSERT INTO item_info (release_id, system, title, meta_json, manual, updated_at) "
|
||||||
|
"VALUES (?, ?, ?, ?, 1, ?) "
|
||||||
|
"ON CONFLICT(release_id, system) DO UPDATE SET "
|
||||||
|
"title = excluded.title, meta_json = excluded.meta_json, manual = 1, updated_at = excluded.updated_at",
|
||||||
|
(key, system, title, json.dumps(meta, ensure_ascii=False), now_iso()),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _cover_paths(release_id, system):
|
||||||
|
base = config.COVERS_DIR / system / str(release_id)
|
||||||
|
return base, [base.with_suffix(ext) for ext in (".png", ".jpg", ".jpeg", ".webp")]
|
||||||
|
|
||||||
|
|
||||||
|
def _find_cover(release_id, system):
|
||||||
|
base, candidates = _cover_paths(release_id, system)
|
||||||
|
for p in candidates:
|
||||||
|
if p.exists():
|
||||||
|
return p
|
||||||
|
return base.with_suffix(".png")
|
||||||
|
|
||||||
|
|
||||||
|
def _save_cover(release_id, system, data):
|
||||||
|
base, candidates = _cover_paths(release_id, system)
|
||||||
|
base.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
ext = ".png"
|
||||||
|
if data[:3] == b"\xff\xd8\xff":
|
||||||
|
ext = ".jpg"
|
||||||
|
elif data[:4] == b"RIFF" and data[8:12] == b"WEBP":
|
||||||
|
ext = ".webp"
|
||||||
|
dest = base.with_suffix(ext)
|
||||||
|
for p in candidates:
|
||||||
|
if p.exists() and p != dest:
|
||||||
|
p.unlink()
|
||||||
|
tmp = dest.with_name(dest.name + ".tmp")
|
||||||
|
tmp.write_bytes(data)
|
||||||
|
tmp.replace(dest)
|
||||||
|
return dest
|
||||||
|
|
||||||
|
|
||||||
|
def _store_root(system):
|
||||||
|
return config.STORE_VIDEOS_ROOT if system == "videos" else config.STORE_ROOT
|
||||||
|
|
||||||
|
|
||||||
|
def _log_download(user, system, name, size):
|
||||||
|
conn = _conn()
|
||||||
|
try:
|
||||||
|
conn.execute(
|
||||||
|
"INSERT INTO download_events (user_id, system, name, bytes, created_at) VALUES (?, ?, ?, ?, ?)",
|
||||||
|
(user["id"] if user else None, system, name, size or 0, now_iso()),
|
||||||
|
)
|
||||||
|
conn.commit()
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
# auth
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
@router.post("/auth/login")
|
||||||
|
def auth_login(payload: dict):
|
||||||
|
username = (payload.get("username") or "").strip()
|
||||||
|
password = payload.get("password") or ""
|
||||||
|
conn = _conn()
|
||||||
|
try:
|
||||||
|
row = conn.execute(
|
||||||
|
"SELECT id, username, password_hash, role, is_active FROM users WHERE username = ?",
|
||||||
|
(username,),
|
||||||
|
).fetchone()
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
if row is None or not row["is_active"] or not verify_password(password, row["password_hash"]):
|
||||||
|
raise HTTPException(status_code=401, detail="Invalid username or password")
|
||||||
|
token = issue_token(row["id"], kind="api", label="desktop")
|
||||||
|
return {"token": token, "username": row["username"], "role": row["role"], "user_id": row["id"]}
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/auth/me")
|
||||||
|
def auth_me(user=Depends(get_current_user)):
|
||||||
|
return user
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/auth/logout")
|
||||||
|
def auth_logout(request: Request, authorization: str = Header(default="")):
|
||||||
|
token = ""
|
||||||
|
if authorization.startswith("Bearer "):
|
||||||
|
token = authorization[7:].strip()
|
||||||
|
else:
|
||||||
|
token = request.cookies.get("psppt_session", "")
|
||||||
|
if token:
|
||||||
|
revoke_token(token)
|
||||||
|
return {"ok": True}
|
||||||
|
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
# users (admin)
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
@router.get("/users")
|
||||||
|
def users_list(user=Depends(require_role("admin"))):
|
||||||
|
conn = _conn()
|
||||||
|
try:
|
||||||
|
rows = conn.execute(
|
||||||
|
"SELECT id, username, role, is_active, created_at, last_login_at FROM users ORDER BY username"
|
||||||
|
).fetchall()
|
||||||
|
return {"items": [dict(r) for r in rows]}
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/users")
|
||||||
|
def users_create(payload: dict, user=Depends(require_role("admin"))):
|
||||||
|
username = (payload.get("username") or "").strip()
|
||||||
|
password = payload.get("password") or ""
|
||||||
|
role = payload.get("role") or "user"
|
||||||
|
if not username or not password:
|
||||||
|
raise HTTPException(status_code=400, detail="username and password are required")
|
||||||
|
if role not in ("admin", "editor", "user"):
|
||||||
|
raise HTTPException(status_code=400, detail="invalid role")
|
||||||
|
conn = _conn()
|
||||||
|
try:
|
||||||
|
try:
|
||||||
|
conn.execute(
|
||||||
|
"INSERT INTO users (username, password_hash, role, is_active, created_at) VALUES (?, ?, ?, 1, ?)",
|
||||||
|
(username, hash_password(password), role, now_iso()),
|
||||||
|
)
|
||||||
|
conn.commit()
|
||||||
|
except Exception:
|
||||||
|
raise HTTPException(status_code=409, detail="username already exists")
|
||||||
|
row = conn.execute("SELECT id, username, role, is_active FROM users WHERE username = ?", (username,)).fetchone()
|
||||||
|
return dict(row)
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
@router.patch("/users/{user_id}")
|
||||||
|
def users_update(user_id: int, payload: dict, user=Depends(require_role("admin"))):
|
||||||
|
conn = _conn()
|
||||||
|
try:
|
||||||
|
row = conn.execute("SELECT id FROM users WHERE id = ?", (user_id,)).fetchone()
|
||||||
|
if row is None:
|
||||||
|
raise HTTPException(status_code=404, detail="not found")
|
||||||
|
if "role" in payload:
|
||||||
|
if payload["role"] not in ("admin", "editor", "user"):
|
||||||
|
raise HTTPException(status_code=400, detail="invalid role")
|
||||||
|
conn.execute("UPDATE users SET role = ? WHERE id = ?", (payload["role"], user_id))
|
||||||
|
if "is_active" in payload:
|
||||||
|
conn.execute("UPDATE users SET is_active = ? WHERE id = ?", (1 if payload["is_active"] else 0, user_id))
|
||||||
|
if payload.get("password"):
|
||||||
|
conn.execute("UPDATE users SET password_hash = ? WHERE id = ?", (hash_password(payload["password"]), user_id))
|
||||||
|
conn.commit()
|
||||||
|
row = conn.execute("SELECT id, username, role, is_active FROM users WHERE id = ?", (user_id,)).fetchone()
|
||||||
|
return dict(row)
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
@router.delete("/users/{user_id}")
|
||||||
|
def users_delete(user_id: int, user=Depends(require_role("admin"))):
|
||||||
|
if user_id == user["id"]:
|
||||||
|
raise HTTPException(status_code=400, detail="cannot delete yourself")
|
||||||
|
conn = _conn()
|
||||||
|
try:
|
||||||
|
conn.execute("DELETE FROM users WHERE id = ?", (user_id,))
|
||||||
|
conn.commit()
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
return {"ok": True}
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/users/{user_id}/tokens")
|
||||||
|
def users_tokens(user_id: int, user=Depends(require_role("admin"))):
|
||||||
|
conn = _conn()
|
||||||
|
try:
|
||||||
|
rows = conn.execute(
|
||||||
|
"SELECT id, label, kind, created_at, last_used_at, expires_at, revoked_at FROM api_tokens "
|
||||||
|
"WHERE user_id = ? ORDER BY id DESC",
|
||||||
|
(user_id,),
|
||||||
|
).fetchall()
|
||||||
|
return {"items": [dict(r) for r in rows]}
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
@router.delete("/users/{user_id}/tokens/{token_id}")
|
||||||
|
def users_revoke_token(user_id: int, token_id: int, user=Depends(require_role("admin"))):
|
||||||
|
conn = _conn()
|
||||||
|
try:
|
||||||
|
conn.execute(
|
||||||
|
"UPDATE api_tokens SET revoked_at = ? WHERE id = ? AND user_id = ?",
|
||||||
|
(now_iso(), token_id, user_id),
|
||||||
|
)
|
||||||
|
conn.commit()
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
return {"ok": True}
|
||||||
|
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
# releases / catalog
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
@router.get("/releases")
|
||||||
|
def releases_list(system: str = Query(default=""), q: str = Query(default=""), limit: int = 50, offset: int = 0):
|
||||||
|
limit = max(1, min(limit, 500))
|
||||||
|
offset = max(0, offset)
|
||||||
|
sql = "SELECT r.id, d.system, r.name, r.region, r.serial FROM releases r JOIN dats d ON d.id = r.dat_id"
|
||||||
|
where, params = [], []
|
||||||
|
if system:
|
||||||
|
where.append("d.system = ?")
|
||||||
|
params.append(system)
|
||||||
|
if q:
|
||||||
|
where.append("r.name LIKE ?")
|
||||||
|
params.append(f"%{q}%")
|
||||||
|
if where:
|
||||||
|
sql += " WHERE " + " AND ".join(where)
|
||||||
|
sql += " ORDER BY r.name LIMIT ? OFFSET ?"
|
||||||
|
params += [limit, offset]
|
||||||
|
conn = _conn()
|
||||||
|
try:
|
||||||
|
rows = conn.execute(sql, params).fetchall()
|
||||||
|
items = []
|
||||||
|
for r in rows:
|
||||||
|
d = dict(r)
|
||||||
|
d["cover"] = f"/api/cover/{d['id']}"
|
||||||
|
items.append(d)
|
||||||
|
return {"items": items, "limit": limit, "offset": offset}
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/releases/{release_id}")
|
||||||
|
def releases_detail(release_id: int):
|
||||||
|
conn = _conn()
|
||||||
|
try:
|
||||||
|
rel = conn.execute(
|
||||||
|
"SELECT r.id, d.system, r.name, r.description, r.region, r.serial "
|
||||||
|
"FROM releases r JOIN dats d ON d.id = r.dat_id WHERE r.id = ?",
|
||||||
|
(release_id,),
|
||||||
|
).fetchone()
|
||||||
|
if rel is None:
|
||||||
|
raise HTTPException(status_code=404, detail="not found")
|
||||||
|
roms = conn.execute(
|
||||||
|
"SELECT name, size, crc32, md5, sha1, serial FROM roms WHERE release_id = ?", (release_id,)
|
||||||
|
).fetchall()
|
||||||
|
result = dict(rel)
|
||||||
|
result["cover"] = f"/api/cover/{release_id}"
|
||||||
|
result["roms"] = [dict(r) for r in roms]
|
||||||
|
result["meta"] = _metadata(conn, release_id, rel["system"])
|
||||||
|
return result
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
@router.patch("/releases/{release_id}")
|
||||||
|
def releases_update(release_id: int, payload: dict, user=Depends(require_role("admin", "editor"))):
|
||||||
|
conn = _conn()
|
||||||
|
try:
|
||||||
|
rel = conn.execute(
|
||||||
|
"SELECT r.id, d.system FROM releases r JOIN dats d ON d.id = r.dat_id WHERE r.id = ?",
|
||||||
|
(release_id,),
|
||||||
|
).fetchone()
|
||||||
|
if rel is None:
|
||||||
|
raise HTTPException(status_code=404, detail="not found")
|
||||||
|
# release-table columns
|
||||||
|
for col in ("name", "region", "serial", "description"):
|
||||||
|
if col in payload:
|
||||||
|
conn.execute(f"UPDATE releases SET {col} = ? WHERE id = ?", (payload[col], release_id))
|
||||||
|
# metadata (item_info)
|
||||||
|
meta_fields = {k: payload[k] for k in _META_FIELDS if k in payload}
|
||||||
|
if meta_fields:
|
||||||
|
_save_metadata(conn, release_id, rel["system"], meta_fields)
|
||||||
|
conn.commit()
|
||||||
|
return {"ok": True}
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
# covers
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
@router.get("/cover/{release_id}")
|
||||||
|
def cover_get(release_id: int):
|
||||||
|
conn = _conn()
|
||||||
|
try:
|
||||||
|
system = _release_system(conn, release_id)
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
if system is None:
|
||||||
|
raise HTTPException(status_code=404, detail="not found")
|
||||||
|
path = _find_cover(release_id, system)
|
||||||
|
if not path.exists():
|
||||||
|
raise HTTPException(status_code=404, detail="no cover available")
|
||||||
|
media = "image/jpeg" if path.suffix.lower() in (".jpg", ".jpeg") else "image/png"
|
||||||
|
if path.suffix.lower() == ".webp":
|
||||||
|
media = "image/webp"
|
||||||
|
return FileResponse(path, media_type=media)
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/cover/{release_id}")
|
||||||
|
async def cover_upload(release_id: int, file: UploadFile = File(...), user=Depends(require_role("admin", "editor"))):
|
||||||
|
conn = _conn()
|
||||||
|
try:
|
||||||
|
system = _release_system(conn, release_id)
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
if system is None:
|
||||||
|
raise HTTPException(status_code=404, detail="not found")
|
||||||
|
data = await file.read()
|
||||||
|
if len(data) > 20 * (1 << 20):
|
||||||
|
raise HTTPException(status_code=400, detail="image too large")
|
||||||
|
_save_cover(release_id, system, data)
|
||||||
|
return {"ok": True, "url": f"/api/cover/{release_id}"}
|
||||||
|
|
||||||
|
|
||||||
|
@router.delete("/cover/{release_id}")
|
||||||
|
def cover_delete(release_id: int, user=Depends(require_role("admin", "editor"))):
|
||||||
|
conn = _conn()
|
||||||
|
try:
|
||||||
|
system = _release_system(conn, release_id)
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
if system is None:
|
||||||
|
raise HTTPException(status_code=404, detail="not found")
|
||||||
|
path = _find_cover(release_id, system)
|
||||||
|
if path.exists():
|
||||||
|
path.unlink()
|
||||||
|
return {"ok": True}
|
||||||
|
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
# store
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
@router.get("/store")
|
||||||
|
def store_list(system: str = Query(default="games")):
|
||||||
|
root = _store_root(system)
|
||||||
|
if not root.is_dir():
|
||||||
|
return {"items": [], "count": 0, "system": system}
|
||||||
|
items = [
|
||||||
|
{"name": it["name"], "filename": Path(it["path"]).name, "size": it["size"], "mtime_ns": it["mtime_ns"], "system": system}
|
||||||
|
for it in store.scan(root)
|
||||||
|
]
|
||||||
|
return {"items": items, "count": len(items), "system": system}
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/store/download/{system}/{name}")
|
||||||
|
def store_download(system: str, name: str, user=Depends(get_current_user)):
|
||||||
|
root = _store_root(system).resolve()
|
||||||
|
target = (root / name).resolve()
|
||||||
|
if not target.is_file() or root not in target.parents:
|
||||||
|
raise HTTPException(status_code=404, detail="not found")
|
||||||
|
_log_download(user, system, name, target.stat().st_size)
|
||||||
|
return FileResponse(target, filename=name, media_type="application/octet-stream")
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/store/upload")
|
||||||
|
async def store_upload(system: str = Query(default="games"), file: UploadFile = File(...), user=Depends(require_role("admin", "editor"))):
|
||||||
|
root = _store_root(system)
|
||||||
|
root.mkdir(parents=True, exist_ok=True)
|
||||||
|
safe = _SAFE_NAME_RE.sub("", file.filename or "")
|
||||||
|
if not safe:
|
||||||
|
raise HTTPException(status_code=400, detail="invalid filename")
|
||||||
|
dest = root / safe
|
||||||
|
data = await file.read()
|
||||||
|
dest.write_bytes(data)
|
||||||
|
return {"ok": True, "filename": safe, "size": len(data)}
|
||||||
|
|
||||||
|
|
||||||
|
@router.delete("/store/{system}/{name}")
|
||||||
|
def store_delete(system: str, name: str, user=Depends(require_role("admin", "editor"))):
|
||||||
|
root = _store_root(system).resolve()
|
||||||
|
target = (root / name).resolve()
|
||||||
|
if not target.is_file() or root not in target.parents:
|
||||||
|
raise HTTPException(status_code=404, detail="not found")
|
||||||
|
target.unlink()
|
||||||
|
return {"ok": True}
|
||||||
|
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
# stats (admin)
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
@router.get("/stats")
|
||||||
|
def stats(user=Depends(require_role("admin"))):
|
||||||
|
conn = _conn()
|
||||||
|
try:
|
||||||
|
systems = conn.execute(
|
||||||
|
"SELECT d.system AS system, COUNT(*) AS releases FROM releases r "
|
||||||
|
"JOIN dats d ON d.id = r.dat_id GROUP BY d.system ORDER BY d.system"
|
||||||
|
).fetchall()
|
||||||
|
users = conn.execute("SELECT COUNT(*) AS n FROM users").fetchone()["n"]
|
||||||
|
covers_count = sum(1 for _ in config.COVERS_DIR.rglob("*") if _.is_file()) if config.COVERS_DIR.is_dir() else 0
|
||||||
|
downloads = conn.execute("SELECT COUNT(*) AS n FROM download_events").fetchone()["n"]
|
||||||
|
recent = conn.execute(
|
||||||
|
"SELECT e.system, e.name, e.bytes, e.created_at, u.username FROM download_events e "
|
||||||
|
"LEFT JOIN users u ON u.id = e.user_id ORDER BY e.id DESC LIMIT 20"
|
||||||
|
).fetchall()
|
||||||
|
return {
|
||||||
|
"systems": [dict(r) for r in systems],
|
||||||
|
"users": users,
|
||||||
|
"covers": covers_count,
|
||||||
|
"downloads": downloads,
|
||||||
|
"recent": [dict(r) for r in recent],
|
||||||
|
}
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
"""Server-specific settings (env-driven)."""
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from app.config import COVERS_DIR, DB_PATH, STORE_ROOT
|
||||||
|
|
||||||
|
STORE_VIDEOS_ROOT = Path(os.environ.get("PSP_STORE_VIDEOS_DIR", "/data/store_videos"))
|
||||||
|
ADMIN_USERNAME = os.environ.get("PSP_ADMIN_USERNAME", "admin")
|
||||||
|
ADMIN_PASSWORD = os.environ.get("PSP_ADMIN_PASSWORD", "admin")
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
"""psppt server: FastAPI app assembly."""
|
||||||
|
import logging
|
||||||
|
from contextlib import asynccontextmanager
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from fastapi import FastAPI
|
||||||
|
from fastapi.staticfiles import StaticFiles
|
||||||
|
|
||||||
|
from app.db import init_db
|
||||||
|
|
||||||
|
from . import api, config, web
|
||||||
|
from .security import ensure_admin
|
||||||
|
|
||||||
|
log = logging.getLogger("psppt.server")
|
||||||
|
|
||||||
|
|
||||||
|
@asynccontextmanager
|
||||||
|
async def lifespan(_app: FastAPI):
|
||||||
|
init_db()
|
||||||
|
created = ensure_admin(config.ADMIN_USERNAME, config.ADMIN_PASSWORD)
|
||||||
|
if created:
|
||||||
|
log.warning(
|
||||||
|
"Created initial admin user %r with the configured password — change it now.",
|
||||||
|
config.ADMIN_USERNAME,
|
||||||
|
)
|
||||||
|
yield
|
||||||
|
|
||||||
|
|
||||||
|
app = FastAPI(title="psppt server", lifespan=lifespan)
|
||||||
|
|
||||||
|
app.include_router(api.router)
|
||||||
|
app.include_router(web.router)
|
||||||
|
|
||||||
|
app.mount("/static", StaticFiles(directory=str(Path(__file__).parent / "static")), name="static")
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/health")
|
||||||
|
def health():
|
||||||
|
return {"ok": True}
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
"""Password hashing, API/session tokens, and FastAPI auth dependencies.
|
||||||
|
|
||||||
|
Stdlib-only crypto: PBKDF2-SHA256 for passwords, SHA-256 hashed bearer tokens
|
||||||
|
for both the desktop client (kind="api") and the WebUI session (kind="session").
|
||||||
|
"""
|
||||||
|
import hashlib
|
||||||
|
import secrets
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
|
from fastapi import Depends, Header, HTTPException, Request, status
|
||||||
|
|
||||||
|
from app.db import get_connection
|
||||||
|
|
||||||
|
_PBKDF2_ITERATIONS = 600_000
|
||||||
|
|
||||||
|
ADMIN_ROLE = "admin"
|
||||||
|
EDITOR_ROLE = "editor"
|
||||||
|
USER_ROLE = "user"
|
||||||
|
ROLES = (ADMIN_ROLE, EDITOR_ROLE, USER_ROLE)
|
||||||
|
|
||||||
|
|
||||||
|
def now_iso():
|
||||||
|
return datetime.now(timezone.utc).isoformat(timespec="seconds")
|
||||||
|
|
||||||
|
|
||||||
|
def hash_password(password: str) -> str:
|
||||||
|
salt = secrets.token_bytes(16)
|
||||||
|
digest = hashlib.pbkdf2_hmac("sha256", password.encode("utf-8"), salt, _PBKDF2_ITERATIONS)
|
||||||
|
return f"pbkdf2_sha256${_PBKDF2_ITERATIONS}${salt.hex()}${digest.hex()}"
|
||||||
|
|
||||||
|
|
||||||
|
def verify_password(password: str, stored: str) -> bool:
|
||||||
|
try:
|
||||||
|
scheme, iterations, salt_hex, digest_hex = stored.split("$")
|
||||||
|
if scheme != "pbkdf2_sha256":
|
||||||
|
return False
|
||||||
|
salt = bytes.fromhex(salt_hex)
|
||||||
|
expected = bytes.fromhex(digest_hex)
|
||||||
|
actual = hashlib.pbkdf2_hmac("sha256", password.encode("utf-8"), salt, int(iterations))
|
||||||
|
return secrets.compare_digest(actual, expected)
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def _hash_token(raw: str) -> str:
|
||||||
|
return hashlib.sha256(raw.encode("utf-8")).hexdigest()
|
||||||
|
|
||||||
|
|
||||||
|
def issue_token(user_id: int, kind: str = "api", label: str = "", expires_at: str = "") -> str:
|
||||||
|
"""Create a token row and return the raw token (only shown once)."""
|
||||||
|
raw = secrets.token_urlsafe(32)
|
||||||
|
conn = get_connection()
|
||||||
|
try:
|
||||||
|
conn.execute(
|
||||||
|
"INSERT INTO api_tokens (user_id, token_hash, label, kind, created_at, last_used_at, expires_at, revoked_at) "
|
||||||
|
"VALUES (?, ?, ?, ?, ?, ?, ?, NULL)",
|
||||||
|
(user_id, _hash_token(raw), label, kind, now_iso(), now_iso(), expires_at or None),
|
||||||
|
)
|
||||||
|
conn.commit()
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
return raw
|
||||||
|
|
||||||
|
|
||||||
|
def revoke_token(raw: str) -> None:
|
||||||
|
conn = get_connection()
|
||||||
|
try:
|
||||||
|
conn.execute(
|
||||||
|
"UPDATE api_tokens SET revoked_at = ? WHERE token_hash = ?",
|
||||||
|
(now_iso(), _hash_token(raw)),
|
||||||
|
)
|
||||||
|
conn.commit()
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
def get_user_by_token(raw: str):
|
||||||
|
if not raw:
|
||||||
|
return None
|
||||||
|
conn = get_connection()
|
||||||
|
try:
|
||||||
|
row = conn.execute(
|
||||||
|
"SELECT u.id, u.username, u.role, u.is_active FROM api_tokens t "
|
||||||
|
"JOIN users u ON u.id = t.user_id "
|
||||||
|
"WHERE t.token_hash = ? AND t.revoked_at IS NULL "
|
||||||
|
"AND (t.expires_at IS NULL OR t.expires_at = '' OR t.expires_at > ?)",
|
||||||
|
(_hash_token(raw), now_iso()),
|
||||||
|
).fetchone()
|
||||||
|
if row is None or not row["is_active"]:
|
||||||
|
return None
|
||||||
|
conn.execute(
|
||||||
|
"UPDATE api_tokens SET last_used_at = ? WHERE token_hash = ?",
|
||||||
|
(now_iso(), _hash_token(raw)),
|
||||||
|
)
|
||||||
|
conn.commit()
|
||||||
|
return dict(row)
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
def get_current_user(request: Request, authorization: str = Header(default="")):
|
||||||
|
"""Authenticate via ``Authorization: Bearer`` (client) or session cookie (WebUI)."""
|
||||||
|
token = ""
|
||||||
|
if authorization.startswith("Bearer "):
|
||||||
|
token = authorization[7:].strip()
|
||||||
|
else:
|
||||||
|
token = request.cookies.get("psppt_session", "")
|
||||||
|
user = get_user_by_token(token)
|
||||||
|
if user is None:
|
||||||
|
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Not authenticated")
|
||||||
|
return user
|
||||||
|
|
||||||
|
|
||||||
|
def require_role(*roles):
|
||||||
|
"""Dependency factory: only users with one of ``roles`` may pass."""
|
||||||
|
def dependency(user=Depends(get_current_user)):
|
||||||
|
if user["role"] not in roles:
|
||||||
|
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Insufficient permissions")
|
||||||
|
return user
|
||||||
|
return dependency
|
||||||
|
|
||||||
|
|
||||||
|
def ensure_admin(username: str, password: str) -> bool:
|
||||||
|
"""Create the initial admin account when the users table is empty."""
|
||||||
|
conn = get_connection()
|
||||||
|
try:
|
||||||
|
count = conn.execute("SELECT COUNT(*) AS n FROM users").fetchone()["n"]
|
||||||
|
if count == 0:
|
||||||
|
conn.execute(
|
||||||
|
"INSERT INTO users (username, password_hash, role, is_active, created_at) "
|
||||||
|
"VALUES (?, ?, 'admin', 1, ?)",
|
||||||
|
(username, hash_password(password), now_iso()),
|
||||||
|
)
|
||||||
|
conn.commit()
|
||||||
|
return True
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
return False
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
:root { color-scheme: dark; }
|
||||||
|
* { box-sizing: border-box; }
|
||||||
|
body {
|
||||||
|
margin: 0; font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
|
||||||
|
background: #12131a; color: #e8e9ed; line-height: 1.45;
|
||||||
|
}
|
||||||
|
nav {
|
||||||
|
display: flex; align-items: center; gap: 16px; padding: 10px 20px;
|
||||||
|
background: #1a1c26; border-bottom: 1px solid #2a2d3a;
|
||||||
|
}
|
||||||
|
nav a { color: #9fb4ff; text-decoration: none; font-weight: 600; }
|
||||||
|
nav a:hover { color: #c7d3ff; }
|
||||||
|
nav .spacer { flex: 1; }
|
||||||
|
nav .who { color: #8a8da0; font-size: 0.9em; }
|
||||||
|
main { max-width: 1100px; margin: 0 auto; padding: 24px 20px 60px; }
|
||||||
|
h1 { font-size: 1.6em; margin-top: 0; }
|
||||||
|
h2 { font-size: 1.15em; margin-top: 28px; color: #b9bdd0; }
|
||||||
|
.card { background: #1a1c26; border: 1px solid #2a2d3a; border-radius: 10px; padding: 24px; }
|
||||||
|
.card.narrow { max-width: 380px; margin: 60px auto; }
|
||||||
|
form label { display: block; margin: 10px 0 2px; font-size: 0.85em; color: #9aa0b5; }
|
||||||
|
input, select, textarea {
|
||||||
|
width: 100%; padding: 8px 10px; border-radius: 6px; border: 1px solid #34384a;
|
||||||
|
background: #0f1016; color: #e8e9ed; font: inherit;
|
||||||
|
}
|
||||||
|
form.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
|
||||||
|
form.inline input, form.inline select { width: auto; }
|
||||||
|
form.filters input { width: 220px; }
|
||||||
|
form.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 18px; max-width: 760px; }
|
||||||
|
form.grid .wide { grid-column: 1 / -1; }
|
||||||
|
button {
|
||||||
|
padding: 8px 16px; border: 0; border-radius: 6px; cursor: pointer;
|
||||||
|
background: #3b5bdb; color: #fff; font: inherit; font-weight: 600;
|
||||||
|
}
|
||||||
|
button:hover { background: #4c6ef5; }
|
||||||
|
button.ghost { background: transparent; border: 1px solid #34384a; color: #c7cadb; }
|
||||||
|
button.danger { background: #b03a3a; }
|
||||||
|
button.danger:hover { background: #d14a4a; }
|
||||||
|
table { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 0.95em; }
|
||||||
|
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid #262936; }
|
||||||
|
th { color: #9aa0b5; font-weight: 600; }
|
||||||
|
tr:hover td { background: #171923; }
|
||||||
|
.cards { display: flex; gap: 14px; flex-wrap: wrap; }
|
||||||
|
.stat { flex: 1; min-width: 120px; background: #1a1c26; border: 1px solid #2a2d3a;
|
||||||
|
border-radius: 10px; padding: 16px; text-align: center; }
|
||||||
|
.stat b { display: block; font-size: 1.7em; }
|
||||||
|
.stat span { color: #8a8da0; font-size: 0.85em; }
|
||||||
|
.error { color: #ff8787; }
|
||||||
|
.muted { color: #8a8da0; }
|
||||||
|
.cover { max-width: 200px; border-radius: 8px; border: 1px solid #2a2d3a; margin-bottom: 10px; }
|
||||||
|
code { background: #0f1016; padding: 2px 6px; border-radius: 4px; }
|
||||||
|
label.check { display: flex; align-items: center; gap: 6px; margin: 0; }
|
||||||
|
label.check input { width: auto; }
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>{% block title %}psppt server{% endblock %}</title>
|
||||||
|
<link rel="stylesheet" href="/static/app.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{% if user %}
|
||||||
|
<nav>
|
||||||
|
<a href="/dashboard">Dashboard</a>
|
||||||
|
<a href="/releases">Games & Videos</a>
|
||||||
|
{% if user.role in ('admin', 'editor') %}<a href="/store">Store</a>{% endif %}
|
||||||
|
{% if user.role == 'admin' %}<a href="/users">Users</a>{% endif %}
|
||||||
|
{% if user.role == 'admin' %}<a href="/settings">Settings</a>{% endif %}
|
||||||
|
<span class="spacer"></span>
|
||||||
|
<span class="who">{{ user.username }} · {{ user.role }}</span>
|
||||||
|
<form method="post" action="/logout" class="inline"><button class="ghost">Logout</button></form>
|
||||||
|
</nav>
|
||||||
|
{% endif %}
|
||||||
|
<main>
|
||||||
|
{% block content %}{% endblock %}
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% block title %}Dashboard · psppt{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<h1>Dashboard</h1>
|
||||||
|
<div class="cards">
|
||||||
|
<div class="stat"><b>{{ users }}</b><span>users</span></div>
|
||||||
|
<div class="stat"><b>{{ downloads }}</b><span>downloads</span></div>
|
||||||
|
<div class="stat"><b>{{ covers }}</b><span>covers</span></div>
|
||||||
|
<div class="stat"><b>{{ store_games }}</b><span>game archives</span></div>
|
||||||
|
<div class="stat"><b>{{ store_videos }}</b><span>video archives</span></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h2>Catalog</h2>
|
||||||
|
<ul>
|
||||||
|
{% for s in systems %}
|
||||||
|
<li>{{ s.system }} — {{ s.releases }} release(s)</li>
|
||||||
|
{% else %}
|
||||||
|
<li>No catalog data ingested yet.</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h2>Recent downloads</h2>
|
||||||
|
<table>
|
||||||
|
<tr><th>When</th><th>User</th><th>System</th><th>Name</th><th>Size</th></tr>
|
||||||
|
{% for r in recent %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ r.created_at }}</td>
|
||||||
|
<td>{{ r.username or '—' }}</td>
|
||||||
|
<td>{{ r.system }}</td>
|
||||||
|
<td>{{ r.name }}</td>
|
||||||
|
<td>{{ (r.bytes / 1048576) | round(1) }} MB</td>
|
||||||
|
</tr>
|
||||||
|
{% else %}
|
||||||
|
<tr><td colspan="5">No downloads yet.</td></tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
{% endblock %}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% block title %}Login · psppt{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<div class="card narrow">
|
||||||
|
<h1>psppt server</h1>
|
||||||
|
{% if error %}<p class="error">{{ error }}</p>{% endif %}
|
||||||
|
<form method="post" action="/login">
|
||||||
|
<label>Username <input name="username" required autofocus></label>
|
||||||
|
<label>Password <input name="password" type="password" required></label>
|
||||||
|
<button>Log in</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% block title %}{{ rel.name }} · psppt{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<p><a href="/releases">← back</a></p>
|
||||||
|
<h1>{{ rel.name }}</h1>
|
||||||
|
<form method="post" action="/releases/{{ rel.id }}/edit" class="grid">
|
||||||
|
<label>Name <input name="name" value="{{ rel.name }}"></label>
|
||||||
|
<label>Region <input name="region" value="{{ rel.region or '' }}"></label>
|
||||||
|
<label>Serial <input name="serial" value="{{ rel.serial or '' }}"></label>
|
||||||
|
<label>Description <textarea name="description">{{ rel.description or '' }}</textarea></label>
|
||||||
|
<label>Title <input name="title" value="{{ meta.title or '' }}"></label>
|
||||||
|
<label>Release date <input name="release_date" value="{{ meta.release_date or '' }}"></label>
|
||||||
|
<label>Developer <input name="developer" value="{{ meta.developer or '' }}"></label>
|
||||||
|
<label>Publisher <input name="publisher" value="{{ meta.publisher or '' }}"></label>
|
||||||
|
<label>Genre <input name="genre" value="{{ meta.genre or '' }}"></label>
|
||||||
|
<label class="wide">Synopsis <textarea name="synopsis">{{ meta.synopsis or '' }}</textarea></label>
|
||||||
|
<button>Save</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<h2>Cover</h2>
|
||||||
|
{% if has_cover %}<img src="/api/cover/{{ rel.id }}" class="cover" alt="cover">{% else %}<p class="muted">No cover.</p>{% endif %}
|
||||||
|
<form method="post" action="/releases/{{ rel.id }}/cover" enctype="multipart/form-data" class="inline">
|
||||||
|
<input type="file" name="cover" accept="image/*">
|
||||||
|
<button>Upload cover</button>
|
||||||
|
</form>
|
||||||
|
{% if has_cover %}
|
||||||
|
<form method="post" action="/releases/{{ rel.id }}/cover/delete" class="inline">
|
||||||
|
<button class="danger">Delete cover</button>
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% block title %}Games & Videos · psppt{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<h1>Games & Videos</h1>
|
||||||
|
<form method="get" action="/releases" class="filters">
|
||||||
|
<select name="system">
|
||||||
|
<option value="">All systems</option>
|
||||||
|
<option value="games" {% if system == 'games' %}selected{% endif %}>Games</option>
|
||||||
|
<option value="videos" {% if system == 'videos' %}selected{% endif %}>Videos</option>
|
||||||
|
</select>
|
||||||
|
<input name="q" value="{{ q }}" placeholder="Search…">
|
||||||
|
<button>Filter</button>
|
||||||
|
</form>
|
||||||
|
<table>
|
||||||
|
<tr><th>Name</th><th>System</th><th>Region</th><th>Serial</th><th>Cover</th><th></th></tr>
|
||||||
|
{% for it in items %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ it.name }}</td>
|
||||||
|
<td>{{ it.system }}</td>
|
||||||
|
<td>{{ it.region or '' }}</td>
|
||||||
|
<td>{{ it.serial or '' }}</td>
|
||||||
|
<td>{% if it.has_cover %}✓{% else %}—{% endif %}</td>
|
||||||
|
<td><a href="/releases/{{ it.id }}/edit">Edit</a></td>
|
||||||
|
</tr>
|
||||||
|
{% else %}
|
||||||
|
<tr><td colspan="6">Nothing found.</td></tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
{% endblock %}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% block title %}Settings · psppt{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<h1>Settings</h1>
|
||||||
|
<ul>
|
||||||
|
<li>Store root (games): <code>{{ store_root }}</code></li>
|
||||||
|
<li>Store root (videos): <code>{{ store_videos_root }}</code></li>
|
||||||
|
<li>Covers directory: <code>{{ covers_dir }}</code></li>
|
||||||
|
</ul>
|
||||||
|
<p class="muted">These paths are configured via environment variables — restart the server to change them.</p>
|
||||||
|
{% endblock %}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% block title %}Store · psppt{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<h1>Store</h1>
|
||||||
|
<h2>Upload archive</h2>
|
||||||
|
<form method="post" action="/store/upload" enctype="multipart/form-data" class="inline">
|
||||||
|
<select name="system">
|
||||||
|
<option value="games">Games</option>
|
||||||
|
<option value="videos">Videos</option>
|
||||||
|
</select>
|
||||||
|
<input type="file" name="file">
|
||||||
|
<button>Upload</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<h2>Games ({{ games | length }})</h2>
|
||||||
|
<table>
|
||||||
|
<tr><th>Name</th><th>Size</th><th></th></tr>
|
||||||
|
{% for g in games %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ g.name }}</td>
|
||||||
|
<td>{{ (g.size / 1048576) | round(1) }} MB</td>
|
||||||
|
<td>
|
||||||
|
<form method="post" action="/store/games/{{ g.filename }}/delete" class="inline">
|
||||||
|
<button class="danger">Delete</button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% else %}
|
||||||
|
<tr><td colspan="3">No game archives.</td></tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<h2>Videos ({{ videos | length }})</h2>
|
||||||
|
<table>
|
||||||
|
<tr><th>Name</th><th>Size</th><th></th></tr>
|
||||||
|
{% for v in videos %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ v.name }}</td>
|
||||||
|
<td>{{ (v.size / 1048576) | round(1) }} MB</td>
|
||||||
|
<td>
|
||||||
|
<form method="post" action="/store/videos/{{ v.filename }}/delete" class="inline">
|
||||||
|
<button class="danger">Delete</button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% else %}
|
||||||
|
<tr><td colspan="3">No video archives.</td></tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
{% endblock %}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% block title %}Users · psppt{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<h1>Users</h1>
|
||||||
|
<h2>Add user</h2>
|
||||||
|
<form method="post" action="/users" class="inline">
|
||||||
|
<input name="username" placeholder="username" required>
|
||||||
|
<input name="password" type="password" placeholder="password" required>
|
||||||
|
<select name="role">
|
||||||
|
<option value="user">user</option>
|
||||||
|
<option value="editor">editor</option>
|
||||||
|
<option value="admin">admin</option>
|
||||||
|
</select>
|
||||||
|
<button>Add</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<h2>Existing</h2>
|
||||||
|
<table>
|
||||||
|
<tr><th>Username</th><th>Role</th><th>Active</th><th>Actions</th></tr>
|
||||||
|
{% for u in users %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ u.username }}</td>
|
||||||
|
<td>{{ u.role }}</td>
|
||||||
|
<td>{{ 'yes' if u.is_active else 'no' }}</td>
|
||||||
|
<td>
|
||||||
|
<form method="post" action="/users/{{ u.id }}" class="inline">
|
||||||
|
<select name="role">
|
||||||
|
<option value="user" {% if u.role == 'user' %}selected{% endif %}>user</option>
|
||||||
|
<option value="editor" {% if u.role == 'editor' %}selected{% endif %}>editor</option>
|
||||||
|
<option value="admin" {% if u.role == 'admin' %}selected{% endif %}>admin</option>
|
||||||
|
</select>
|
||||||
|
<input name="password" type="password" placeholder="new password">
|
||||||
|
<label class="check"><input type="checkbox" name="is_active" {% if u.is_active %}checked{% endif %}> active</label>
|
||||||
|
<button name="action" value="save">Save</button>
|
||||||
|
<button name="action" value="delete" class="danger">Delete</button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
{% endblock %}
|
||||||
+339
@@ -0,0 +1,339 @@
|
|||||||
|
"""Server-rendered admin WebUI (Jinja2, plain HTML forms — no JS build)."""
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from fastapi import APIRouter, Depends, HTTPException, Request, status
|
||||||
|
from fastapi.responses import RedirectResponse
|
||||||
|
from fastapi.templating import Jinja2Templates
|
||||||
|
|
||||||
|
from app import store as store_mod
|
||||||
|
from app.db import get_connection
|
||||||
|
|
||||||
|
from . import config
|
||||||
|
from .api import _find_cover, _metadata, _release_system, _store_root, _SAFE_NAME_RE
|
||||||
|
from .security import get_user_by_token, hash_password, issue_token, now_iso, require_role, revoke_token, verify_password
|
||||||
|
|
||||||
|
router = APIRouter(include_in_schema=False)
|
||||||
|
templates = Jinja2Templates(directory=str(Path(__file__).parent / "templates"))
|
||||||
|
|
||||||
|
|
||||||
|
def _render(request, name, **ctx):
|
||||||
|
ctx.setdefault("user", getattr(request.state, "user", None))
|
||||||
|
return templates.TemplateResponse(request, name, ctx)
|
||||||
|
|
||||||
|
|
||||||
|
def web_user(request: Request) -> dict:
|
||||||
|
user = get_user_by_token(request.cookies.get("psppt_session", ""))
|
||||||
|
if user is None:
|
||||||
|
raise HTTPException(status_code=status.HTTP_303_SEE_OTHER, headers={"Location": "/login"})
|
||||||
|
request.state.user = user
|
||||||
|
return user
|
||||||
|
|
||||||
|
|
||||||
|
def web_admin(request: Request, user=Depends(web_user)) -> dict:
|
||||||
|
if user["role"] != "admin":
|
||||||
|
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Admin only")
|
||||||
|
return user
|
||||||
|
|
||||||
|
|
||||||
|
def web_editor(request: Request, user=Depends(web_user)) -> dict:
|
||||||
|
if user["role"] not in ("admin", "editor"):
|
||||||
|
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Editor or admin required")
|
||||||
|
return user
|
||||||
|
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
# auth pages
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
@router.get("/login")
|
||||||
|
def login_page(request: Request):
|
||||||
|
return _render(request, "login.html")
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/login")
|
||||||
|
async def login_submit(request: Request):
|
||||||
|
form = await request.form()
|
||||||
|
username = (form.get("username") or "").strip()
|
||||||
|
password = form.get("password") or ""
|
||||||
|
conn = get_connection()
|
||||||
|
try:
|
||||||
|
row = conn.execute(
|
||||||
|
"SELECT id, username, password_hash, role, is_active FROM users WHERE username = ?", (username,)
|
||||||
|
).fetchone()
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
if row is None or not row["is_active"] or not verify_password(password, row["password_hash"]):
|
||||||
|
return _render(request, "login.html", error="Invalid username or password")
|
||||||
|
token = issue_token(row["id"], kind="session", label="web session")
|
||||||
|
conn = get_connection()
|
||||||
|
try:
|
||||||
|
conn.execute("UPDATE users SET last_login_at = ? WHERE id = ?", (now_iso(), row["id"]))
|
||||||
|
conn.commit()
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
resp = RedirectResponse("/dashboard", status_code=status.HTTP_303_SEE_OTHER)
|
||||||
|
resp.set_cookie("psppt_session", token, httponly=True, samesite="lax", path="/")
|
||||||
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/logout")
|
||||||
|
def logout(request: Request):
|
||||||
|
token = request.cookies.get("psppt_session", "")
|
||||||
|
if token:
|
||||||
|
revoke_token(token)
|
||||||
|
resp = RedirectResponse("/login", status_code=status.HTTP_303_SEE_OTHER)
|
||||||
|
resp.delete_cookie("psppt_session", path="/")
|
||||||
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
# dashboard
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
@router.get("/")
|
||||||
|
def root():
|
||||||
|
return RedirectResponse("/dashboard", status_code=status.HTTP_303_SEE_OTHER)
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/dashboard")
|
||||||
|
def dashboard(request: Request, user=Depends(web_user)):
|
||||||
|
conn = get_connection()
|
||||||
|
try:
|
||||||
|
systems = conn.execute(
|
||||||
|
"SELECT d.system AS system, COUNT(*) AS releases FROM releases r "
|
||||||
|
"JOIN dats d ON d.id = r.dat_id GROUP BY d.system ORDER BY d.system"
|
||||||
|
).fetchall()
|
||||||
|
users = conn.execute("SELECT COUNT(*) AS n FROM users").fetchone()["n"]
|
||||||
|
downloads = conn.execute("SELECT COUNT(*) AS n FROM download_events").fetchone()["n"]
|
||||||
|
covers = sum(1 for _ in config.COVERS_DIR.rglob("*") if _.is_file()) if config.COVERS_DIR.is_dir() else 0
|
||||||
|
recent = conn.execute(
|
||||||
|
"SELECT e.system, e.name, e.bytes, e.created_at, u.username FROM download_events e "
|
||||||
|
"LEFT JOIN users u ON u.id = e.user_id ORDER BY e.id DESC LIMIT 15"
|
||||||
|
).fetchall()
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
store_games = len(store_mod.scan(config.STORE_ROOT)) if config.STORE_ROOT.is_dir() else 0
|
||||||
|
store_videos = len(store_mod.scan(config.STORE_VIDEOS_ROOT)) if config.STORE_VIDEOS_ROOT.is_dir() else 0
|
||||||
|
return _render(request, "dashboard.html", systems=[dict(r) for r in systems], users=users,
|
||||||
|
downloads=downloads, covers=covers, recent=[dict(r) for r in recent],
|
||||||
|
store_games=store_games, store_videos=store_videos)
|
||||||
|
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
# releases (games / videos browser)
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
@router.get("/releases")
|
||||||
|
def releases_page(request: Request, system: str = "", q: str = "", user=Depends(web_user)):
|
||||||
|
sql = "SELECT r.id, d.system, r.name, r.region, r.serial FROM releases r JOIN dats d ON d.id = r.dat_id"
|
||||||
|
where, params = [], []
|
||||||
|
if system:
|
||||||
|
where.append("d.system = ?")
|
||||||
|
params.append(system)
|
||||||
|
if q:
|
||||||
|
where.append("r.name LIKE ?")
|
||||||
|
params.append(f"%{q}%")
|
||||||
|
if where:
|
||||||
|
sql += " WHERE " + " AND ".join(where)
|
||||||
|
sql += " ORDER BY r.name LIMIT 200"
|
||||||
|
conn = get_connection()
|
||||||
|
try:
|
||||||
|
rows = conn.execute(sql, params).fetchall()
|
||||||
|
items = []
|
||||||
|
for r in rows:
|
||||||
|
d = dict(r)
|
||||||
|
d["has_cover"] = _find_cover(r["id"], r["system"]).exists()
|
||||||
|
items.append(d)
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
return _render(request, "releases.html", items=items, system=system, q=q)
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/releases/{release_id}/edit")
|
||||||
|
def release_edit_page(release_id: int, request: Request, user=Depends(web_editor)):
|
||||||
|
conn = get_connection()
|
||||||
|
try:
|
||||||
|
rel = conn.execute(
|
||||||
|
"SELECT r.id, d.system, r.name, r.description, r.region, r.serial "
|
||||||
|
"FROM releases r JOIN dats d ON d.id = r.dat_id WHERE r.id = ?",
|
||||||
|
(release_id,),
|
||||||
|
).fetchone()
|
||||||
|
if rel is None:
|
||||||
|
raise HTTPException(status_code=404, detail="not found")
|
||||||
|
meta = _metadata(conn, release_id, rel["system"])
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
has_cover = _find_cover(release_id, rel["system"]).exists()
|
||||||
|
return _render(request, "release_edit.html", rel=dict(rel), meta=meta, has_cover=has_cover)
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/releases/{release_id}/edit")
|
||||||
|
async def release_edit_save(release_id: int, request: Request, user=Depends(web_editor)):
|
||||||
|
form = await request.form()
|
||||||
|
conn = get_connection()
|
||||||
|
try:
|
||||||
|
rel = conn.execute(
|
||||||
|
"SELECT d.system FROM releases r JOIN dats d ON d.id = r.dat_id WHERE r.id = ?", (release_id,)
|
||||||
|
).fetchone()
|
||||||
|
if rel is None:
|
||||||
|
raise HTTPException(status_code=404, detail="not found")
|
||||||
|
conn.execute(
|
||||||
|
"UPDATE releases SET name = ?, region = ?, serial = ?, description = ? WHERE id = ?",
|
||||||
|
(form.get("name") or "", form.get("region") or "", form.get("serial") or "",
|
||||||
|
form.get("description") or "", release_id),
|
||||||
|
)
|
||||||
|
meta = {}
|
||||||
|
for k in ("title", "release_date", "developer", "publisher", "genre", "synopsis"):
|
||||||
|
v = form.get(k)
|
||||||
|
if v is not None and str(v).strip():
|
||||||
|
meta[k] = str(v).strip()
|
||||||
|
if meta:
|
||||||
|
from .api import _save_metadata
|
||||||
|
_save_metadata(conn, release_id, rel["system"], meta)
|
||||||
|
conn.commit()
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
return RedirectResponse(f"/releases/{release_id}/edit", status_code=status.HTTP_303_SEE_OTHER)
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/releases/{release_id}/cover")
|
||||||
|
async def release_cover_upload(release_id: int, request: Request, user=Depends(web_editor)):
|
||||||
|
from .api import _save_cover
|
||||||
|
form = await request.form()
|
||||||
|
file = form.get("cover")
|
||||||
|
if file is None or not getattr(file, "filename", ""):
|
||||||
|
raise HTTPException(status_code=400, detail="no file")
|
||||||
|
data = await file.read()
|
||||||
|
conn = get_connection()
|
||||||
|
try:
|
||||||
|
system = _release_system(conn, release_id)
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
if system is None:
|
||||||
|
raise HTTPException(status_code=404, detail="not found")
|
||||||
|
_save_cover(release_id, system, data)
|
||||||
|
return RedirectResponse(f"/releases/{release_id}/edit", status_code=status.HTTP_303_SEE_OTHER)
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/releases/{release_id}/cover/delete")
|
||||||
|
def release_cover_delete(release_id: int, user=Depends(web_editor)):
|
||||||
|
from .api import _find_cover
|
||||||
|
conn = get_connection()
|
||||||
|
try:
|
||||||
|
system = _release_system(conn, release_id)
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
if system:
|
||||||
|
p = _find_cover(release_id, system)
|
||||||
|
if p.exists():
|
||||||
|
p.unlink()
|
||||||
|
return RedirectResponse(f"/releases/{release_id}/edit", status_code=status.HTTP_303_SEE_OTHER)
|
||||||
|
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
# users (admin)
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
@router.get("/users")
|
||||||
|
def users_page(request: Request, user=Depends(web_admin)):
|
||||||
|
conn = get_connection()
|
||||||
|
try:
|
||||||
|
rows = conn.execute(
|
||||||
|
"SELECT id, username, role, is_active, created_at, last_login_at FROM users ORDER BY username"
|
||||||
|
).fetchall()
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
return _render(request, "users.html", users=[dict(r) for r in rows])
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/users")
|
||||||
|
async def users_create(request: Request, user=Depends(web_admin)):
|
||||||
|
form = await request.form()
|
||||||
|
username = (form.get("username") or "").strip()
|
||||||
|
password = form.get("password") or ""
|
||||||
|
role = form.get("role") or "user"
|
||||||
|
if not username or not password:
|
||||||
|
raise HTTPException(status_code=400, detail="username and password required")
|
||||||
|
conn = get_connection()
|
||||||
|
try:
|
||||||
|
try:
|
||||||
|
conn.execute(
|
||||||
|
"INSERT INTO users (username, password_hash, role, is_active, created_at) VALUES (?, ?, ?, 1, ?)",
|
||||||
|
(username, hash_password(password), role, now_iso()),
|
||||||
|
)
|
||||||
|
conn.commit()
|
||||||
|
except Exception:
|
||||||
|
raise HTTPException(status_code=409, detail="username already exists")
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
return RedirectResponse("/users", status_code=status.HTTP_303_SEE_OTHER)
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/users/{user_id}")
|
||||||
|
async def users_update(user_id: int, request: Request, user=Depends(web_admin)):
|
||||||
|
form = await request.form()
|
||||||
|
action = form.get("action") or ""
|
||||||
|
conn = get_connection()
|
||||||
|
try:
|
||||||
|
if action == "delete":
|
||||||
|
if user_id != user["id"]:
|
||||||
|
conn.execute("DELETE FROM users WHERE id = ?", (user_id,))
|
||||||
|
else:
|
||||||
|
role = form.get("role")
|
||||||
|
if role in ("admin", "editor", "user"):
|
||||||
|
conn.execute("UPDATE users SET role = ? WHERE id = ?", (role, user_id))
|
||||||
|
conn.execute("UPDATE users SET is_active = ? WHERE id = ?", (1 if form.get("is_active") else 0, user_id))
|
||||||
|
pw = form.get("password") or ""
|
||||||
|
if pw:
|
||||||
|
conn.execute("UPDATE users SET password_hash = ? WHERE id = ?", (hash_password(pw), user_id))
|
||||||
|
conn.commit()
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
return RedirectResponse("/users", status_code=status.HTTP_303_SEE_OTHER)
|
||||||
|
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
# store management (editor+)
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
@router.get("/store")
|
||||||
|
def store_page(request: Request, user=Depends(web_editor)):
|
||||||
|
def _rows(root):
|
||||||
|
out = []
|
||||||
|
for it in store_mod.scan(root):
|
||||||
|
out.append({"name": it["name"], "filename": Path(it["path"]).name, "size": it["size"]})
|
||||||
|
return out
|
||||||
|
games = _rows(config.STORE_ROOT) if config.STORE_ROOT.is_dir() else []
|
||||||
|
videos = _rows(config.STORE_VIDEOS_ROOT) if config.STORE_VIDEOS_ROOT.is_dir() else []
|
||||||
|
return _render(request, "store.html", games=games, videos=videos)
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/store/upload")
|
||||||
|
async def store_upload(request: Request, user=Depends(web_editor)):
|
||||||
|
form = await request.form()
|
||||||
|
system = form.get("system") or "games"
|
||||||
|
file = form.get("file")
|
||||||
|
if file is None or not getattr(file, "filename", ""):
|
||||||
|
raise HTTPException(status_code=400, detail="no file")
|
||||||
|
data = await file.read()
|
||||||
|
root = _store_root(system)
|
||||||
|
root.mkdir(parents=True, exist_ok=True)
|
||||||
|
safe = _SAFE_NAME_RE.sub("", file.filename or "")
|
||||||
|
if not safe:
|
||||||
|
raise HTTPException(status_code=400, detail="invalid filename")
|
||||||
|
(root / safe).write_bytes(data)
|
||||||
|
return RedirectResponse("/store", status_code=status.HTTP_303_SEE_OTHER)
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/store/{system}/{name}/delete")
|
||||||
|
def store_delete(system: str, name: str, user=Depends(web_editor)):
|
||||||
|
root = _store_root(system).resolve()
|
||||||
|
target = (root / name).resolve()
|
||||||
|
if target.is_file() and root in target.parents:
|
||||||
|
target.unlink()
|
||||||
|
return RedirectResponse("/store", status_code=status.HTTP_303_SEE_OTHER)
|
||||||
|
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
# settings (admin)
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
@router.get("/settings")
|
||||||
|
def settings_page(request: Request, user=Depends(web_admin)):
|
||||||
|
return _render(request, "settings.html",
|
||||||
|
store_root=config.STORE_ROOT, store_videos_root=config.STORE_VIDEOS_ROOT,
|
||||||
|
covers_dir=config.COVERS_DIR)
|
||||||
Reference in New Issue
Block a user