···
-
import { getSeries, getUser, getWork } from "@fujocoded/ao3.js"
-
import { Hono } from "hono"
-
import PageSkeleton from "./pages/PageSkeleton.jsx"
-
import Home from "./pages/Home.jsx"
-
import Image from "./pages/Image.jsx"
-
const ipx = createIPX({
-
storage: ipxFSStorage({ dir: "./imagecache" })
-
app.use("/", createIPXNodeServer(ipx))
-
return c.html(<Home />)
app.get("/works/:workId", async (c) => {
-
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) => {
-
if (a.anonymous) return "Anonymous"
-
if (a.pseud !== a.username) return `${a.pseud} (${a.username})`
const authors = authorsFormatted.length > 1
? authorsFormatted.slice(0, -1).join(", ") + " & " +
authorsFormatted.slice(-1)
-
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) => {
-
const workId = c.req.param("workId")
-
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) => {
-
if (a.anonymous) return "Anonymous"
-
if (a.pseud !== a.username) return `${a.pseud} (${a.username})`
const authors = authorsFormatted.length > 1
? authorsFormatted.slice(0, -1).join(", ") + " & " +
authorsFormatted.slice(-1)
`${work.title} by ${authors}, Chapter ${work.chapterInfo.index}${
work.chapterInfo.name ? `: ${work.chapterInfo.name}` : ""
-
} - ${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) => {
-
const seriesId = c.req.param("seriesId")
-
const series = await getSeries({ seriesId: seriesId })
const authorsFormatted = series.authors.map((a) => {
-
if (a.anonymous) return "Anonymous"
-
if (a.pseud !== a.username) return `${a.pseud} (${a.username})`
const authors = authorsFormatted.length > 1
? authorsFormatted.slice(0, -1).join(", ") + " & " +
authorsFormatted.slice(-1)
-
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) => {
-
const username = c.req.param("username")
-
const user = await getUser({ username: username })
description={user.header}
addr={`users/${username}`}
app.get("/users/:username/pseuds/:pseud", async (c) => {
-
const username = c.req.param("username")
-
const pseud = c.req.param("pseud")
-
const user = await getUser({ username: username })
title={`${pseud} (${username})`}
description={user.header}
addr={`users/${username}`}
app.get("/preview/works/:workId", async (c) => {
-
const workId = c.req.param("workId")
const work = await getWork({
-
const addr = `works/${workId}`
-
return Image({ data: work, addr: addr })
app.get("/preview/works/:workId/chapters/:chapterId", async (c) => {
-
const workId = c.req.param("workId")
-
const chapterId = c.req.param("chapterId")
const work = await getWork({
-
const addr = `works/${workId}/chapters/${chapterId}`
return Image({ data: work, addr: addr })