fix uri encode error

This commit is contained in:
monoid 2023-01-06 18:17:36 +09:00
parent ceb30a6427
commit 2726e2abaf
6 changed files with 14 additions and 6 deletions

View File

@ -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) {
<img src={asset("/icon/sort-alpha-down.svg")} /> Sort Alphabet
</button>
</li>
<ListItem key=".." href={`/dir/${join(data.path,"..")}`}
<ListItem key=".." href={`/dir/${encodePath(join(data.path,".."))}`}
icon="/icon/back.svg"
>...</ListItem>
{files.map((file) => (
<ListItem key={file.name} href={`/dir/${join(data.path,file.name)}`}
<ListItem key={file.name} href={`/dir/${encodePath(join(data.path,file.name))}`}
icon={file.isDirectory ? "/icon/folder.svg": extToIcon(extname(file.name))}
>{file.name}</ListItem>
))}

View File

@ -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: {
<ul class="mt-4">
{docs.map((doc) => (
<li class="mt-2">
<a href={`/dir/${doc.path}`}> {doc.path}</a>
<a href={`/dir/${encodePath(doc.path)}`}> {doc.path}</a>
</li>
))}
</ul>

View File

@ -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 (
<div class="p-4 mx-auto max-w-screen-md">
<UpList path={path} />

View File

@ -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) => (
<>
<span class="p-2">/</span>
<a class="flex flex-wrap p-2 hover:bg-gray-400 rounded-sm" href={`/dir/${cur}`}>
<a class="flex flex-wrap p-2 hover:bg-gray-400 rounded-sm" href={`/dir/${encodePath(cur)}`}>
<img src={asset("/icon/folder.svg")} />
<span class="ml-1">{up}</span>
</a>

View File

@ -15,7 +15,7 @@ export default function Home() {
<p class="my-6">
This is a simple file server. It serves files from the <code>CWD</code>.
</p>
<a href="/dir/">Go To CWD</a>
<a href="/dir/">Go To CWD</a> | <a href="/doc/">Doc</a>
<hr></hr>
<a href="/login">Login</a> | <a href="/api/logout">Logout</a>
</div>

View File

@ -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("/");
}