CODEX - More changes to the binary files, listing and storing

This commit is contained in:
2026-02-23 13:58:40 +02:00
parent d390bdac0d
commit 04b2a0bcb8
5 changed files with 154 additions and 22 deletions

View File

@@ -557,11 +557,12 @@ export default function MelodyDetail() {
const handleDownload = async (e) => {
e.preventDefault();
const preferredUrl = melody?.id ? `/api/melodies/${melody.id}/download/binary` : binaryUrl;
try {
const token = localStorage.getItem("access_token");
let res = null;
try {
res = await fetch(binaryUrl, {
res = await fetch(preferredUrl, {
headers: token ? { Authorization: `Bearer ${token}` } : {},
});
} catch {

View File

@@ -227,14 +227,15 @@ export default function MelodyForm() {
return { effectiveUrl, effectiveName };
};
const downloadExistingFile = async (fileUrl, fallbackName, e) => {
const downloadExistingFile = async (fileUrl, fallbackName, e, downloadEndpoint = null) => {
e?.preventDefault?.();
if (!fileUrl) return;
try {
const token = localStorage.getItem("access_token");
const sourceUrl = downloadEndpoint || fileUrl;
let res = null;
try {
res = await fetch(fileUrl, {
res = await fetch(sourceUrl, {
headers: token ? { Authorization: `Bearer ${token}` } : {},
});
} catch {
@@ -793,7 +794,14 @@ export default function MelodyForm() {
<div className="inline-flex items-center gap-2.5">
<button
type="button"
onClick={(e) => downloadExistingFile(binaryUrl, binaryName, e)}
onClick={(e) =>
downloadExistingFile(
binaryUrl,
binaryName,
e,
(id || savedMelodyId) ? `/api/melodies/${id || savedMelodyId}/download/binary` : null
)
}
className="px-2 py-0.5 text-xs rounded-full"
style={{ color: "var(--text-link)", backgroundColor: "rgba(88,156,250,0.14)" }}
>

View File

@@ -438,13 +438,14 @@ export default function MelodyList() {
e.stopPropagation();
const resolved = resolveEffectiveBinary(row);
const binaryUrl = resolved.url;
const preferredUrl = row?.id ? `/api/melodies/${row.id}/download/binary` : binaryUrl;
if (!binaryUrl) return;
try {
const token = localStorage.getItem("access_token");
let res = null;
try {
res = await fetch(binaryUrl, {
res = await fetch(preferredUrl, {
headers: token ? { Authorization: `Bearer ${token}` } : {},
});
} catch {