redirecter for ao3 that adds opengraph metadata

fix server issues lol

Changed files
+61 -72
+61 -72
main.jsx
···
-
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"
-
import {
-
createIPX,
-
ipxFSStorage,
-
createIPXNodeServer
-
} from "ipx"
-
-
const ipx = createIPX({
-
storage: ipxFSStorage({ dir: "./imagecache" })
-
})
-
-
const app = new Hono()
+
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";
-
app.use("/", createIPXNodeServer(ipx))
+
const app = new Hono();
app.get("/", (c) => {
-
return c.html(<Home />)
-
})
+
return c.html(<Home />);
+
});
app.get("/works/:workId", async (c) => {
-
const workId = c.req.param("workId")
+
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})`
-
return a.username
-
})
+
if (a.anonymous) return "Anonymous";
+
if (a.pseud !== a.username) return `${a.pseud} (${a.username})`;
+
return a.username;
+
});
const authors = authorsFormatted.length > 1
? authorsFormatted.slice(0, -1).join(", ") + " & " +
authorsFormatted.slice(-1)
-
: authorsFormatted[0]
-
const title = `${work.title} by ${authors} - ${work.fandoms.join(", ")}`
+
: authorsFormatted[0];
+
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 | " : ""
-
} ${work.summary}`
+
} ${work.summary}`;
return c.html(
<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 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})`
-
return a.username
-
})
+
if (a.anonymous) return "Anonymous";
+
if (a.pseud !== a.username) return `${a.pseud} (${a.username})`;
+
return a.username;
+
});
const authors = authorsFormatted.length > 1
? authorsFormatted.slice(0, -1).join(", ") + " & " +
authorsFormatted.slice(-1)
-
: authorsFormatted[0]
+
: authorsFormatted[0];
const title =
`${work.title} by ${authors}, Chapter ${work.chapterInfo.index}${
work.chapterInfo.name ? `: ${work.chapterInfo.name}` : ""
-
} - ${work.fandoms.join(", ")}`
+
} - ${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
-
}`
+
}`;
return c.html(
<PageSkeleton
title={title}
description={desc}
addr={`works/${workId}/chapters/${chapterId}`}
/>,
-
)
-
})
+
);
+
});
app.get("/series/:seriesId", async (c) => {
-
const seriesId = c.req.param("seriesId")
-
const series = await getSeries({ seriesId: seriesId })
+
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})`
-
return a.username
-
})
+
if (a.anonymous) return "Anonymous";
+
if (a.pseud !== a.username) return `${a.pseud} (${a.username})`;
+
return a.username;
+
});
const authors = authorsFormatted.length > 1
? authorsFormatted.slice(0, -1).join(", ") + " & " +
authorsFormatted.slice(-1)
-
: authorsFormatted[0]
-
const title = `${series.name} by ${authors}`
+
: authorsFormatted[0];
+
const title = `${series.name} by ${authors}`;
const desc = ` Updated ${
series.updatedAt ? series.updatedAt : series.publishedAt
} | Works: ${series.worksCount} | ${
series.complete ? "Complete | " : ""
-
} ${series.notes}`
+
} ${series.notes}`;
return c.html(
<PageSkeleton
title={title}
description={desc}
addr={`series/${seriesId}`}
/>,
-
)
-
})
+
);
+
});
app.get("/users/:username", async (c) => {
-
const username = c.req.param("username")
-
const user = await getUser({ username: username })
+
const username = c.req.param("username");
+
const user = await getUser({ username: username });
return c.html(
<PageSkeleton
title={`${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 })
+
const username = c.req.param("username");
+
const pseud = c.req.param("pseud");
+
const user = await getUser({ username: username });
return c.html(
<PageSkeleton
title={`${pseud} (${username})`}
description={user.header}
addr={`users/${username}`}
/>,
-
)
-
})
+
);
+
});
app.get("/preview/works/:workId", async (c) => {
-
const workId = c.req.param("workId")
+
const workId = c.req.param("workId");
const work = await getWork({
workId: workId,
-
})
-
const addr = `works/${workId}`
-
return Image({ data: work, addr: addr })
-
})
+
});
+
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 workId = c.req.param("workId");
+
const chapterId = c.req.param("chapterId");
const work = await getWork({
workId: workId,
chapterId: chapterId,
-
})
-
const addr = `works/${workId}/chapters/${chapterId}`
+
});
+
const addr = `works/${workId}/chapters/${chapterId}`;
return Image({ data: work, addr: addr })
})
-
export default app
+
export default app;