diff --git a/components/MarkdownRenderer.tsx b/components/MarkdownRenderer.tsx index 6742fb0..3e94c7d 100644 --- a/components/MarkdownRenderer.tsx +++ b/components/MarkdownRenderer.tsx @@ -12,18 +12,23 @@ export function MarkdownRenderer(props: { text: string | undefined }) { meta = text.slice(4, index); c = text.slice(index + 4, text.length); } - return (<> - {meta ?
-

Meta

-
{meta}
-
-
:
} -
+ {meta + ? ( +
+

Meta

+
{meta}
+
+
+ ) + :
} +
-
- +
+ ); } diff --git a/dev.ts b/dev.ts index 13f60b9..3f93b38 100644 --- a/dev.ts +++ b/dev.ts @@ -8,11 +8,11 @@ await devUserAdd(); await dev(import.meta.url, "./main.ts"); async function devUserAdd() { - if(Deno.env.get("DB_PATH") === ":memory:") { - const db = await connectDB(); - const username = "admin"; - const password = "admin"; - const new_user = await users.createUser(username, password); - await users.addUser(db, new_user); - } -} \ No newline at end of file + if (Deno.env.get("DB_PATH") === ":memory:") { + const db = await connectDB(); + const username = "admin"; + const password = "admin"; + const new_user = await users.createUser(username, password); + await users.addUser(db, new_user); + } +} diff --git a/import_map.json b/import_map.json index 2cc5da1..9c65394 100644 --- a/import_map.json +++ b/import_map.json @@ -15,4 +15,4 @@ "sqlite": "https://deno.land/x/sqlite@v3.7.0/mod.ts", "djwt": "https://deno.land/x/djwt@v2.8/mod.ts" } -} \ No newline at end of file +} diff --git a/islands/ContentRenderer.tsx b/islands/ContentRenderer.tsx index e2a697b..393ea18 100644 --- a/islands/ContentRenderer.tsx +++ b/islands/ContentRenderer.tsx @@ -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 type = extToType(extname(src)); switch (type) { diff --git a/islands/DirList.tsx b/islands/DirList.tsx index cfd8100..f6d8007 100644 --- a/islands/DirList.tsx +++ b/islands/DirList.tsx @@ -61,7 +61,9 @@ export function DirList(props: DirListProps) { {files.map((file) => ( - the fresh logo: a sliced lemon dripping with juice -

Login

- {failed ?

Login failed

: null} -
-
-
- - -
-
- - -
-
- -
+ > + Login + + -} \ No newline at end of file + ); +} diff --git a/islands/UpList.tsx b/islands/UpList.tsx index 5a3ce55..8e6fc02 100644 --- a/islands/UpList.tsx +++ b/islands/UpList.tsx @@ -5,7 +5,7 @@ import { encodePath } from "../util/util.ts"; function stairs(path: string) { if (path === ".") return []; - const uplist = path.split("/").filter(x=> x.length > 0); + const uplist = path.split("/").filter((x) => x.length > 0); let current = "."; const stairs = []; for (const up of uplist) { diff --git a/main.ts b/main.ts index fdaf5b5..af01a48 100644 --- a/main.ts +++ b/main.ts @@ -4,11 +4,7 @@ /// /// -import { - Manifest, - ServerContext, - StartOptions, -} from "$fresh/server.ts"; +import { Manifest, ServerContext, StartOptions } from "$fresh/server.ts"; import manifest from "./fresh.gen.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 * as users from "./src/user/user.ts"; - async function startServer(manifest: Manifest, options: StartOptions = {}) { const ctx = await ServerContext.fromManifest(manifest, options); diff --git a/routes/_middleware.ts b/routes/_middleware.ts index a725531..bf73649 100644 --- a/routes/_middleware.ts +++ b/routes/_middleware.ts @@ -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 { verify } from "djwt"; import { prepareSecretKey } from "../util/secret.ts"; @@ -17,4 +21,4 @@ export const handler = async ( ctx.state["login"] = null; } return await ctx.next(); -} +}; diff --git a/routes/dir/[...path].tsx b/routes/dir/[...path].tsx index 99e797c..1115c41 100644 --- a/routes/dir/[...path].tsx +++ b/routes/dir/[...path].tsx @@ -28,9 +28,13 @@ export type DirOrFileProps = DirProps | FileProps; type RenderOption = { fileInfo?: Deno.FileInfo; -} +}; -async function renderFile(req: Request, path: string, { fileInfo }: RenderOption = {}) { +async function renderFile( + req: Request, + path: string, + { fileInfo }: RenderOption = {}, +) { try { if (!fileInfo) { 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 { if (!fileInfo) { fileInfo = await Deno.stat(path); @@ -233,4 +242,4 @@ export default function DirLists(props: PageProps) { ); -} \ No newline at end of file +} diff --git a/routes/dir/_middleware.ts b/routes/dir/_middleware.ts index ba18de3..1ed89fa 100644 --- a/routes/dir/_middleware.ts +++ b/routes/dir/_middleware.ts @@ -1 +1 @@ -export { handler } from "../../src/login_middleware.ts"; \ No newline at end of file +export { handler } from "../../src/login_middleware.ts"; diff --git a/routes/doc/_middleware.ts b/routes/doc/_middleware.ts index ba18de3..1ed89fa 100644 --- a/routes/doc/_middleware.ts +++ b/routes/doc/_middleware.ts @@ -1 +1 @@ -export { handler } from "../../src/login_middleware.ts"; \ No newline at end of file +export { handler } from "../../src/login_middleware.ts"; diff --git a/routes/index.tsx b/routes/index.tsx index 87dfa60..b3b5ff3 100644 --- a/routes/index.tsx +++ b/routes/index.tsx @@ -5,7 +5,6 @@ export default function Home() { <> Simple file server -
{ path: "/", secure: url.protocol === "https:", }); - + let redirect = "/"; if (url.searchParams.has("redirect")) { redirect = url.searchParams.get("redirect")!; @@ -58,7 +58,9 @@ async function POST(req: Request, _ctx: HandlerContext): Promise {

Login Failed

Back to Home

`, @@ -85,7 +87,7 @@ export default function Login(props: PageProps) { Simple file server - Login
- +
); diff --git a/src/login_middleware.ts b/src/login_middleware.ts index feb9b2b..0f839ff 100644 --- a/src/login_middleware.ts +++ b/src/login_middleware.ts @@ -1,20 +1,20 @@ import { MiddlewareHandlerContext, Status } from "$fresh/server.ts"; export const handler = async ( - req: Request, - ctx: MiddlewareHandlerContext>, - ) => { - const authRequired = Deno.env.get("AUTH_REQUIRED") === "true"; - if (authRequired) { - const login = ctx.state["login"]; - if (!login) { - return new Response(null, { - status: Status.Found, - headers: { - Location: `/login?redirect=${encodeURIComponent(req.url)}`, - } - }); - } + req: Request, + ctx: MiddlewareHandlerContext>, +) => { + const authRequired = Deno.env.get("AUTH_REQUIRED") === "true"; + if (authRequired) { + const login = ctx.state["login"]; + if (!login) { + return new Response(null, { + status: Status.Found, + headers: { + Location: `/login?redirect=${encodeURIComponent(req.url)}`, + }, + }); } - return await ctx.next(); -} \ No newline at end of file + } + return await ctx.next(); +}; diff --git a/test_data/f/SUMMARY.md b/test_data/f/SUMMARY.md index 09b0d83..7acbf84 100644 --- a/test_data/f/SUMMARY.md +++ b/test_data/f/SUMMARY.md @@ -11,8 +11,7 @@ tags: ["한글", "테스트"] 2. asdf 3. sdf - -* a -* b -* c -* d \ No newline at end of file +- a +- b +- c +- d