30 lines
731 B
TypeScript
30 lines
731 B
TypeScript
export const deleteFile = async (fileId: string) => {
|
|
await fetch(fileId, {
|
|
method: 'DELETE',
|
|
headers: {
|
|
'Tus-Resumable': '1.0.0',
|
|
},
|
|
keepalive: true,
|
|
})
|
|
}
|
|
|
|
export const handleBeforeUnload = (_e: BeforeUnloadEvent, files: string[]) =>
|
|
batchDelete(files)
|
|
|
|
export const batchDelete = (files: string[]) => {
|
|
for (const file of files) deleteFile(file)
|
|
|
|
if (navigator.userAgent.match(/firefox|fxios/i)) {
|
|
const firefoxVer = Number(navigator.userAgent.match(/Firefox\/(\d+)/)[1])
|
|
|
|
// One day dom.fetchKeepalive.enabled becomes true by default... until then!
|
|
if (firefoxVer < 129) {
|
|
const time = Date.now()
|
|
|
|
while (Date.now() - time < 500) {
|
|
/* empty */
|
|
}
|
|
}
|
|
}
|
|
}
|