This commit is contained in:
monoid 2023-01-14 03:03:58 +09:00
parent e2ee2c6375
commit 21111549b6
16 changed files with 124 additions and 110 deletions

View File

@ -12,12 +12,17 @@ export function MarkdownRenderer(props: { text: string | undefined }) {
meta = text.slice(4, index); meta = text.slice(4, index);
c = text.slice(index + 4, text.length); c = text.slice(index + 4, text.length);
} }
return (<> return (
{meta ? <div> <>
{meta
? (
<div>
<h2>Meta</h2> <h2>Meta</h2>
<pre>{meta}</pre> <pre>{meta}</pre>
<hr class="mt-2 mb-2"></hr> <hr class="mt-2 mb-2"></hr>
</div> : <div></div>} </div>
)
: <div></div>}
<div <div
class="markdown-body" class="markdown-body"
dangerouslySetInnerHTML={{ __html: marked.parse(c) }} dangerouslySetInnerHTML={{ __html: marked.parse(c) }}

View File

@ -50,7 +50,7 @@ function FetchAndRender(props: { src: string; type: string }) {
} }
} }
export function RenderView(props: { src: string, mdbase?: string }) { export function RenderView(props: { src: string; mdbase?: string }) {
const src = props.src; const src = props.src;
const type = extToType(extname(src)); const type = extToType(extname(src));
switch (type) { switch (type) {

View File

@ -61,7 +61,9 @@ export function DirList(props: DirListProps) {
{files.map((file) => ( {files.map((file) => (
<ListItem <ListItem
key={file.name} key={file.name}
href={`/dir/${encodePath(join(data.path, file.name))}${(file.isDirectory ? "/" : "")}?pretty`} href={`/dir/${
encodePath(join(data.path, file.name))
}${(file.isDirectory ? "/" : "")}?pretty`}
icon={file.isDirectory icon={file.isDirectory
? "/icon/folder.svg" ? "/icon/folder.svg"
: extToIcon(extname(file.name))} : extToIcon(extname(file.name))}

View File

@ -1,11 +1,9 @@
export default function LoginForm({ export default function LoginForm({
redirect = "/", redirect = "/",
failed = false, failed = false,
}: { redirect?: string }: { redirect?: string; failed?: boolean }) {
failed?: boolean } return (
) { <div class="p-4 absolute top-[50%] left-[50%] translate-x-[-50%] translate-y-[-50%]
return <div class="p-4 absolute top-[50%] left-[50%] translate-x-[-50%] translate-y-[-50%]
flex flex-col items-center border-gray-500 border-2 rounded-md flex flex-col items-center border-gray-500 border-2 rounded-md
sm:max-w-screen-sm max-w-screen-md"> sm:max-w-screen-sm max-w-screen-md">
<img <img
@ -49,4 +47,5 @@ export default function LoginForm({
</button> </button>
</form> </form>
</div> </div>
);
} }

View File

@ -5,7 +5,7 @@ import { encodePath } from "../util/util.ts";
function stairs(path: string) { function stairs(path: string) {
if (path === ".") return []; if (path === ".") return [];
const uplist = path.split("/").filter(x=> x.length > 0); const uplist = path.split("/").filter((x) => x.length > 0);
let current = "."; let current = ".";
const stairs = []; const stairs = [];
for (const up of uplist) { for (const up of uplist) {

View File

@ -4,11 +4,7 @@
/// <reference lib="dom.asynciterable" /> /// <reference lib="dom.asynciterable" />
/// <reference lib="deno.ns" /> /// <reference lib="deno.ns" />
import { import { Manifest, ServerContext, StartOptions } from "$fresh/server.ts";
Manifest,
ServerContext,
StartOptions,
} from "$fresh/server.ts";
import manifest from "./fresh.gen.ts"; import manifest from "./fresh.gen.ts";
import twindPlugin from "$fresh/plugins/twind.ts"; import twindPlugin from "$fresh/plugins/twind.ts";
@ -25,7 +21,6 @@ import { prepareDocs } from "./src/store/doc.ts";
import { connectDB } from "./src/user/db.ts"; import { connectDB } from "./src/user/db.ts";
import * as users from "./src/user/user.ts"; import * as users from "./src/user/user.ts";
async function startServer(manifest: Manifest, options: StartOptions = {}) { async function startServer(manifest: Manifest, options: StartOptions = {}) {
const ctx = await ServerContext.fromManifest(manifest, options); const ctx = await ServerContext.fromManifest(manifest, options);

View File

@ -1,4 +1,8 @@
import { HandlerContext, MiddlewareHandlerContext, Status } from "$fresh/server.ts"; import {
HandlerContext,
MiddlewareHandlerContext,
Status,
} from "$fresh/server.ts";
import { getCookies } from "http/cookie.ts"; import { getCookies } from "http/cookie.ts";
import { verify } from "djwt"; import { verify } from "djwt";
import { prepareSecretKey } from "../util/secret.ts"; import { prepareSecretKey } from "../util/secret.ts";
@ -17,4 +21,4 @@ export const handler = async (
ctx.state["login"] = null; ctx.state["login"] = null;
} }
return await ctx.next(); return await ctx.next();
} };

View File

@ -28,9 +28,13 @@ export type DirOrFileProps = DirProps | FileProps;
type RenderOption = { type RenderOption = {
fileInfo?: Deno.FileInfo; fileInfo?: Deno.FileInfo;
} };
async function renderFile(req: Request, path: string, { fileInfo }: RenderOption = {}) { async function renderFile(
req: Request,
path: string,
{ fileInfo }: RenderOption = {},
) {
try { try {
if (!fileInfo) { if (!fileInfo) {
fileInfo = await Deno.stat(path); fileInfo = await Deno.stat(path);
@ -82,7 +86,12 @@ async function renderFile(req: Request, path: string, { fileInfo }: RenderOption
} }
} }
async function renderPage(_req: Request, path: string, ctx: HandlerContext, { fileInfo }: RenderOption = {}) { async function renderPage(
_req: Request,
path: string,
ctx: HandlerContext,
{ fileInfo }: RenderOption = {},
) {
try { try {
if (!fileInfo) { if (!fileInfo) {
fileInfo = await Deno.stat(path); fileInfo = await Deno.stat(path);

View File

@ -5,7 +5,6 @@ export default function Home() {
<> <>
<Head> <Head>
<title>Simple file server</title> <title>Simple file server</title>
</Head> </Head>
<div class="p-4 mx-auto max-w-screen-md"> <div class="p-4 mx-auto max-w-screen-md">
<img <img

View File

@ -58,7 +58,9 @@ async function POST(req: Request, _ctx: HandlerContext): Promise<Response> {
<h1> Login Failed </h1> <h1> Login Failed </h1>
<p> <a href="/"> Back to Home </a> </p> <p> <a href="/"> Back to Home </a> </p>
<script> <script>
document.location.href = "/login?failed=true&redirect=${url.searchParams.get("redirect")}"; document.location.href = "/login?failed=true&redirect=${
url.searchParams.get("redirect")
}";
</script> </script>
</body> </body>
</html>`, </html>`,

View File

@ -12,9 +12,9 @@ export const handler = async (
status: Status.Found, status: Status.Found,
headers: { headers: {
Location: `/login?redirect=${encodeURIComponent(req.url)}`, Location: `/login?redirect=${encodeURIComponent(req.url)}`,
} },
}); });
} }
} }
return await ctx.next(); return await ctx.next();
} };

View File

@ -11,8 +11,7 @@ tags: ["한글", "테스트"]
2. asdf 2. asdf
3. sdf 3. sdf
- a
* a - b
* b - c
* c - d
* d