mirror of
https://github.com/rommapp/romm.git
synced 2026-11-28 17:48:31 +01:00
Spotify-style library features for soundtrack tracks: per-user favorites (liked songs) and user-owned playlists with manual ordering and optional public read-only sharing. Track references are stored as (rom_id, md5_hash) rather than rom_file_id: scans purge and re-insert rom_files rows, so file ids churn while rom ids and content hashes are stable. Entries survive rescans and renames, and resolve to the current file at query time; entries whose content is gone are omitted from listings until the file returns. To make the content hash reliably present, soundtrack audio files are now always hashed individually during scans (including NON_HASHABLE_PLATFORMS and SKIP_HASH_CALCULATION, whose file-size concerns don't apply to audio), and soundtrack uploads compute crc/md5/sha1 on write. Existing libraries backfill via a HASHES scan; adding an unhashed track returns 400. New playlists.read/playlists.write scopes are wired through the granular permission system (PermEntity.PLAYLISTS); the migration mirrors every group's collections grants onto the playlists entity so existing groups keep working without admin intervention. Endpoints under /api/music: favorites GET/POST/DELETE, is_favorite and md5_hash on track rows, playlists CRUD, playlist tracks GET/POST/DELETE and PUT /tracks/order.
80 lines
2.5 KiB
Python
80 lines
2.5 KiB
Python
import enum
|
|
from datetime import timedelta
|
|
from typing import Final
|
|
|
|
ALGORITHM: Final = "HS256"
|
|
DEFAULT_OAUTH_TOKEN_EXPIRY: Final = timedelta(minutes=15)
|
|
# Name of the session cookie set by RedisSessionMiddleware (see main.py). Shared
|
|
# so the socket log-stream handshake reads the same cookie the middleware writes.
|
|
SESSION_COOKIE_NAME: Final = "romm_session"
|
|
|
|
|
|
class Scope(enum.StrEnum):
|
|
ME_READ = "me.read"
|
|
ME_WRITE = "me.write"
|
|
ROMS_READ = "roms.read"
|
|
ROMS_WRITE = "roms.write"
|
|
ROMS_USER_READ = "roms.user.read"
|
|
ROMS_USER_WRITE = "roms.user.write"
|
|
PLATFORMS_READ = "platforms.read"
|
|
PLATFORMS_WRITE = "platforms.write"
|
|
ASSETS_READ = "assets.read"
|
|
ASSETS_WRITE = "assets.write"
|
|
DEVICES_READ = "devices.read"
|
|
DEVICES_WRITE = "devices.write"
|
|
FIRMWARE_READ = "firmware.read"
|
|
FIRMWARE_WRITE = "firmware.write"
|
|
COLLECTIONS_READ = "collections.read"
|
|
COLLECTIONS_WRITE = "collections.write"
|
|
PLAYLISTS_READ = "playlists.read"
|
|
PLAYLISTS_WRITE = "playlists.write"
|
|
USERS_READ = "users.read"
|
|
USERS_WRITE = "users.write"
|
|
TASKS_RUN = "tasks.run"
|
|
LOGS_READ = "logs.read"
|
|
|
|
|
|
READ_SCOPES_MAP: Final = {
|
|
Scope.ME_READ: "View your profile",
|
|
Scope.ROMS_READ: "View ROMs",
|
|
Scope.PLATFORMS_READ: "View platforms",
|
|
Scope.ASSETS_READ: "View assets",
|
|
Scope.DEVICES_READ: "View devices",
|
|
Scope.FIRMWARE_READ: "View firmware",
|
|
Scope.ROMS_USER_READ: "View user-rom properties",
|
|
Scope.COLLECTIONS_READ: "View collections",
|
|
Scope.PLAYLISTS_READ: "View music playlists",
|
|
}
|
|
|
|
WRITE_SCOPES_MAP: Final = {
|
|
Scope.ME_WRITE: "Modify your profile",
|
|
Scope.ASSETS_WRITE: "Modify assets",
|
|
Scope.DEVICES_WRITE: "Modify devices",
|
|
Scope.ROMS_USER_WRITE: "Modify user-rom properties",
|
|
Scope.COLLECTIONS_WRITE: "Modify collections",
|
|
Scope.PLAYLISTS_WRITE: "Modify music playlists",
|
|
}
|
|
|
|
EDIT_SCOPES_MAP: Final = {
|
|
Scope.ROMS_WRITE: "Modify ROMs",
|
|
Scope.PLATFORMS_WRITE: "Modify platforms",
|
|
Scope.FIRMWARE_WRITE: "Modify firmware",
|
|
}
|
|
|
|
FULL_SCOPES_MAP: Final = {
|
|
Scope.USERS_READ: "View users",
|
|
Scope.USERS_WRITE: "Modify users",
|
|
Scope.TASKS_RUN: "Run tasks",
|
|
Scope.LOGS_READ: "View backend logs",
|
|
}
|
|
|
|
READ_SCOPES: Final = list(READ_SCOPES_MAP.keys())
|
|
WRITE_SCOPES: Final = READ_SCOPES + list(WRITE_SCOPES_MAP.keys())
|
|
EDIT_SCOPES: Final = WRITE_SCOPES + list(EDIT_SCOPES_MAP.keys())
|
|
FULL_SCOPES: Final = EDIT_SCOPES + list(FULL_SCOPES_MAP.keys())
|
|
|
|
|
|
class TokenPurpose(enum.StrEnum):
|
|
INVITE = "invite"
|
|
RESET = "reset"
|