2023-01-05 18:18:07 +09:00
|
|
|
import { Head } from "$fresh/runtime.ts";
|
2023-01-06 18:24:27 +09:00
|
|
|
import { HandlerContext, Handlers, PageProps } from "$fresh/server.ts";
|
2023-01-05 18:18:07 +09:00
|
|
|
import DocSearch from "../../islands/DocSearch.tsx";
|
|
|
|
import { Doc } from "../../src/collect.ts";
|
|
|
|
import { docCollector } from "../../src/store/doc.ts";
|
|
|
|
|
|
|
|
async function GET(req: Request, ctx: HandlerContext): Promise<Response> {
|
2023-01-06 18:24:27 +09:00
|
|
|
const authRequired = Deno.env.get("AUTH_REQUIRED") === "true";
|
|
|
|
if (authRequired) {
|
|
|
|
const login = ctx.state["login"];
|
|
|
|
if (!login) {
|
|
|
|
return new Response(null, {
|
|
|
|
status: 302,
|
|
|
|
headers: {
|
|
|
|
"Location": "/login",
|
|
|
|
"content-type": "text/plain",
|
|
|
|
"Access-Control-Allow-Origin": "*",
|
|
|
|
"Access-Control-Allow-Methods": "GET,HEAD,PUT,PATCH,POST,DELETE",
|
|
|
|
"Access-Control-Allow-Headers":
|
|
|
|
"Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const docs = docCollector.getDocs();
|
|
|
|
return await ctx.render({ docs });
|
2023-01-05 18:18:07 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
export const handler: Handlers = {
|
2023-01-06 18:24:27 +09:00
|
|
|
GET,
|
|
|
|
};
|
2023-01-05 18:18:07 +09:00
|
|
|
|
2023-01-06 18:24:27 +09:00
|
|
|
export default function Docs(props: PageProps<{ docs: Doc[] }>) {
|
|
|
|
const { docs } = props.data;
|
2023-01-05 18:18:07 +09:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Head>
|
|
|
|
<title>Simple file server - Doc</title>
|
|
|
|
</Head>
|
|
|
|
<div class="p-4 mx-auto max-w-screen-md">
|
|
|
|
<DocSearch docs={docs}></DocSearch>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
2023-01-06 18:24:27 +09:00
|
|
|
}
|