Add 7-zip file explorer

This commit is contained in:
2024-01-25 00:29:41 +01:00
parent 0ea5a20d74
commit 62a4a6426f
3 changed files with 27 additions and 5 deletions

View File

@@ -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"

View File

@@ -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) => {
<FileTitle title={file.name}/>
<IconBlock icon_href={file.icon_href}>
{#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}
Compressed size: {formatDataVolume(file.size, 3)}<br/>
Uncompressed size: {formatDataVolume(zip.size, 3)} (Ratio: {comp_ratio.toFixed(2)}x)<br/>
Uploaded on: {formatDate(file.date_upload, true, true, true)}
@@ -83,7 +100,7 @@ const recursive_set_url = (parent_path, file) => {
{#if status === "finished"}
<TextBlock>
<h2>Files in this zip archive</h2>
<h2>Files in this archive</h2>
<ZipItem item={zip} />
</TextBlock>
{:else if status === "parse_failed"}

View File

@@ -25,7 +25,12 @@ export let item = {
{#each Object.entries(item.children) as [name, child]}
{#if !child.children}
<li>
<a href={child.download_url}>{name}</a> ({formatDataVolume(child.size, 3)})<br/>
{#if child.download_url}
<a href={child.download_url}>{name}</a>
{:else}
{name}
{/if}
({formatDataVolume(child.size, 3)})<br/>
</li>
{/if}
{/each}