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 => {
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"

View File

@@ -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)}<br/>
Uncompressed size: {formatDataVolume(zip.size, 3)} (Ratio: {comp_ratio.toFixed(2)}x)<br/>
{#if !truncated}
Uncompressed size: {formatDataVolume(zip.size, 3)} (Ratio: {comp_ratio.toFixed(2)}x)<br/>
{/if}
Uploaded on: {formatDate(file.date_upload, true, true, true)}
<br/>
<button class="button_highlight" on:click={() => {dispatch("download")}}>
@@ -101,6 +107,13 @@ const recursive_set_url = (parent_path, file) => {
{#if status === "finished"}
<TextBlock>
<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} />
</TextBlock>
{:else if status === "parse_failed"}

View File

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

View File

@@ -251,7 +251,11 @@ export const fs_node_type = (node: FSNode) => {
return "torrent"
} else if (
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"
} else if (node.file_type.startsWith("image")) {

View File

@@ -19,12 +19,13 @@ let zip = {
let uncomp_size = 0
let comp_ratio = 0
let archive_type = ""
let truncated = false
export const update = async () => {
if (nav.base.file_type === "application/zip") {
archive_type = "zip"
} else if (nav.base.file_type === "application/x-7z-compressed") {
if (nav.base.file_type === "application/x-7z-compressed") {
archive_type = "7z"
} else {
archive_type = ""
}
try {
@@ -41,9 +42,12 @@ export const update = async () => {
// 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(fs_path_url(nav.base.path)+"?zip_file=", 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")
}
uncomp_size = recursive_size(zip)
@@ -95,7 +99,9 @@ const recursive_size = (file) => {
{/if}
Compressed size: {formatDataVolume($nav.base.file_size, 3)}<br/>
Uncompressed size: {formatDataVolume(zip.size, 3)} (Ratio: {comp_ratio.toFixed(2)}x)<br/>
{#if !truncated}
Uncompressed size: {formatDataVolume(zip.size, 3)} (Ratio: {comp_ratio.toFixed(2)}x)<br/>
{/if}
Uploaded on: {formatDate($nav.base.created, true, true, true)}
<br/>
<button class="button_highlight" on:click={() => {dispatch("download")}}>
@@ -107,6 +113,13 @@ const recursive_size = (file) => {
{#if status === "finished"}
<TextBlock>
<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} />
</TextBlock>
{:else if status === "parse_failed"}