2023-05-17 15:34:56 +02:00
|
|
|
<script>
|
2024-08-09 13:02:07 +02:00
|
|
|
import { onMount, tick } from "svelte";
|
2023-05-19 17:17:05 +02:00
|
|
|
import Spinner from "../../util/Spinner.svelte";
|
2024-11-19 15:31:51 +01:00
|
|
|
import { fs_node_type, fs_thumbnail_url } from "../FilesystemAPI.mjs";
|
2023-05-17 15:34:56 +02:00
|
|
|
import FileManager from "../filemanager/FileManager.svelte";
|
|
|
|
import Audio from "./Audio.svelte";
|
2023-05-17 19:27:46 +02:00
|
|
|
import File from "./File.svelte";
|
2023-05-17 15:34:56 +02:00
|
|
|
import Image from "./Image.svelte";
|
|
|
|
import Pdf from "./PDF.svelte";
|
2023-05-17 19:27:46 +02:00
|
|
|
import Text from "./Text.svelte";
|
2023-05-17 15:34:56 +02:00
|
|
|
import Video from "./Video.svelte";
|
2023-05-19 17:17:05 +02:00
|
|
|
import Torrent from "./Torrent.svelte";
|
|
|
|
import Zip from "./Zip.svelte";
|
2024-02-16 14:50:34 +01:00
|
|
|
import CustomBanner from "./CustomBanner.svelte";
|
2024-09-12 15:11:50 +02:00
|
|
|
import { stats } from "../../lib/StatsSocket.js"
|
2024-09-11 14:18:03 +02:00
|
|
|
import SlowDown from "../../layout/SlowDown.svelte";
|
2023-05-17 15:34:56 +02:00
|
|
|
|
2024-08-09 13:02:07 +02:00
|
|
|
export let nav
|
2024-09-10 18:51:13 +02:00
|
|
|
export let upload_widget
|
2023-05-17 15:34:56 +02:00
|
|
|
export let edit_window
|
2023-05-19 17:17:05 +02:00
|
|
|
|
|
|
|
let viewer
|
|
|
|
let viewer_type = ""
|
2023-05-30 15:51:10 +02:00
|
|
|
let last_path = ""
|
2023-05-19 17:17:05 +02:00
|
|
|
|
2024-08-09 13:02:07 +02:00
|
|
|
onMount(() => nav.subscribe(state_update))
|
|
|
|
|
|
|
|
const state_update = async () => {
|
|
|
|
if (!nav.initialized || nav.base.path === last_path) {
|
2023-05-30 15:51:10 +02:00
|
|
|
return
|
|
|
|
}
|
2024-08-09 13:02:07 +02:00
|
|
|
last_path = nav.base.path
|
2023-05-30 15:51:10 +02:00
|
|
|
|
2023-05-19 17:17:05 +02:00
|
|
|
// Update the viewer area with the right viewer type
|
2024-08-09 13:02:07 +02:00
|
|
|
viewer_type = fs_node_type(nav.base)
|
2023-05-19 17:17:05 +02:00
|
|
|
|
2024-08-09 13:02:07 +02:00
|
|
|
console.debug("Previewing file", nav.base, "viewer type", viewer_type)
|
2023-05-19 17:17:05 +02:00
|
|
|
|
|
|
|
// Render the viewer component and set the file type
|
|
|
|
await tick()
|
2023-11-16 16:33:35 +01:00
|
|
|
if (viewer && viewer.update) {
|
2023-05-19 17:17:05 +02:00
|
|
|
viewer.update()
|
|
|
|
}
|
|
|
|
}
|
2024-04-11 20:32:55 +02:00
|
|
|
|
|
|
|
export const toggle_playback = () => {
|
|
|
|
if (viewer && viewer.toggle_playback) {
|
|
|
|
viewer.toggle_playback()
|
2025-01-27 21:05:18 +01:00
|
|
|
return true
|
2024-04-11 20:32:55 +02:00
|
|
|
}
|
2025-01-27 21:05:18 +01:00
|
|
|
return false
|
2024-04-11 20:32:55 +02:00
|
|
|
}
|
2024-08-14 19:58:25 +02:00
|
|
|
export const seek = delta => {
|
|
|
|
if (viewer && viewer.seek) {
|
|
|
|
viewer.seek(delta)
|
|
|
|
}
|
|
|
|
}
|
2023-05-17 15:34:56 +02:00
|
|
|
</script>
|
|
|
|
|
2023-05-25 17:06:17 +02:00
|
|
|
{#if viewer_type === ""}
|
|
|
|
<div class="center">
|
|
|
|
<Spinner></Spinner>
|
|
|
|
</div>
|
|
|
|
{:else if viewer_type === "dir"}
|
2024-09-10 18:51:13 +02:00
|
|
|
<FileManager nav={nav} upload_widget={upload_widget} edit_window={edit_window}>
|
2024-08-09 13:02:07 +02:00
|
|
|
<CustomBanner path={$nav.path}/>
|
2024-02-16 14:50:34 +01:00
|
|
|
</FileManager>
|
2024-09-05 17:28:31 +02:00
|
|
|
{:else if $nav.context.premium_transfer === false && $stats.limits.transfer_limit_used > $stats.limits.transfer_limit}
|
|
|
|
<SlowDown
|
|
|
|
on:download
|
|
|
|
file_size={$nav.base.file_size}
|
|
|
|
file_name={$nav.base.name}
|
|
|
|
file_type={$nav.base.file_type}
|
|
|
|
icon_href={fs_thumbnail_url($nav.base.path, 256, 256)}
|
|
|
|
/>
|
2023-05-25 17:06:17 +02:00
|
|
|
{:else if viewer_type === "audio"}
|
2024-08-09 13:02:07 +02:00
|
|
|
<Audio nav={nav} bind:this={viewer}>
|
|
|
|
<CustomBanner path={$nav.path}/>
|
2024-02-16 14:50:34 +01:00
|
|
|
</Audio>
|
2023-05-25 17:06:17 +02:00
|
|
|
{:else if viewer_type === "image"}
|
2024-08-09 13:02:07 +02:00
|
|
|
<Image nav={nav} bind:this={viewer}/>
|
2023-05-25 17:06:17 +02:00
|
|
|
{:else if viewer_type === "video"}
|
2024-08-09 13:02:07 +02:00
|
|
|
<Video nav={nav} bind:this={viewer} on:open_sibling/>
|
2023-05-25 17:06:17 +02:00
|
|
|
{:else if viewer_type === "pdf"}
|
2024-08-09 13:02:07 +02:00
|
|
|
<Pdf nav={nav}/>
|
2023-05-25 17:06:17 +02:00
|
|
|
{:else if viewer_type === "text"}
|
2024-08-09 13:02:07 +02:00
|
|
|
<Text nav={nav} bind:this={viewer}>
|
|
|
|
<CustomBanner path={$nav.path}/>
|
2024-02-16 14:50:34 +01:00
|
|
|
</Text>
|
2023-05-25 17:06:17 +02:00
|
|
|
{:else if viewer_type === "torrent"}
|
2024-08-09 13:47:10 +02:00
|
|
|
<Torrent nav={nav} bind:this={viewer} on:download>
|
2024-08-09 13:02:07 +02:00
|
|
|
<CustomBanner path={$nav.path}/>
|
2024-02-16 14:50:34 +01:00
|
|
|
</Torrent>
|
2023-05-25 17:06:17 +02:00
|
|
|
{:else if viewer_type === "zip"}
|
2024-08-09 13:47:10 +02:00
|
|
|
<Zip nav={nav} bind:this={viewer} on:download>
|
2024-08-09 13:02:07 +02:00
|
|
|
<CustomBanner path={$nav.path}/>
|
2024-02-16 14:50:34 +01:00
|
|
|
</Zip>
|
2023-05-25 17:06:17 +02:00
|
|
|
{:else}
|
2024-08-09 13:02:07 +02:00
|
|
|
<File nav={nav} on:download>
|
|
|
|
<CustomBanner path={$nav.path}/>
|
2024-02-16 14:50:34 +01:00
|
|
|
</File>
|
2023-05-25 17:06:17 +02:00
|
|
|
{/if}
|
2023-05-17 15:34:56 +02:00
|
|
|
|
|
|
|
<style>
|
2023-05-19 17:17:05 +02:00
|
|
|
.center{
|
|
|
|
position: relative;
|
|
|
|
display: block;
|
|
|
|
margin: auto;
|
|
|
|
width: 100px;
|
|
|
|
max-width: 100%;
|
|
|
|
height: 100px;
|
|
|
|
max-height: 100%;
|
|
|
|
top: 50%;
|
|
|
|
transform: translateY(-50%);
|
|
|
|
}
|
2023-05-17 15:34:56 +02:00
|
|
|
</style>
|