fix uri encode error
This commit is contained in:
parent
ceb30a6427
commit
2726e2abaf
@ -4,6 +4,7 @@ import { extname, join } from "path/posix.ts";
|
|||||||
import { ComponentChild } from "preact";
|
import { ComponentChild } from "preact";
|
||||||
import UpList from "./UpList.tsx";
|
import UpList from "./UpList.tsx";
|
||||||
import {extToIcon} from "../src/media.ts";
|
import {extToIcon} from "../src/media.ts";
|
||||||
|
import { encodePath } from "../util/util.ts";
|
||||||
|
|
||||||
function ListItem(props:{
|
function ListItem(props:{
|
||||||
href: string,
|
href: string,
|
||||||
@ -47,11 +48,11 @@ export function DirList(props: DirListProps) {
|
|||||||
<img src={asset("/icon/sort-alpha-down.svg")} /> Sort Alphabet
|
<img src={asset("/icon/sort-alpha-down.svg")} /> Sort Alphabet
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
<ListItem key=".." href={`/dir/${join(data.path,"..")}`}
|
<ListItem key=".." href={`/dir/${encodePath(join(data.path,".."))}`}
|
||||||
icon="/icon/back.svg"
|
icon="/icon/back.svg"
|
||||||
>...</ListItem>
|
>...</ListItem>
|
||||||
{files.map((file) => (
|
{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))}
|
icon={file.isDirectory ? "/icon/folder.svg": extToIcon(extname(file.name))}
|
||||||
>{file.name}</ListItem>
|
>{file.name}</ListItem>
|
||||||
))}
|
))}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { Doc } from "../src/collect.ts";
|
import { Doc } from "../src/collect.ts";
|
||||||
import { useEffect, useState } from "preact/hooks";
|
import { useEffect, useState } from "preact/hooks";
|
||||||
import { Index } from "../src/client_search.ts";
|
import { Index } from "../src/client_search.ts";
|
||||||
|
import { encodePath } from "../util/util.ts";
|
||||||
|
|
||||||
function SearchBar(props:{
|
function SearchBar(props:{
|
||||||
search?: string;
|
search?: string;
|
||||||
@ -35,7 +36,7 @@ export default function DocSearch(props: {
|
|||||||
<ul class="mt-4">
|
<ul class="mt-4">
|
||||||
{docs.map((doc) => (
|
{docs.map((doc) => (
|
||||||
<li class="mt-2">
|
<li class="mt-2">
|
||||||
<a href={`/dir/${doc.path}`}> {doc.path}</a>
|
<a href={`/dir/${encodePath(doc.path)}`}> {doc.path}</a>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import RenderView from "./ContentRenderer.tsx";
|
import RenderView from "./ContentRenderer.tsx";
|
||||||
import UpList from "./UpList.tsx";
|
import UpList from "./UpList.tsx";
|
||||||
import { extname } from "path/mod.ts";
|
import { extname } from "path/mod.ts";
|
||||||
|
import { encodePath } from "../util/util.ts";
|
||||||
|
|
||||||
export default function FileViewer(props: { path: string }) {
|
export default function FileViewer(props: { path: string }) {
|
||||||
const { path } = props;
|
const { path } = props;
|
||||||
const srcPath = `/fs/${path}`;
|
const srcPath = `/fs/${encodePath(path)}`;
|
||||||
return (
|
return (
|
||||||
<div class="p-4 mx-auto max-w-screen-md">
|
<div class="p-4 mx-auto max-w-screen-md">
|
||||||
<UpList path={path} />
|
<UpList path={path} />
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { Head, asset } from "$fresh/runtime.ts";
|
import { Head, asset } from "$fresh/runtime.ts";
|
||||||
import { join } from "path/posix.ts";
|
import { join } from "path/posix.ts";
|
||||||
import { ComponentChild } from "preact";
|
import { ComponentChild } from "preact";
|
||||||
|
import { encodePath } from "../util/util.ts";
|
||||||
|
|
||||||
|
|
||||||
function stairs(path: string){
|
function stairs(path: string){
|
||||||
@ -28,7 +29,7 @@ export default function UpList(props:{path: string}) {
|
|||||||
uplist.map(([cur, up], i) => (
|
uplist.map(([cur, up], i) => (
|
||||||
<>
|
<>
|
||||||
<span class="p-2">/</span>
|
<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")} />
|
<img src={asset("/icon/folder.svg")} />
|
||||||
<span class="ml-1">{up}</span>
|
<span class="ml-1">{up}</span>
|
||||||
</a>
|
</a>
|
||||||
|
@ -15,7 +15,7 @@ export default function Home() {
|
|||||||
<p class="my-6">
|
<p class="my-6">
|
||||||
This is a simple file server. It serves files from the <code>CWD</code>.
|
This is a simple file server. It serves files from the <code>CWD</code>.
|
||||||
</p>
|
</p>
|
||||||
<a href="/dir/">Go To CWD</a>
|
<a href="/dir/">Go To CWD</a> | <a href="/doc/">Doc</a>
|
||||||
<hr></hr>
|
<hr></hr>
|
||||||
<a href="/login">Login</a> | <a href="/api/logout">Logout</a>
|
<a href="/login">Login</a> | <a href="/api/logout">Logout</a>
|
||||||
</div>
|
</div>
|
||||||
|
@ -9,3 +9,7 @@ export function removePrefixFromPathname(pathname: string, prefix: string): stri
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function encodePath(path: string): string {
|
||||||
|
return path.split("/").map(encodeURIComponent).join("/");
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user