Add support for various tar archive formats

This commit is contained in:
2024-12-04 15:06:58 +01:00
parent 1c07f6ed1d
commit c36a3dc0c7
5 changed files with 56 additions and 15 deletions

View File

@@ -38,7 +38,14 @@ export const file_set_href = file => {
export const file_type = file => { export const file_type = file => {
if (file.mime_type === "application/bittorrent" || file.mime_type === "application/x-bittorrent") { if (file.mime_type === "application/bittorrent" || file.mime_type === "application/x-bittorrent") {
return "torrent" 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" return "zip"
} else if (file.mime_type.startsWith("image")) { } else if (file.mime_type.startsWith("image")) {
return "image" return "image"

View File

@@ -25,6 +25,7 @@ let zip = {
} }
let comp_ratio = 0 let comp_ratio = 0
let archive_type = "" let archive_type = ""
let truncated = false
export const set_file = async f => { export const set_file = async f => {
file = 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 // 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 // downloaded. If so then we set the download URL for each file
if (zip.properties && zip.properties.includes("read_individual_files")) { if (zip.properties !== undefined) {
if (zip.properties.includes("read_individual_files")) {
// Set the download URL for each file in the zip // Set the download URL for each file in the zip
recursive_set_url(f.info_href+"/zip", zip) recursive_set_url(fs_path_url(nav.base.path)+"?zip_file=", zip)
}
truncated = zip.properties.includes("truncated")
} }
comp_ratio = (zip.size / file.size) comp_ratio = (zip.size / file.size)
@@ -85,7 +89,9 @@ const recursive_set_url = (parent_path, file) => {
{/if} {/if}
Compressed size: {formatDataVolume(file.size, 3)}<br/> Compressed size: {formatDataVolume(file.size, 3)}<br/>
{#if !truncated}
Uncompressed size: {formatDataVolume(zip.size, 3)} (Ratio: {comp_ratio.toFixed(2)}x)<br/> Uncompressed size: {formatDataVolume(zip.size, 3)} (Ratio: {comp_ratio.toFixed(2)}x)<br/>
{/if}
Uploaded on: {formatDate(file.date_upload, true, true, true)} Uploaded on: {formatDate(file.date_upload, true, true, true)}
<br/> <br/>
<button class="button_highlight" on:click={() => {dispatch("download")}}> <button class="button_highlight" on:click={() => {dispatch("download")}}>
@@ -101,6 +107,13 @@ const recursive_set_url = (parent_path, file) => {
{#if status === "finished"} {#if status === "finished"}
<TextBlock> <TextBlock>
<h2>Files in this archive</h2> <h2>Files in this archive</h2>
{#if truncated}
<div class="highlight_yellow">
Due to the large size of this archive, the results have been
truncated. The list below is incomplete!
</div>
{/if}
<ZipItem item={zip} /> <ZipItem item={zip} />
</TextBlock> </TextBlock>
{:else if status === "parse_failed"} {:else if status === "parse_failed"}

View File

@@ -11,11 +11,15 @@ export let item = {
<!-- First get directories and render them as details collapsibles --> <!-- First get directories and render them as details collapsibles -->
{#each Object.entries(item.children) as [name, child]} {#each Object.entries(item.children) as [name, child]}
{#if child.children} {#if child.children}
<details> <details bind:open={child.details_open}>
<summary> <summary>
{name} ({formatDataVolume(child.size, 3)}) {name} ({formatDataVolume(child.size, 3)})
</summary> </summary>
<!-- Performance optimization, only render children if details is expanded -->
{#if child.details_open}
<svelte:self item={child}></svelte:self> <svelte:self item={child}></svelte:self>
{/if}
</details> </details>
{/if} {/if}
{/each} {/each}

View File

@@ -251,7 +251,11 @@ export const fs_node_type = (node: FSNode) => {
return "torrent" return "torrent"
} else if ( } else if (
node.file_type === "application/zip" || node.file_type === "application/zip" ||
node.file_type === "application/x-7z-compressed" node.file_type === "application/x-7z-compressed" ||
node.file_type === "application/x-tar" ||
(node.file_type === "application/gzip" && node.name.endsWith(".tar.gz")) ||
(node.file_type === "application/x-xz" && node.name.endsWith(".tar.xz")) ||
(node.file_type === "application/zstd" && node.name.endsWith(".tar.zst"))
) { ) {
return "zip" return "zip"
} else if (node.file_type.startsWith("image")) { } else if (node.file_type.startsWith("image")) {

View File

@@ -19,12 +19,13 @@ let zip = {
let uncomp_size = 0 let uncomp_size = 0
let comp_ratio = 0 let comp_ratio = 0
let archive_type = "" let archive_type = ""
let truncated = false
export const update = async () => { export const update = async () => {
if (nav.base.file_type === "application/zip") { if (nav.base.file_type === "application/x-7z-compressed") {
archive_type = "zip"
} else if (nav.base.file_type === "application/x-7z-compressed") {
archive_type = "7z" archive_type = "7z"
} else {
archive_type = ""
} }
try { try {
@@ -41,10 +42,13 @@ export const update = async () => {
// Check if the zip has the property which allows separate files to be // 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 // downloaded. If so then we set the download URL for each file
if (zip.properties && zip.properties.includes("read_individual_files")) { if (zip.properties !== undefined) {
if (zip.properties.includes("read_individual_files")) {
// Set the download URL for each file in the zip // Set the download URL for each file in the zip
recursive_set_url(fs_path_url(nav.base.path)+"?zip_file=", zip) recursive_set_url(fs_path_url(nav.base.path)+"?zip_file=", zip)
} }
truncated = zip.properties.includes("truncated")
}
uncomp_size = recursive_size(zip) uncomp_size = recursive_size(zip)
comp_ratio = (uncomp_size / nav.base.file_size) comp_ratio = (uncomp_size / nav.base.file_size)
@@ -95,7 +99,9 @@ const recursive_size = (file) => {
{/if} {/if}
Compressed size: {formatDataVolume($nav.base.file_size, 3)}<br/> Compressed size: {formatDataVolume($nav.base.file_size, 3)}<br/>
{#if !truncated}
Uncompressed size: {formatDataVolume(zip.size, 3)} (Ratio: {comp_ratio.toFixed(2)}x)<br/> Uncompressed size: {formatDataVolume(zip.size, 3)} (Ratio: {comp_ratio.toFixed(2)}x)<br/>
{/if}
Uploaded on: {formatDate($nav.base.created, true, true, true)} Uploaded on: {formatDate($nav.base.created, true, true, true)}
<br/> <br/>
<button class="button_highlight" on:click={() => {dispatch("download")}}> <button class="button_highlight" on:click={() => {dispatch("download")}}>
@@ -107,6 +113,13 @@ const recursive_size = (file) => {
{#if status === "finished"} {#if status === "finished"}
<TextBlock> <TextBlock>
<h2>Files in this zip archive</h2> <h2>Files in this zip archive</h2>
{#if truncated}
<div class="highlight_yellow">
Due to the large size of this archive, the results have been
truncated. The list below is incomplete!
</div>
{/if}
<ZipItem item={zip} /> <ZipItem item={zip} />
</TextBlock> </TextBlock>
{:else if status === "parse_failed"} {:else if status === "parse_failed"}