auto download

This commit is contained in:
2026-01-16 13:45:22 +00:00
parent ab4ceb877b
commit 7fcc5e344a

View File

@@ -8,9 +8,11 @@
const url = ref("");
const in_url = ref("");
const file_dwnl = ref("");
const music_params_schema = z.object({
song: z.string("Song name required"),
artist: z.string("Artist name required"),
artist: z.string().optional(),
album: z.string().optional()
})
@@ -30,6 +32,7 @@
else video.value = 0
}
async function start_conversion(event: FormSubmitEvent<musicParamsSchema>) {
return fetch("/convert", {
method: "POST",
@@ -38,15 +41,27 @@
},
body: JSON.stringify({
url: url.value,
name: music_params.song,
song: music_params.song,
artist: music_params.artist,
album: music_params.album
})
}).then(r => {
console.log(r.status)
}).then(async r => {
//console.log(r.status)
if(r.status == 401)
window.location.href = "/login"
if(r.ok) {
const data = await r.json(); // resolves to { file: "my_audio.mp3" }
const file = data.file;
file_dwnl.value = `/download/${file}`;
const a = document.createElement("a");
a.href = file_dwnl.value;
a.download = file; // sets suggested filename
document.body.appendChild(a); // must append first
a.click(); // triggers download
a.remove();
}
})
}
</script>
@@ -75,19 +90,22 @@
<LazyYoutube :src="url" />
</div>
<UForm :schema="music_params_schema" :state="music_params" @submit="start_conversion()">
<UForm :schema="music_params_schema" :state="music_params" @submit="start_conversion">
<UFormField name="song" class="w-full mt-4 mb-3" label="Track Name:">
<UInput type="text" v-model="music_params.song" class="w-full" />
</UFormField>
<UFormField name="artist" class="w-full mt-4 mb-3" label="Artist Name:">
<UFormField name="artist" class="w-full mt-4 mb-3" label="Artist Name: (optional)">
<UInput type="text" v-model="music_params.artist"class="w-full" />
</UFormField>
<UFormField name="album" class="w-full mt-4 mb-3" label="Album Name:">
<UFormField name="album" class="w-full mt-4 mb-3" label="Album Name: (optional)">
<UInput type="text" v-model="music_params.album" class="w-full" />
</UFormField>
<div class="text-center">
<UButton class="mt-4 rounded-2xl px-9 w-2/3 py-3 justify-center text-center " loading-auto type="submit">Convert to MP3</UButton>
</div>
<div class="text-center">
<UButton class="mt-4 rounded-2xl px-9 w-2/3 py-3 justify-center text-center" icon="lucide:cloud-download" color="success" >Download</UButton>
</div>
</UForm>
</div>