Compare commits
2 Commits
4b8bd11a4c
...
39e0019ce3
| Author | SHA1 | Date | |
|---|---|---|---|
| 39e0019ce3 | |||
| e88b137d2b |
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { fs_encode_path } from "lib/FilesystemAPI";
|
||||
import { fs_encode_path } from "lib/FilesystemAPI.svelte";
|
||||
import { path_link, type FSNavigator } from "./FSNavigator";
|
||||
import FileMenu from "./filemanager/FileMenu.svelte";
|
||||
import EditWindow from "./edit_window/EditWindow.svelte";
|
||||
|
||||
@@ -3,7 +3,7 @@ import { run } from 'svelte/legacy';
|
||||
import Chart from "util/Chart.svelte";
|
||||
import { formatDataVolume, formatDate, formatThousands } from "util/Formatting";
|
||||
import Modal from "util/Modal.svelte";
|
||||
import { fs_path_url, fs_share_hotlink_url, fs_share_url, fs_timeseries, type FSNode } from "lib/FilesystemAPI";
|
||||
import { fs_path_url, fs_share_hotlink_url, fs_share_url, fs_timeseries, type FSNode } from "lib/FilesystemAPI.svelte";
|
||||
import { color_by_name } from "util/Util";
|
||||
import { tick } from "svelte";
|
||||
import CopyButton from "layout/CopyButton.svelte";
|
||||
|
||||
48
svelte/src/filesystem/ErrorPage.svelte
Normal file
48
svelte/src/filesystem/ErrorPage.svelte
Normal file
@@ -0,0 +1,48 @@
|
||||
<script lang="ts">
|
||||
import TextBlock from "layout/TextBlock.svelte";
|
||||
import { type FSNavigator } from "./FSNavigator";
|
||||
import { onMount } from "svelte";
|
||||
import { breadcrumbs_store } from "wrap/BreadcrumbStore";
|
||||
|
||||
let {
|
||||
nav
|
||||
}: {
|
||||
nav: FSNavigator;
|
||||
} = $props();
|
||||
|
||||
onMount(() => {
|
||||
return nav.subscribe(nav => {
|
||||
breadcrumbs_store.set(breadcrumbs)
|
||||
})
|
||||
|
||||
|
||||
})
|
||||
</script>
|
||||
|
||||
{#snippet breadcrumbs()}
|
||||
{$nav.navigation_error}
|
||||
{/snippet}
|
||||
|
||||
<TextBlock>
|
||||
{#if $nav.navigation_error === "not_found" || $nav.navigation_error === "path_not_found"}
|
||||
<h1>Page not found</h1>
|
||||
<p>
|
||||
This page could not be found.
|
||||
</p>
|
||||
{:else if $nav.navigation_error === "permission_denied" || $nav.navigation_error === "forbidden"}
|
||||
<h1>Permission denied</h1>
|
||||
<p>
|
||||
You are not allowed to access this resource.
|
||||
</p>
|
||||
{:else if $nav.navigation_error === "unavailable_for_legal_reasons"}
|
||||
<h1>Unavailable for legal reasons</h1>
|
||||
<p>
|
||||
This content has been removed for breaking the law.
|
||||
</p>
|
||||
{:else}
|
||||
<h1>Unknown error code</h1>
|
||||
<p>
|
||||
{$nav.navigation_error}
|
||||
</p>
|
||||
{/if}
|
||||
</TextBlock>
|
||||
@@ -1,6 +1,6 @@
|
||||
import { loading_finish, loading_start } from "lib/Loading";
|
||||
import { fs_get_node, fs_encode_path, fs_split_path } from "lib/FilesystemAPI";
|
||||
import type { FSNode, FSPath, FSPermissions, FSContext } from "lib/FilesystemAPI";
|
||||
import { fs_get_node, fs_encode_path, fs_split_path } from "lib/FilesystemAPI.svelte";
|
||||
import type { FSNode, FSPath, FSPermissions, FSContext } from "lib/FilesystemAPI.svelte";
|
||||
|
||||
export class FSNavigator {
|
||||
// Parts of the raw API response
|
||||
@@ -54,6 +54,7 @@ export class FSNavigator {
|
||||
}
|
||||
|
||||
last_requested_path: string = ""
|
||||
navigation_error: string = ""
|
||||
navigate = async (path: string, push_history: boolean) => {
|
||||
if (path === this.last_requested_path) {
|
||||
console.debug("FSNavigator: Requested path ", path, " is equal to current path. Debouncing")
|
||||
@@ -72,14 +73,14 @@ export class FSNavigator {
|
||||
const resp = await fs_get_node(path)
|
||||
this.open_node(resp, push_history)
|
||||
} catch (err: any) {
|
||||
if (err.value && err.value === "path_not_found") {
|
||||
if (err.value !== undefined && err.value === "path_not_found") {
|
||||
if (path !== this.path[0].path && path !== "/" && path !== "") {
|
||||
console.debug("Path", path, "was not found, trying to navigate to parent")
|
||||
this.navigate(fs_split_path(path).parent, push_history)
|
||||
}
|
||||
} else if (err.message) {
|
||||
console.error(err)
|
||||
alert("Error: " + err.message)
|
||||
} else if (err.value !== undefined) {
|
||||
this.navigation_error = err.value
|
||||
this.notify_subscribers()
|
||||
} else {
|
||||
console.error(err)
|
||||
alert("Error: " + err)
|
||||
@@ -133,6 +134,7 @@ export class FSNavigator {
|
||||
this.children = node.children
|
||||
this.permissions = node.permissions
|
||||
this.context = node.context
|
||||
this.navigation_error = "" // Clear the error value
|
||||
this.initialized = true
|
||||
|
||||
console.debug("Opened node", node)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import { formatDataVolume, formatThousands } from "util/Formatting"
|
||||
import { fs_path_url } from "lib/FilesystemAPI";
|
||||
import { fs_path_url } from "lib/FilesystemAPI.svelte";
|
||||
import type { FSNavigator } from "./FSNavigator";
|
||||
|
||||
let {
|
||||
|
||||
@@ -11,6 +11,7 @@ import { css_from_path } from "filesystem/edit_window/Branding";
|
||||
import AffiliatePrompt from "user_home/AffiliatePrompt.svelte";
|
||||
import { current_page_store } from "wrap/RouterStore";
|
||||
import SearchBar from "./SearchBar.svelte";
|
||||
import ErrorPage from "./ErrorPage.svelte";
|
||||
|
||||
let file_preview: FilePreview = $state()
|
||||
let toolbar: Toolbar = $state()
|
||||
@@ -141,6 +142,7 @@ const keydown = (e: KeyboardEvent) => {
|
||||
|
||||
<svelte:window onkeydown={keydown} />
|
||||
|
||||
{#if $nav.navigation_error === ""}
|
||||
<div class="filesystem">
|
||||
<Breadcrumbs nav={nav} edit_window={edit_window}/>
|
||||
|
||||
@@ -164,6 +166,10 @@ const keydown = (e: KeyboardEvent) => {
|
||||
/>
|
||||
</div>
|
||||
|
||||
{:else}
|
||||
<ErrorPage nav={nav} />
|
||||
{/if}
|
||||
|
||||
<SearchBar bind:this={search_bar} nav={nav}/>
|
||||
|
||||
<DetailsWindow nav={nav} bind:this={details_window} bind:visible={details_visible} />
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { onMount, tick } from "svelte";
|
||||
import { fs_search, fs_encode_path, fs_thumbnail_url, FSNode } from "lib/FilesystemAPI";
|
||||
import { fs_search, fs_encode_path, fs_thumbnail_url, FSNode } from "lib/FilesystemAPI.svelte";
|
||||
import type { FSNavigator } from "filesystem/FSNavigator";
|
||||
import { loading_finish, loading_start } from "lib/Loading";
|
||||
import Modal from "util/Modal.svelte";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import type { FSNavigator } from "./FSNavigator";
|
||||
import { fs_node_icon, fs_share_hotlink_url, fs_share_url, fs_update, type FSNode, type FSPermissions } from "lib/FilesystemAPI";
|
||||
import { fs_node_icon, fs_share_hotlink_url, fs_share_url, fs_update, type FSNode, type FSPermissions } from "lib/FilesystemAPI.svelte";
|
||||
import { copy_text } from "util/Util";
|
||||
import CopyButton from "layout/CopyButton.svelte";
|
||||
import Dialog from "layout/Dialog.svelte";
|
||||
|
||||
@@ -3,7 +3,7 @@ import { copy_text } from "util/Util";
|
||||
import FileStats from "./FileStats.svelte";
|
||||
import type { FSNavigator } from "./FSNavigator";
|
||||
import EditWindow from "./edit_window/EditWindow.svelte";
|
||||
import { fs_share_url, path_is_shared } from "lib/FilesystemAPI";
|
||||
import { fs_share_url, path_is_shared } from "lib/FilesystemAPI.svelte";
|
||||
import ShareDialog from "./ShareDialog.svelte";
|
||||
import { bookmark_add, bookmark_del, bookmarks_store, is_bookmark } from "lib/Bookmarks";
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import Button from "layout/Button.svelte";
|
||||
import type { FSPermissions, NodeOptions } from "lib/FilesystemAPI";
|
||||
import type { FSPermissions, NodeOptions } from "lib/FilesystemAPI.svelte";
|
||||
import PermissionButton from "./PermissionButton.svelte";
|
||||
|
||||
let {
|
||||
|
||||
@@ -2,7 +2,7 @@ import parse from "pure-color/parse";
|
||||
import rgb2hsl from "pure-color/convert/rgb2hsl";
|
||||
import hsl2rgb from "pure-color/convert/hsl2rgb";
|
||||
import rgb2hex from "pure-color/convert/rgb2hex";
|
||||
import type { FSNode, FSNodeProperties } from "lib/FilesystemAPI";
|
||||
import type { FSNode, FSNodeProperties } from "lib/FilesystemAPI.svelte";
|
||||
|
||||
const text_contrast = 85
|
||||
const body_alpha = 0.9
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import ThemePresets from "./ThemePresets.svelte";
|
||||
import { fs_update, fs_node_type, type FSNode, type NodeOptions, type FSPermissions } from "lib/FilesystemAPI";
|
||||
import { fs_update, fs_node_type, type FSNode, type NodeOptions, type FSPermissions } from "lib/FilesystemAPI.svelte";
|
||||
import CustomBanner from "filesystem/viewers/CustomBanner.svelte";
|
||||
import HelpButton from "layout/HelpButton.svelte";
|
||||
import FilePicker from "filesystem/filemanager/FilePicker.svelte";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { fs_rename, fs_update, type FSNode, type FSPermissions, type NodeOptions } from "lib/FilesystemAPI";
|
||||
import { fs_rename, fs_update, type FSNode, type FSPermissions, type NodeOptions } from "lib/FilesystemAPI.svelte";
|
||||
import Modal from "util/Modal.svelte";
|
||||
import BrandingOptions from "./BrandingOptions.svelte";
|
||||
import { branding_from_props } from "./Branding";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import Button from "layout/Button.svelte";
|
||||
import { fs_trash, type FSNode } from "lib/FilesystemAPI";
|
||||
import { fs_trash, type FSNode } from "lib/FilesystemAPI.svelte";
|
||||
import type { FSNavigator } from "filesystem/FSNavigator";
|
||||
import { loading_finish, loading_start } from "lib/Loading";
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import ToggleButton from "layout/ToggleButton.svelte";
|
||||
import type { FSPermissions } from "lib/FilesystemAPI";
|
||||
import type { FSPermissions } from "lib/FilesystemAPI.svelte";
|
||||
|
||||
let {
|
||||
permissions = $bindable()
|
||||
|
||||
@@ -3,7 +3,7 @@ import { run } from 'svelte/legacy';
|
||||
import { domain_url } from "util/Util";
|
||||
import CopyButton from "layout/CopyButton.svelte";
|
||||
import { formatDate } from "util/Formatting";
|
||||
import { type FSNode, type NodeOptions } from "lib/FilesystemAPI";
|
||||
import { type FSNode, type NodeOptions } from "lib/FilesystemAPI.svelte";
|
||||
import AccessControl from "./AccessControl.svelte";
|
||||
|
||||
let {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import type { FSNodeProperties } from "lib/FilesystemAPI";
|
||||
import type { FSNodeProperties } from "lib/FilesystemAPI.svelte";
|
||||
|
||||
let {
|
||||
properties = $bindable({} as FSNodeProperties)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { fs_encode_path, fs_node_icon } from "lib/FilesystemAPI"
|
||||
import { fs_encode_path, fs_node_icon } from "lib/FilesystemAPI.svelte"
|
||||
import type { FSNavigator } from "filesystem/FSNavigator";
|
||||
import { FileAction, type FileActionHandler } from "./FileManagerLib";
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import { fs_mkdir } from "lib/FilesystemAPI";
|
||||
import { fs_mkdir } from "lib/FilesystemAPI.svelte";
|
||||
import Button from "layout/Button.svelte";
|
||||
import type { FSNavigator } from "filesystem/FSNavigator";
|
||||
import { loading_finish, loading_start } from "lib/Loading";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { fs_rename, fs_trash, FSNode } from "lib/FilesystemAPI"
|
||||
import { fs_rename, fs_trash, FSNode } from "lib/FilesystemAPI.svelte"
|
||||
import { onMount } from "svelte"
|
||||
import CreateDirectory from "./CreateDirectory.svelte"
|
||||
import ListView from "./ListView.svelte"
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { FSNavigator } from "filesystem/FSNavigator";
|
||||
import Button from "layout/Button.svelte";
|
||||
import Dialog from "layout/Dialog.svelte";
|
||||
import { bookmark_add, bookmark_del, bookmarks_store, is_bookmark } from "lib/Bookmarks";
|
||||
import { fs_trash, type FSNode } from "lib/FilesystemAPI";
|
||||
import { fs_trash, type FSNode } from "lib/FilesystemAPI.svelte";
|
||||
import { loading_finish, loading_start } from "lib/Loading";
|
||||
import { tick } from "svelte";
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import GalleryView from "./GalleryView.svelte"
|
||||
import CompactView from "./CompactView.svelte"
|
||||
import Modal from "util/Modal.svelte";
|
||||
import { FSNavigator, path_link } from "filesystem/FSNavigator";
|
||||
import { fs_encode_path, type FSNode } from "lib/FilesystemAPI";
|
||||
import { fs_encode_path, type FSNode } from "lib/FilesystemAPI.svelte";
|
||||
import { FileAction, type FileActionHandler } from "./FileManagerLib";
|
||||
|
||||
let nav = $state(new FSNavigator(false))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { fs_node_icon, fs_node_type, fs_encode_path } from "lib/FilesystemAPI";
|
||||
import { fs_node_icon, fs_node_type, fs_encode_path } from "lib/FilesystemAPI.svelte";
|
||||
import type { FSNavigator } from "filesystem/FSNavigator";
|
||||
import { FileAction, type FileActionHandler } from "./FileManagerLib";
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { formatDataVolume } from "util/Formatting";
|
||||
import { fs_encode_path, fs_node_icon } from "lib/FilesystemAPI"
|
||||
import { fs_encode_path, fs_node_icon } from "lib/FilesystemAPI.svelte"
|
||||
import type { FSNavigator } from "filesystem/FSNavigator";
|
||||
import SortButton from "layout/SortButton.svelte";
|
||||
import { FileAction, type FileActionHandler } from "./FileManagerLib";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { formatDataVolume, formatDate } from "util/Formatting";
|
||||
import { fs_check_response, fs_encode_path, fs_get_trash, fs_node_icon, fs_path_url, type TrashEntry } from "lib/FilesystemAPI";
|
||||
import { fs_check_response, fs_encode_path, fs_get_trash, fs_node_icon, fs_path_url, type TrashEntry } from "lib/FilesystemAPI.svelte";
|
||||
import { loading_finish, loading_start } from "lib/Loading";
|
||||
import { onMount } from "svelte";
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
//
|
||||
// on_error is called when the upload has failed. The parameters are the error
|
||||
|
||||
import { fs_path_url, type GenericResponse } from "lib/FilesystemAPI"
|
||||
import { fs_path_url, type GenericResponse } from "lib/FilesystemAPI.svelte"
|
||||
|
||||
// code and an error message
|
||||
export const upload_file = (
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte'
|
||||
import { fs_path_url, fs_encode_path, fs_node_icon, FSNode } from "lib/FilesystemAPI"
|
||||
import { fs_path_url, fs_encode_path, fs_node_icon, FSNode } from "lib/FilesystemAPI.svelte"
|
||||
import TextBlock from "layout/TextBlock.svelte"
|
||||
import type { FSNavigator } from 'filesystem/FSNavigator';
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import type { FSNode } from 'lib/FilesystemAPI';
|
||||
import type { FSNode } from 'lib/FilesystemAPI.svelte';
|
||||
import { run } from 'svelte/legacy';
|
||||
|
||||
let { path = [] }: {path: FSNode[]} = $props();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import IconBlock from "layout/IconBlock.svelte";
|
||||
import { fs_thumbnail_url, FSNode } from "lib/FilesystemAPI";
|
||||
import { fs_thumbnail_url, FSNode } from "lib/FilesystemAPI.svelte";
|
||||
import TextBlock from "layout/TextBlock.svelte"
|
||||
import { formatDataVolume, formatDate } from "util/Formatting";
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { onMount, tick } from "svelte";
|
||||
import Spinner from "util/Spinner.svelte";
|
||||
import { fs_node_type } from "lib/FilesystemAPI";
|
||||
import { fs_node_type } from "lib/FilesystemAPI.svelte";
|
||||
import FileManager from "filesystem/filemanager/FileManager.svelte";
|
||||
import TrashBin from "filesystem/filemanager/TrashBin.svelte";
|
||||
import Audio from "./Audio.svelte";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { swipe_nav } from "lib/SwipeNavigate";
|
||||
import { fs_path_url } from "lib/FilesystemAPI";
|
||||
import { fs_path_url } from "lib/FilesystemAPI.svelte";
|
||||
import type { FSNavigator } from "filesystem/FSNavigator";
|
||||
import { loading_finish, loading_start } from "lib/Loading";
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { fs_path_url, FSNode } from "lib/FilesystemAPI";
|
||||
import { fs_path_url, FSNode } from "lib/FilesystemAPI.svelte";
|
||||
|
||||
let { node }: { node: FSNode } = $props();
|
||||
</script>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { tick } from "svelte";
|
||||
import { fs_path_url, type FSNode } from "lib/FilesystemAPI";
|
||||
import { fs_path_url, type FSNode } from "lib/FilesystemAPI.svelte";
|
||||
|
||||
let {
|
||||
node,
|
||||
|
||||
@@ -18,7 +18,7 @@ import { formatDate } from "util/Formatting"
|
||||
import TorrentItem from "./TorrentItem.svelte"
|
||||
import IconBlock from "layout/IconBlock.svelte";
|
||||
import TextBlock from "layout/TextBlock.svelte"
|
||||
import { fs_node_icon, fs_path_url, FSNode } from "lib/FilesystemAPI";
|
||||
import { fs_node_icon, fs_path_url, FSNode } from "lib/FilesystemAPI.svelte";
|
||||
import CopyButton from "layout/CopyButton.svelte";
|
||||
import { loading_finish, loading_start } from "lib/Loading";
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { onMount, tick } from "svelte";
|
||||
import { video_position } from "lib/VideoPosition";
|
||||
import { fs_path_url, FSNode } from "lib/FilesystemAPI";
|
||||
import { fs_path_url, FSNode } from "lib/FilesystemAPI.svelte";
|
||||
|
||||
let {
|
||||
node,
|
||||
|
||||
@@ -12,7 +12,7 @@ import { formatDataVolume, formatDate } from "util/Formatting"
|
||||
import ZipItem from "filesystem/viewers/ZipItem.svelte";
|
||||
import IconBlock from "layout/IconBlock.svelte";
|
||||
import TextBlock from "layout/TextBlock.svelte"
|
||||
import { fs_node_icon, fs_path_url, FSNode } from "lib/FilesystemAPI";
|
||||
import { fs_node_icon, fs_path_url, FSNode } from "lib/FilesystemAPI.svelte";
|
||||
import { loading_finish, loading_start } from "lib/Loading";
|
||||
|
||||
let {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { writable } from "svelte/store"
|
||||
import { fs_check_response, fs_path_url, type FSNode } from "./FilesystemAPI"
|
||||
import { fs_check_response, fs_path_url, type FSNode } from "./FilesystemAPI.svelte"
|
||||
import { loading_finish, loading_start } from "lib/Loading"
|
||||
import { get_user } from "lib/NovaAPI"
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { bookmarks_save, bookmarks_store } from "lib/Bookmarks";
|
||||
import { fs_encode_path, fs_thumbnail_url } from "lib/FilesystemAPI";
|
||||
import { fs_encode_path, fs_thumbnail_url } from "lib/FilesystemAPI.svelte";
|
||||
import { highlight_current_page } from "lib/HighlightCurrentPage";
|
||||
import MenuEntry from "./MenuEntry.svelte";
|
||||
import { flip } from "svelte/animate";
|
||||
|
||||
@@ -9,7 +9,7 @@ import { formatDataVolume } from "util/Formatting";
|
||||
import Router from "wrap/Router.svelte";
|
||||
import Bookmarks from "./Bookmarks.svelte";
|
||||
import { onMount } from "svelte";
|
||||
import { fs_get_node } from "lib/FilesystemAPI";
|
||||
import { fs_get_node } from "lib/FilesystemAPI.svelte";
|
||||
import { css_from_path } from "filesystem/edit_window/Branding";
|
||||
import { loading_run, loading_store } from "lib/Loading";
|
||||
import Spinner from "util/Spinner.svelte";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { global_navigator } from "filesystem/FSNavigator";
|
||||
import { fs_encode_path, fs_node_icon, FSNode } from "lib/FilesystemAPI";
|
||||
import { fs_encode_path, fs_node_icon, FSNode } from "lib/FilesystemAPI.svelte";
|
||||
import { highlight_current_page } from "lib/HighlightCurrentPage";
|
||||
import { onMount } from "svelte";
|
||||
import MenuEntry from "./MenuEntry.svelte";
|
||||
|
||||
@@ -25,22 +25,31 @@ func (wc *WebController) serveDirectory(w http.ResponseWriter, r *http.Request,
|
||||
return
|
||||
}
|
||||
|
||||
pdapi := wc.api.RealIP(util.RemoteAddress(r)).RealAgent(r.UserAgent())
|
||||
var pdapi = wc.api.RealIP(util.RemoteAddress(r)).RealAgent(r.UserAgent())
|
||||
|
||||
if apikey, err := wc.getAPIKey(r); err == nil {
|
||||
pdapi = pdapi.Login(apikey)
|
||||
}
|
||||
|
||||
node, err := pdapi.GetFilesystemPath(path)
|
||||
if err != nil {
|
||||
if apiErr, ok := errors.AsType[pixelapi.Error](err); ok {
|
||||
// Set the proper response code for the error message
|
||||
switch apiErr.StatusCode {
|
||||
case "not_found", "path_not_found":
|
||||
wc.serveNotFound(w, r)
|
||||
case "forbidden":
|
||||
wc.serveForbidden(w, r)
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
case "forbidden", "permission_denied":
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
case "unavailable_for_legal_reasons":
|
||||
w.WriteHeader(http.StatusUnavailableForLegalReasons)
|
||||
case "authentication_required":
|
||||
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
||||
case "unavailable_for_legal_reasons":
|
||||
wc.serveUnavailableForLegalReasons(w, r)
|
||||
case "permission_denied":
|
||||
wc.serveForbidden(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
// Let the JS figure it out
|
||||
if err = wc.templates.Run(w, r, "wrap", td); err != nil {
|
||||
log.Error("Failed to run template: %s", err)
|
||||
}
|
||||
} else {
|
||||
log.Error("Failed to get path: %s", err)
|
||||
@@ -57,21 +66,3 @@ func (wc *WebController) serveDirectory(w http.ResponseWriter, r *http.Request,
|
||||
log.Error("Error executing template filesystem: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (wc *WebController) serveForbidden(w http.ResponseWriter, r *http.Request) {
|
||||
log.Debug("Forbidden: %s", r.URL)
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
if err := wc.templates.Run(w, r, "wrap", wc.newTemplateData(r)); err != nil {
|
||||
log.Error("Failed to run template 403: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (wc *WebController) serveNotFound(w http.ResponseWriter, r *http.Request) {
|
||||
log.Debug("Not Found: %s", r.URL)
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
wc.templates.Run(w, r, "404", wc.newTemplateData(r))
|
||||
}
|
||||
func (wc *WebController) serveUnavailableForLegalReasons(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusUnavailableForLegalReasons)
|
||||
wc.templates.Run(w, r, "451", wc.newTemplateData(r))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user