From 2726e2abaf5aeb52af704a4319f2b465135980af Mon Sep 17 00:00:00 2001 From: monoid Date: Fri, 6 Jan 2023 18:17:36 +0900 Subject: [PATCH] fix uri encode error --- islands/DirList.tsx | 5 +++-- islands/DocSearch.tsx | 3 ++- islands/FileViewer.tsx | 3 ++- islands/UpList.tsx | 3 ++- routes/index.tsx | 2 +- util/util.ts | 4 ++++ 6 files changed, 14 insertions(+), 6 deletions(-) diff --git a/islands/DirList.tsx b/islands/DirList.tsx index 340d9e2..a4a8496 100644 --- a/islands/DirList.tsx +++ b/islands/DirList.tsx @@ -4,6 +4,7 @@ import { extname, join } from "path/posix.ts"; import { ComponentChild } from "preact"; import UpList from "./UpList.tsx"; import {extToIcon} from "../src/media.ts"; +import { encodePath } from "../util/util.ts"; function ListItem(props:{ href: string, @@ -47,11 +48,11 @@ export function DirList(props: DirListProps) { Sort Alphabet - ... {files.map((file) => ( - {file.name} ))} diff --git a/islands/DocSearch.tsx b/islands/DocSearch.tsx index df01048..b94e6af 100644 --- a/islands/DocSearch.tsx +++ b/islands/DocSearch.tsx @@ -1,6 +1,7 @@ import { Doc } from "../src/collect.ts"; import { useEffect, useState } from "preact/hooks"; import { Index } from "../src/client_search.ts"; +import { encodePath } from "../util/util.ts"; function SearchBar(props:{ search?: string; @@ -35,7 +36,7 @@ export default function DocSearch(props: { diff --git a/islands/FileViewer.tsx b/islands/FileViewer.tsx index e70fee8..35c3d70 100644 --- a/islands/FileViewer.tsx +++ b/islands/FileViewer.tsx @@ -1,10 +1,11 @@ import RenderView from "./ContentRenderer.tsx"; import UpList from "./UpList.tsx"; import { extname } from "path/mod.ts"; +import { encodePath } from "../util/util.ts"; export default function FileViewer(props: { path: string }) { const { path } = props; - const srcPath = `/fs/${path}`; + const srcPath = `/fs/${encodePath(path)}`; return (
diff --git a/islands/UpList.tsx b/islands/UpList.tsx index 75b5853..8dd5a76 100644 --- a/islands/UpList.tsx +++ b/islands/UpList.tsx @@ -1,6 +1,7 @@ import { Head, asset } from "$fresh/runtime.ts"; import { join } from "path/posix.ts"; import { ComponentChild } from "preact"; +import { encodePath } from "../util/util.ts"; function stairs(path: string){ @@ -28,7 +29,7 @@ export default function UpList(props:{path: string}) { uplist.map(([cur, up], i) => ( <> / - + {up} diff --git a/routes/index.tsx b/routes/index.tsx index 3d51f33..b280231 100644 --- a/routes/index.tsx +++ b/routes/index.tsx @@ -15,7 +15,7 @@ export default function Home() {

This is a simple file server. It serves files from the CWD.

- Go To CWD + Go To CWD | Doc
Login | Logout
diff --git a/util/util.ts b/util/util.ts index 9c1a44e..ceb49fb 100644 --- a/util/util.ts +++ b/util/util.ts @@ -8,4 +8,8 @@ export function removePrefixFromPathname(pathname: string, prefix: string): stri ret = "."; } return ret; +} + +export function encodePath(path: string): string { + return path.split("/").map(encodeURIComponent).join("/"); } \ No newline at end of file