diff --git a/backend/builder/service.py b/backend/builder/service.py index 7d91f9f..17feb47 100644 --- a/backend/builder/service.py +++ b/backend/builder/service.py @@ -196,7 +196,8 @@ async def build_binary(melody_id: str) -> BuiltMelodyInDB: _ensure_storage_dir() values = steps_string_to_values(row["steps"]) - bsm_path = STORAGE_DIR / f"{melody_id}.bsm" + file_name = f"{row['pid']}.bsm" if row.get("pid") else f"{melody_id}.bsm" + bsm_path = STORAGE_DIR / file_name with open(bsm_path, "wb") as f: for value in values: value = value & 0xFFFF diff --git a/frontend/src/melodies/MelodyDetail.jsx b/frontend/src/melodies/MelodyDetail.jsx index 996e406..b268cbb 100644 --- a/frontend/src/melodies/MelodyDetail.jsx +++ b/frontend/src/melodies/MelodyDetail.jsx @@ -459,12 +459,12 @@ export default function MelodyDetail() { const binaryFilename = `${binaryPid}.bsm`; // Derive a display name: for firebase URLs extract the filename portion - let displayName = binaryFilename; + let downloadName = binaryFilename; if (!files.binary_url && melody.url) { try { const urlPath = decodeURIComponent(new URL(melody.url).pathname); const parts = urlPath.split("/"); - displayName = parts[parts.length - 1] || binaryFilename; + downloadName = parts[parts.length - 1] || binaryFilename; } catch { /* keep binaryFilename */ } } @@ -484,7 +484,7 @@ export default function MelodyDetail() { const objectUrl = URL.createObjectURL(blob); const a = document.createElement("a"); a.href = objectUrl; - a.download = displayName; + a.download = downloadName; a.click(); URL.revokeObjectURL(objectUrl); } catch (err) { @@ -493,18 +493,37 @@ export default function MelodyDetail() { }; return ( - - - {displayName} - - {!files.binary_url && melody.url && ( - - via URL + + + {builtMelody?.name ? ( + {builtMelody.name} + ) : ( + + {downloadName} + + )} + {!files.binary_url && melody.url && ( + + via URL + + )} + + {builtMelody?.name && ( + + file:{" "} + + {downloadName} + )} diff --git a/frontend/src/melodies/MelodyForm.jsx b/frontend/src/melodies/MelodyForm.jsx index d07c8c8..f29a0c0 100644 --- a/frontend/src/melodies/MelodyForm.jsx +++ b/frontend/src/melodies/MelodyForm.jsx @@ -93,6 +93,7 @@ export default function MelodyForm() { const [showPlayback, setShowPlayback] = useState(false); const [builtMelody, setBuiltMelody] = useState(null); const [assignedBinaryName, setAssignedBinaryName] = useState(null); + const [assignedBinaryPid, setAssignedBinaryPid] = useState(null); // Metadata / Admin Notes const [adminNotes, setAdminNotes] = useState([]); @@ -145,6 +146,7 @@ export default function MelodyForm() { const bm = await api.get(`/builder/melodies/for-melody/${id}`); setBuiltMelody(bm || null); setAssignedBinaryName(bm?.name || null); + setAssignedBinaryPid(bm?.pid || null); } catch { setBuiltMelody(null); } @@ -391,7 +393,12 @@ export default function MelodyForm() { <>