sveltekit-ui 1.1.20 → 1.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -297,6 +297,32 @@ export function create_audio_manager(config) {
|
|
|
297
297
|
is_loading = false
|
|
298
298
|
}
|
|
299
299
|
|
|
300
|
+
function mime_to_ext(mime) {
|
|
301
|
+
const v = String(mime || "").toLowerCase()
|
|
302
|
+
if (v.includes("mpeg")) return "mp3"
|
|
303
|
+
if (v.includes("mp4")) return "mp4"
|
|
304
|
+
if (v.includes("webm")) return "webm"
|
|
305
|
+
if (v.includes("ogg")) return "ogg"
|
|
306
|
+
if (v.includes("wav")) return "wav"
|
|
307
|
+
if (v.includes("flac")) return "flac"
|
|
308
|
+
if (v.includes("aac")) return "aac"
|
|
309
|
+
return "audio"
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function safe_file_base(input) {
|
|
313
|
+
const s = String(input || "").trim()
|
|
314
|
+
if (!s) return "audio"
|
|
315
|
+
return (
|
|
316
|
+
s
|
|
317
|
+
.replace(/\.[a-z0-9]+$/i, "")
|
|
318
|
+
.replace(/[^a-z0-9_\- ]/gi, "")
|
|
319
|
+
.trim()
|
|
320
|
+
.replace(/\s+/g, "_")
|
|
321
|
+
.slice(0, 80)
|
|
322
|
+
.toLowerCase() || "audio"
|
|
323
|
+
)
|
|
324
|
+
}
|
|
325
|
+
|
|
300
326
|
async function download_audio() {
|
|
301
327
|
if (!browser) return
|
|
302
328
|
download_error_message = null
|
|
@@ -306,7 +332,7 @@ export function create_audio_manager(config) {
|
|
|
306
332
|
}
|
|
307
333
|
try {
|
|
308
334
|
download_is_loading = true
|
|
309
|
-
const res = await fetch(src
|
|
335
|
+
const res = await fetch(src)
|
|
310
336
|
if (!res.ok) {
|
|
311
337
|
const t = await res.text().catch(() => null)
|
|
312
338
|
download_error_message = t || `download failed (${res.status})`
|
|
@@ -316,11 +342,11 @@ export function create_audio_manager(config) {
|
|
|
316
342
|
const blob = await res.blob()
|
|
317
343
|
const ext = mime_to_ext(content_type || blob.type)
|
|
318
344
|
const base = safe_file_base(title || album || artist || "recording")
|
|
319
|
-
const
|
|
345
|
+
const file_name = `${base}.${ext}`
|
|
320
346
|
const object_url = URL.createObjectURL(blob)
|
|
321
347
|
const a = document.createElement("a")
|
|
322
348
|
a.href = object_url
|
|
323
|
-
a.download =
|
|
349
|
+
a.download = file_name
|
|
324
350
|
a.rel = "noopener"
|
|
325
351
|
document.body.appendChild(a)
|
|
326
352
|
a.click()
|
package/package.json
CHANGED
|
@@ -297,6 +297,32 @@ export function create_audio_manager(config) {
|
|
|
297
297
|
is_loading = false
|
|
298
298
|
}
|
|
299
299
|
|
|
300
|
+
function mime_to_ext(mime) {
|
|
301
|
+
const v = String(mime || "").toLowerCase()
|
|
302
|
+
if (v.includes("mpeg")) return "mp3"
|
|
303
|
+
if (v.includes("mp4")) return "mp4"
|
|
304
|
+
if (v.includes("webm")) return "webm"
|
|
305
|
+
if (v.includes("ogg")) return "ogg"
|
|
306
|
+
if (v.includes("wav")) return "wav"
|
|
307
|
+
if (v.includes("flac")) return "flac"
|
|
308
|
+
if (v.includes("aac")) return "aac"
|
|
309
|
+
return "audio"
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function safe_file_base(input) {
|
|
313
|
+
const s = String(input || "").trim()
|
|
314
|
+
if (!s) return "audio"
|
|
315
|
+
return (
|
|
316
|
+
s
|
|
317
|
+
.replace(/\.[a-z0-9]+$/i, "")
|
|
318
|
+
.replace(/[^a-z0-9_\- ]/gi, "")
|
|
319
|
+
.trim()
|
|
320
|
+
.replace(/\s+/g, "_")
|
|
321
|
+
.slice(0, 80)
|
|
322
|
+
.toLowerCase() || "audio"
|
|
323
|
+
)
|
|
324
|
+
}
|
|
325
|
+
|
|
300
326
|
async function download_audio() {
|
|
301
327
|
if (!browser) return
|
|
302
328
|
download_error_message = null
|
|
@@ -306,7 +332,7 @@ export function create_audio_manager(config) {
|
|
|
306
332
|
}
|
|
307
333
|
try {
|
|
308
334
|
download_is_loading = true
|
|
309
|
-
const res = await fetch(src
|
|
335
|
+
const res = await fetch(src)
|
|
310
336
|
if (!res.ok) {
|
|
311
337
|
const t = await res.text().catch(() => null)
|
|
312
338
|
download_error_message = t || `download failed (${res.status})`
|
|
@@ -316,11 +342,11 @@ export function create_audio_manager(config) {
|
|
|
316
342
|
const blob = await res.blob()
|
|
317
343
|
const ext = mime_to_ext(content_type || blob.type)
|
|
318
344
|
const base = safe_file_base(title || album || artist || "recording")
|
|
319
|
-
const
|
|
345
|
+
const file_name = `${base}.${ext}`
|
|
320
346
|
const object_url = URL.createObjectURL(blob)
|
|
321
347
|
const a = document.createElement("a")
|
|
322
348
|
a.href = object_url
|
|
323
|
-
a.download =
|
|
349
|
+
a.download = file_name
|
|
324
350
|
a.rel = "noopener"
|
|
325
351
|
document.body.appendChild(a)
|
|
326
352
|
a.click()
|