Force url extension for encrypted uploads

This commit is contained in:
Jon Staab
2025-09-29 13:48:10 -07:00
parent 9ed483abf7
commit 7ff9c00032
+6 -3
View File
@@ -750,6 +750,7 @@ export const uploadFile = async (file: File, options: UploadFileOptions = {}) =>
})
}
const ext = "." + type.split("/")[1]
const server = await getBlossomServer(options)
const hashes = [await sha256(await file.arrayBuffer())]
const $signer = signer.get() || Nip01Signer.ephemeral()
@@ -764,9 +765,11 @@ export const uploadFile = async (file: File, options: UploadFileOptions = {}) =>
return {error: text}
}
// Always append file extension if missing
if (new URL(url).pathname.split(".").length === 1) {
url += "." + type.split("/")[1]
// Always append correct file extension if we encrypted the file, or if it's missing
if (options.encrypt) {
url = url.replace(/\.\w+$/, "") + ext
} else if (new URL(url).pathname.split(".").length === 1) {
url += ext
}
const result = {...task, tags, url}