2025-03-28 14:16:20 +01:00
|
|
|
<script lang="ts" context="module">
|
|
|
|
export type ZipEntry = {
|
|
|
|
size: number,
|
|
|
|
children?: {[index: string]: ZipEntry},
|
|
|
|
properties?: string[],
|
|
|
|
download_url?: string, // Added by us
|
|
|
|
details_open?: boolean, // Added by us
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<script lang="ts">
|
2023-05-19 17:17:05 +02:00
|
|
|
import { createEventDispatcher } from "svelte";
|
2025-03-28 14:16:20 +01:00
|
|
|
import { formatDataVolume, formatDate } from "util/Formatting"
|
2025-09-24 15:37:57 +02:00
|
|
|
import ZipItem from "filesystem/viewers/ZipItem.svelte";
|
2025-03-27 15:38:59 +01:00
|
|
|
import IconBlock from "layout/IconBlock.svelte";
|
|
|
|
import TextBlock from "layout/TextBlock.svelte"
|
2025-10-09 15:48:23 +02:00
|
|
|
import { fs_node_icon, fs_path_url } from "lib/FilesystemAPI";
|
2025-03-28 14:16:20 +01:00
|
|
|
import type { FSNavigator } from "filesystem/FSNavigator";
|
2025-10-09 15:48:23 +02:00
|
|
|
import { loading_finish, loading_start } from "lib/Loading";
|
2023-05-19 17:17:05 +02:00
|
|
|
|
|
|
|
let dispatch = createEventDispatcher()
|
|
|
|
|
2025-03-28 14:16:20 +01:00
|
|
|
export let nav: FSNavigator
|
2023-05-19 17:17:05 +02:00
|
|
|
|
|
|
|
let status = "loading"
|
|
|
|
|
2025-03-28 14:16:20 +01:00
|
|
|
let zip: ZipEntry = {size: 0} as ZipEntry
|
2023-05-19 17:17:05 +02:00
|
|
|
let uncomp_size = 0
|
|
|
|
let comp_ratio = 0
|
2024-02-16 18:02:51 +01:00
|
|
|
let archive_type = ""
|
2024-12-04 15:06:58 +01:00
|
|
|
let truncated = false
|
2023-05-19 17:17:05 +02:00
|
|
|
|
|
|
|
export const update = async () => {
|
2024-12-04 15:06:58 +01:00
|
|
|
if (nav.base.file_type === "application/x-7z-compressed") {
|
2024-02-16 18:02:51 +01:00
|
|
|
archive_type = "7z"
|
2024-12-04 15:06:58 +01:00
|
|
|
} else {
|
|
|
|
archive_type = ""
|
2024-02-16 18:02:51 +01:00
|
|
|
}
|
|
|
|
|
2023-05-19 17:17:05 +02:00
|
|
|
try {
|
2025-10-09 15:48:23 +02:00
|
|
|
loading_start()
|
2024-12-04 11:33:31 +01:00
|
|
|
status = "loading"
|
2024-08-09 13:02:07 +02:00
|
|
|
let resp = await fetch(fs_path_url(nav.base.path)+"?zip_info")
|
2023-05-19 17:17:05 +02:00
|
|
|
|
|
|
|
if (resp.status >= 400) {
|
|
|
|
status = "parse_failed"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2025-03-28 14:16:20 +01:00
|
|
|
zip = await resp.json() as ZipEntry
|
2023-05-19 17:17:05 +02:00
|
|
|
|
2024-02-16 18:02:51 +01:00
|
|
|
// 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
|
2024-12-04 15:06:58 +01:00
|
|
|
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")
|
2024-02-16 18:02:51 +01:00
|
|
|
}
|
|
|
|
|
2023-05-19 17:17:05 +02:00
|
|
|
uncomp_size = recursive_size(zip)
|
2024-08-09 13:02:07 +02:00
|
|
|
comp_ratio = (uncomp_size / nav.base.file_size)
|
2024-12-04 11:33:31 +01:00
|
|
|
status = "finished"
|
2023-05-19 17:17:05 +02:00
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
2024-12-04 11:33:31 +01:00
|
|
|
status = "parse_failed"
|
2023-05-19 17:17:05 +02:00
|
|
|
} finally {
|
2025-10-09 15:48:23 +02:00
|
|
|
loading_finish()
|
2023-05-19 17:17:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-03-28 14:16:20 +01:00
|
|
|
const recursive_set_url = (parent_path: string, file: ZipEntry) => {
|
2024-02-16 18:02:51 +01:00
|
|
|
file.download_url = parent_path
|
|
|
|
|
2025-03-28 14:16:20 +01:00
|
|
|
if (file.children !== undefined) {
|
|
|
|
for (const [name, child] of Object.entries(file.children)) {
|
|
|
|
recursive_set_url(file.download_url + "/" + name, child)
|
|
|
|
}
|
2024-02-16 18:02:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-03-28 14:16:20 +01:00
|
|
|
const recursive_size = (file: ZipEntry) => {
|
2023-05-19 17:17:05 +02:00
|
|
|
let size = file.size
|
|
|
|
|
2025-03-28 14:16:20 +01:00
|
|
|
if (file.children !== undefined) {
|
|
|
|
for (const v of Object.values(file.children)) {
|
|
|
|
size += recursive_size(v)
|
|
|
|
}
|
2023-05-19 17:17:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return the total size of this file and all its children
|
|
|
|
return size
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2024-02-16 14:50:34 +01:00
|
|
|
<slot></slot>
|
|
|
|
|
2024-08-09 13:02:07 +02:00
|
|
|
<h1>{$nav.base.name}</h1>
|
2023-05-19 17:17:05 +02:00
|
|
|
|
2024-08-09 13:02:07 +02:00
|
|
|
<IconBlock icon_href={fs_node_icon($nav.base, 256, 256)}>
|
2024-02-16 18:02:51 +01:00
|
|
|
{#if archive_type === "7z"}
|
|
|
|
This is a 7-zip archive. You will need
|
|
|
|
<a href="https://www.7-zip.org/">7-zip</a> or compatible software to
|
|
|
|
extract it<br/>
|
|
|
|
{/if}
|
|
|
|
|
2024-08-09 13:02:07 +02:00
|
|
|
Compressed size: {formatDataVolume($nav.base.file_size, 3)}<br/>
|
2024-12-04 15:06:58 +01:00
|
|
|
{#if !truncated}
|
|
|
|
Uncompressed size: {formatDataVolume(zip.size, 3)} (Ratio: {comp_ratio.toFixed(2)}x)<br/>
|
|
|
|
{/if}
|
2024-08-09 13:02:07 +02:00
|
|
|
Uploaded on: {formatDate($nav.base.created, true, true, true)}
|
2023-05-19 17:17:05 +02:00
|
|
|
<br/>
|
|
|
|
<button class="button_highlight" on:click={() => {dispatch("download")}}>
|
|
|
|
<i class="icon">download</i>
|
|
|
|
<span>Download</span>
|
|
|
|
</button>
|
|
|
|
</IconBlock>
|
|
|
|
|
|
|
|
{#if status === "finished"}
|
|
|
|
<TextBlock>
|
|
|
|
<h2>Files in this zip archive</h2>
|
2024-12-04 15:06:58 +01:00
|
|
|
{#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}
|
|
|
|
|
2023-05-19 17:17:05 +02:00
|
|
|
<ZipItem item={zip} />
|
|
|
|
</TextBlock>
|
|
|
|
{:else if status === "parse_failed"}
|
|
|
|
<TextBlock>
|
|
|
|
<p>
|
2024-08-09 14:09:26 +02:00
|
|
|
Zip archive could not be parsed. This usually means that the archive
|
|
|
|
is encrypted or that it uses an unsupported compression format.
|
2023-05-19 17:17:05 +02:00
|
|
|
</p>
|
|
|
|
</TextBlock>
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
<style>
|
|
|
|
h1 {
|
|
|
|
text-shadow: 1px 1px 3px var(--shadow_color);
|
|
|
|
line-break: anywhere;
|
|
|
|
}
|
|
|
|
</style>
|