Files
fnx_web/svelte/src/file_viewer/FileUtilities.svelte

73 lines
1.8 KiB
Svelte
Raw Normal View History

2021-11-28 15:19:00 +01:00
<script context="module">
export const file_struct = {
id: "",
name: "",
size: 0,
bandwidth_used: 0,
bandwidth_used_paid: 0,
downloads: 0,
views: 0,
mime_type: "",
availability: "",
abuse_type: "",
2022-01-27 19:56:44 +01:00
hash_sha256: "",
2021-11-28 15:19:00 +01:00
show_ads: false,
can_edit: false,
can_download: false,
2021-11-28 15:19:00 +01:00
get_href: "",
info_href: "",
download_href: "",
icon_href: "",
}
export const list_struct = {
id: "",
title: "",
files: [],
download_href: "",
info_href: "",
can_edit: false,
}
export const file_set_href = file => {
file.get_href = window.api_endpoint+"/file/"+file.id
file.info_href = window.api_endpoint+"/file/"+file.id+"/info"
file.download_href = window.api_endpoint+"/file/"+file.id+"?download"
file.icon_href = window.api_endpoint+"/file/"+file.id+"/thumbnail"
file.timeseries_href = window.api_endpoint+"/file/"+file.id+"/timeseries"
}
export const file_type = file => {
2022-01-11 18:53:01 +01:00
if (file.mime_type === "application/bittorrent" || file.mime_type === "application/x-bittorrent") {
return "torrent"
2024-01-25 00:29:41 +01:00
} else if (file.mime_type === "application/zip" || file.mime_type === "application/x-7z-compressed") {
2023-01-17 16:13:26 +01:00
return "zip"
2022-01-11 18:53:01 +01:00
} else if (file.mime_type.startsWith("image")) {
2021-11-28 15:19:00 +01:00
return "image"
} else if (
file.mime_type.startsWith("video") ||
file.mime_type === "application/matroska" ||
file.mime_type === "application/x-matroska"
) {
return "video"
} else if (
file.mime_type.startsWith("audio") ||
file.mime_type === "application/ogg" ||
file.name.endsWith(".mp3")
) {
return "audio"
} else if (
file.mime_type === "application/pdf" ||
file.mime_type === "application/x-pdf"
) {
return "pdf"
} else if (
2023-06-08 14:18:12 +02:00
file.mime_type === "application/json" ||
2023-09-29 18:56:16 +02:00
file.mime_type === "application/x-shellscript" ||
2021-11-28 15:19:00 +01:00
file.mime_type.startsWith("text")
) {
return "text"
} else {
return "file"
}
}
</script>