From c36a3dc0c739fa8ae48bf223c734d668cb84e77b Mon Sep 17 00:00:00 2001 From: Wim Brand Date: Wed, 4 Dec 2024 15:06:58 +0100 Subject: [PATCH] Add support for various tar archive formats --- svelte/src/file_viewer/FileUtilities.svelte | 9 ++++++- svelte/src/file_viewer/viewers/Zip.svelte | 21 ++++++++++++--- svelte/src/file_viewer/viewers/ZipItem.svelte | 8 ++++-- svelte/src/filesystem/FilesystemAPI.mts | 6 ++++- svelte/src/filesystem/viewers/Zip.svelte | 27 ++++++++++++++----- 5 files changed, 56 insertions(+), 15 deletions(-) diff --git a/svelte/src/file_viewer/FileUtilities.svelte b/svelte/src/file_viewer/FileUtilities.svelte index 542537d..bf53148 100644 --- a/svelte/src/file_viewer/FileUtilities.svelte +++ b/svelte/src/file_viewer/FileUtilities.svelte @@ -38,7 +38,14 @@ export const file_set_href = file => { export const file_type = file => { if (file.mime_type === "application/bittorrent" || file.mime_type === "application/x-bittorrent") { return "torrent" - } else if (file.mime_type === "application/zip" || file.mime_type === "application/x-7z-compressed") { + } else if ( + file.mime_type === "application/zip" || + file.mime_type === "application/x-7z-compressed" || + file.mime_type === "application/x-tar" || + (file.mime_type === "application/gzip" && file.name.endsWith(".tar.gz")) || + (file.mime_type === "application/x-xz" && file.name.endsWith(".tar.xz")) || + (file.mime_type === "application/zstd" && file.name.endsWith(".tar.zst")) + ) { return "zip" } else if (file.mime_type.startsWith("image")) { return "image" diff --git a/svelte/src/file_viewer/viewers/Zip.svelte b/svelte/src/file_viewer/viewers/Zip.svelte index afec955..2f10c0d 100644 --- a/svelte/src/file_viewer/viewers/Zip.svelte +++ b/svelte/src/file_viewer/viewers/Zip.svelte @@ -25,6 +25,7 @@ let zip = { } let comp_ratio = 0 let archive_type = "" +let truncated = false export const set_file = async f => { file = f @@ -49,9 +50,12 @@ export const set_file = async f => { // Check if the zip has the property which allows separate files to be // downloaded. If so then we set the download URL for each file - if (zip.properties && zip.properties.includes("read_individual_files")) { - // Set the download URL for each file in the zip - recursive_set_url(f.info_href+"/zip", zip) + if (zip.properties !== undefined) { + if (zip.properties.includes("read_individual_files")) { + // Set the download URL for each file in the zip + recursive_set_url(fs_path_url(nav.base.path)+"?zip_file=", zip) + } + truncated = zip.properties.includes("truncated") } comp_ratio = (zip.size / file.size) @@ -85,7 +89,9 @@ const recursive_set_url = (parent_path, file) => { {/if} Compressed size: {formatDataVolume(file.size, 3)}
- Uncompressed size: {formatDataVolume(zip.size, 3)} (Ratio: {comp_ratio.toFixed(2)}x)
+ {#if !truncated} + Uncompressed size: {formatDataVolume(zip.size, 3)} (Ratio: {comp_ratio.toFixed(2)}x)
+ {/if} Uploaded on: {formatDate(file.date_upload, true, true, true)}