diff --git a/backend/alembic/versions/0080_rom_category_soundtrack.py b/backend/alembic/versions/0080_rom_category_soundtrack.py index eba8e5786..769a6f34a 100644 --- a/backend/alembic/versions/0080_rom_category_soundtrack.py +++ b/backend/alembic/versions/0080_rom_category_soundtrack.py @@ -9,7 +9,6 @@ Create Date: 2026-04-17 00:00:00.000000 import sqlalchemy as sa from alembic import op -from sqlalchemy.dialects.postgresql import ENUM from utils.database import CustomJSON, is_postgresql @@ -24,23 +23,21 @@ def upgrade() -> None: connection = op.get_bind() if is_postgresql(connection): - rom_file_category_enum = ENUM( - "GAME", - "DLC", - "HACK", - "MANUAL", - "PATCH", - "UPDATE", - "MOD", - "DEMO", - "TRANSLATION", - "PROTOTYPE", - "CHEAT", - "SOUNDTRACK", - name="romfilecategory", - create_type=False, + # `ALTER TYPE ... ADD VALUE` must run outside a transaction in PostgreSQL. + # autocommit_block breaks out of alembic's wrapping transaction for + # exactly this operation. + with op.get_context().autocommit_block(): + op.execute( + "ALTER TYPE romfilecategory ADD VALUE IF NOT EXISTS 'SOUNDTRACK'" + ) + + # audio_meta column (added separately so the enum change sticks even + # if the JSON column already exists from a partial prior run). + op.add_column( + "rom_files", + sa.Column("audio_meta", CustomJSON(), nullable=True), + if_not_exists=True, ) - rom_file_category_enum.create(connection, checkfirst=True) else: rom_file_category_enum = sa.Enum( "GAME", @@ -57,15 +54,19 @@ def upgrade() -> None: "SOUNDTRACK", name="romfilecategory", ) - - with op.batch_alter_table("rom_files", schema=None) as batch_op: - batch_op.alter_column("category", type_=rom_file_category_enum, nullable=True) - batch_op.add_column( - sa.Column("audio_meta", CustomJSON(), nullable=True), - if_not_exists=True, - ) + with op.batch_alter_table("rom_files", schema=None) as batch_op: + batch_op.alter_column( + "category", type_=rom_file_category_enum, nullable=True + ) + batch_op.add_column( + sa.Column("audio_meta", CustomJSON(), nullable=True), + if_not_exists=True, + ) def downgrade() -> None: + # PostgreSQL cannot remove enum values, so on downgrade we only drop the + # audio_meta column and leave SOUNDTRACK in the enum. Any rows that still + # hold the new value keep working; a re-upgrade is a no-op. with op.batch_alter_table("rom_files", schema=None) as batch_op: batch_op.drop_column("audio_meta", if_exists=True) diff --git a/backend/endpoints/responses/rom.py b/backend/endpoints/responses/rom.py index ae649544b..669654a7a 100644 --- a/backend/endpoints/responses/rom.py +++ b/backend/endpoints/responses/rom.py @@ -182,6 +182,15 @@ class RomFileSchema(BaseModel): audio_meta: RomFileAudioMetaSchema | None = None +class SoundtrackTrackMetaSchema(BaseModel): + model_config = ConfigDict(from_attributes=True) + + file_id: int + file_name: str + file_size_bytes: int + audio_meta: RomFileAudioMetaSchema | None = None + + class RomMetadataSchema(BaseModel): model_config = ConfigDict(from_attributes=True) diff --git a/backend/endpoints/roms/files.py b/backend/endpoints/roms/files.py index 2dca2e854..41124fdad 100644 --- a/backend/endpoints/roms/files.py +++ b/backend/endpoints/roms/files.py @@ -92,21 +92,23 @@ async def get_romfile_content( media_type = ( _guess_media_type(file_name) if is_audio else "application/octet-stream" ) + disposition = "inline" if is_audio else "attachment" # Serve the file directly in development mode for emulatorjs if DEV_MODE: rom_path = fs_rom_handler.validate_path(file.full_path) - # Audio: serve inline so the browser streams + seeks via Range. Other - # categories: keep the attachment disposition so navigation downloads. - # In both cases Starlette sets Content-Length and honors Range natively. + # Starlette sets Content-Length and honors Range natively — inline + # disposition lets