···
1
-
import { getSeries, getUser, getWork } from "@fujocoded/ao3.js"
2
-
import { Hono } from "hono"
3
-
import PageSkeleton from "./pages/PageSkeleton.jsx"
4
-
import Home from "./pages/Home.jsx"
5
-
import Image from "./pages/Image.jsx"
12
-
const ipx = createIPX({
13
-
storage: ipxFSStorage({ dir: "./imagecache" })
16
-
const app = new Hono()
1
+
import { getSeries, getUser, getWork } from "@fujocoded/ao3.js";
2
+
import { Hono } from "hono";
3
+
import PageSkeleton from "./pages/PageSkeleton.jsx";
4
+
import Home from "./pages/Home.jsx";
5
+
import Image from "./pages/Image.jsx";
18
-
app.use("/", createIPXNodeServer(ipx))
7
+
const app = new Hono();
21
-
return c.html(<Home />)
10
+
return c.html(<Home />);
app.get("/works/:workId", async (c) => {
25
-
const workId = c.req.param("workId")
14
+
const workId = c.req.param("workId");
const work = await getWork({
workId: c.req.param("workId"),
chapterId: c.req.param("chapterId"),
const authorsFormatted = work.authors.map((a) => {
31
-
if (a.anonymous) return "Anonymous"
32
-
if (a.pseud !== a.username) return `${a.pseud} (${a.username})`
20
+
if (a.anonymous) return "Anonymous";
21
+
if (a.pseud !== a.username) return `${a.pseud} (${a.username})`;
const authors = authorsFormatted.length > 1
? authorsFormatted.slice(0, -1).join(", ") + " & " +
authorsFormatted.slice(-1)
38
-
: authorsFormatted[0]
39
-
const title = `${work.title} by ${authors} - ${work.fandoms.join(", ")}`
27
+
: authorsFormatted[0];
28
+
const title = `${work.title} by ${authors} - ${work.fandoms.join(", ")}`;
const desc = `Rating: ${work.rating} | ${work.category} | Updated ${
work.updatedAt ? work.updatedAt : work.publishedAt
} | Words: ${work.words} | ${
work.complete ? "Complete | " : ""
<PageSkeleton title={title} description={desc} addr={`works/${workId}`} />,
app.get("/works/:workId/chapters/:chapterId", async (c) => {
51
-
const workId = c.req.param("workId")
52
-
const chapterId = c.req.param("chapterId")
40
+
const workId = c.req.param("workId");
41
+
const chapterId = c.req.param("chapterId");
const work = await getWork({
workId: c.req.param("workId"),
chapterId: c.req.param("chapterId"),
const authorsFormatted = work.authors.map((a) => {
58
-
if (a.anonymous) return "Anonymous"
59
-
if (a.pseud !== a.username) return `${a.pseud} (${a.username})`
47
+
if (a.anonymous) return "Anonymous";
48
+
if (a.pseud !== a.username) return `${a.pseud} (${a.username})`;
const authors = authorsFormatted.length > 1
? authorsFormatted.slice(0, -1).join(", ") + " & " +
authorsFormatted.slice(-1)
65
-
: authorsFormatted[0]
54
+
: authorsFormatted[0];
`${work.title} by ${authors}, Chapter ${work.chapterInfo.index}${
work.chapterInfo.name ? `: ${work.chapterInfo.name}` : ""
69
-
} - ${work.fandoms.join(", ")}`
58
+
} - ${work.fandoms.join(", ")}`;
const desc = `Rating: ${work.rating} | ${work.category} | Updated ${
work.updatedAt ? work.updatedAt : work.publishedAt
} | Words: ${work.words} | ${work.complete ? "Complete | " : ""} ${
work.chapterInfo.summary ? work.chapterInfo.summary : work.summary
addr={`works/${workId}/chapters/${chapterId}`}
app.get("/series/:seriesId", async (c) => {
85
-
const seriesId = c.req.param("seriesId")
86
-
const series = await getSeries({ seriesId: seriesId })
74
+
const seriesId = c.req.param("seriesId");
75
+
const series = await getSeries({ seriesId: seriesId });
const authorsFormatted = series.authors.map((a) => {
88
-
if (a.anonymous) return "Anonymous"
89
-
if (a.pseud !== a.username) return `${a.pseud} (${a.username})`
77
+
if (a.anonymous) return "Anonymous";
78
+
if (a.pseud !== a.username) return `${a.pseud} (${a.username})`;
const authors = authorsFormatted.length > 1
? authorsFormatted.slice(0, -1).join(", ") + " & " +
authorsFormatted.slice(-1)
95
-
: authorsFormatted[0]
96
-
const title = `${series.name} by ${authors}`
84
+
: authorsFormatted[0];
85
+
const title = `${series.name} by ${authors}`;
const desc = ` Updated ${
series.updatedAt ? series.updatedAt : series.publishedAt
} | Works: ${series.worksCount} | ${
series.complete ? "Complete | " : ""
addr={`series/${seriesId}`}
app.get("/users/:username", async (c) => {
112
-
const username = c.req.param("username")
113
-
const user = await getUser({ username: username })
101
+
const username = c.req.param("username");
102
+
const user = await getUser({ username: username });
description={user.header}
addr={`users/${username}`}
app.get("/users/:username/pseuds/:pseud", async (c) => {
124
-
const username = c.req.param("username")
125
-
const pseud = c.req.param("pseud")
126
-
const user = await getUser({ username: username })
113
+
const username = c.req.param("username");
114
+
const pseud = c.req.param("pseud");
115
+
const user = await getUser({ username: username });
title={`${pseud} (${username})`}
description={user.header}
addr={`users/${username}`}
app.get("/preview/works/:workId", async (c) => {
137
-
const workId = c.req.param("workId")
126
+
const workId = c.req.param("workId");
const work = await getWork({
141
-
const addr = `works/${workId}`
142
-
return Image({ data: work, addr: addr })
130
+
const addr = `works/${workId}`;
131
+
return Image({ data: work, addr: addr });
app.get("/preview/works/:workId/chapters/:chapterId", async (c) => {
146
-
const workId = c.req.param("workId")
147
-
const chapterId = c.req.param("chapterId")
135
+
const workId = c.req.param("workId");
136
+
const chapterId = c.req.param("chapterId");
const work = await getWork({
152
-
const addr = `works/${workId}/chapters/${chapterId}`
141
+
const addr = `works/${workId}/chapters/${chapterId}`;
return Image({ data: work, addr: addr })
145
+
export default app;