From 62a4a6426f7de18e135dad1cde69ae1af8df3c1a Mon Sep 17 00:00:00 2001 From: Fornax Date: Thu, 25 Jan 2024 00:29:41 +0100 Subject: [PATCH] Add 7-zip file explorer --- svelte/src/file_viewer/FileUtilities.svelte | 2 +- svelte/src/file_viewer/viewers/Zip.svelte | 23 ++++++++++++++++--- svelte/src/file_viewer/viewers/ZipItem.svelte | 7 +++++- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/svelte/src/file_viewer/FileUtilities.svelte b/svelte/src/file_viewer/FileUtilities.svelte index ae1eb45..8e4def1 100644 --- a/svelte/src/file_viewer/FileUtilities.svelte +++ b/svelte/src/file_viewer/FileUtilities.svelte @@ -38,7 +38,7 @@ 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") { + } else if (file.mime_type === "application/zip" || file.mime_type === "application/x-7z-compressed") { 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 734bafe..052d92f 100644 --- a/svelte/src/file_viewer/viewers/Zip.svelte +++ b/svelte/src/file_viewer/viewers/Zip.svelte @@ -24,12 +24,19 @@ let zip = { children: null, } let comp_ratio = 0 +let archive_type = "" export const set_file = async f => { file = f dispatch("loading", true) + if (f.mime_type === "application/zip") { + archive_type = "zip" + } else if (f.mime_type === "application/x-7z-compressed") { + archive_type = "7z" + } + try { let resp = await fetch(f.info_href+"/zip") @@ -40,8 +47,12 @@ export const set_file = async f => { zip = await resp.json() - // Set the download URL for each file in the zip - recursive_set_url(f.info_href+"/zip", zip) + // 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) + } comp_ratio = (zip.size / file.size) } catch (err) { @@ -67,6 +78,12 @@ const recursive_set_url = (parent_path, file) => { + {#if archive_type === "7z"} + This is a 7-zip archive. You will need + 7-zip or compatible software to + extract it
+ {/if} + Compressed size: {formatDataVolume(file.size, 3)}
Uncompressed size: {formatDataVolume(zip.size, 3)} (Ratio: {comp_ratio.toFixed(2)}x)
Uploaded on: {formatDate(file.date_upload, true, true, true)} @@ -83,7 +100,7 @@ const recursive_set_url = (parent_path, file) => { {#if status === "finished"} -

Files in this zip archive

+

Files in this archive

{:else if status === "parse_failed"} diff --git a/svelte/src/file_viewer/viewers/ZipItem.svelte b/svelte/src/file_viewer/viewers/ZipItem.svelte index 7fd2239..6b1fa51 100644 --- a/svelte/src/file_viewer/viewers/ZipItem.svelte +++ b/svelte/src/file_viewer/viewers/ZipItem.svelte @@ -25,7 +25,12 @@ export let item = { {#each Object.entries(item.children) as [name, child]} {#if !child.children}
  • - {name} ({formatDataVolume(child.size, 3)})
    + {#if child.download_url} + {name} + {:else} + {name} + {/if} + ({formatDataVolume(child.size, 3)})
  • {/if} {/each}