redirecter for ao3 that adds opengraph metadata

try and get other sites to work

Changed files
+22 -3
src
app
api
series
[seriesId]
works
[workId]
chapters
[chapterId]
lib
+4 -1
src/app/api/series/[seriesId]/route.js
···
export async function GET(req, ctx) {
const { seriesId } = await ctx.params
const { archive } = await req.nextUrl.searchParams
+
const domain = await req.nextUrl.hostname
+
const subdomain = domain.split(".").length > 1 ? domain.split(".")[0] : null
+
if (subdomain) setArchiveBaseUrl('https://'+subdomain)
if (archive) setArchiveBaseUrl(archive)
const series = await getSeries({seriesId: seriesId})
-
if (archive) resetArchiveBaseUrl()
+
if (archive || subdomain) resetArchiveBaseUrl()
return Response.json(series)
}
+5 -1
src/app/api/works/[workId]/chapters/[chapterId]/route.js
···
import { getWork } from "@fujocoded/ao3.js"
import { setArchiveBaseUrl, resetArchiveBaseUrl } from "@fujocoded/ao3.js/urls"
+
import siteMap from "@/lib/siteMap.js"
export const dynamic = 'force-static'
export async function GET(req, ctx) {
const { workId, chapterId } = await ctx.params
const params = await req.nextUrl.searchParams
+
const domain = await req.nextUrl.hostname
+
const subdomain = domain.split(".").length > 1 ? domain.split(".")[0] : null
const archive = params.get('archive')
+
if (subdomain) setArchiveBaseUrl('https://'+siteMap[subdomain])
if (archive) setArchiveBaseUrl(archive)
const work = await getWork({workId: workId, chapterId: chapterId})
-
if (archive) resetArchiveBaseUrl()
+
if (archive || subdomain) resetArchiveBaseUrl()
return Response.json(work)
}
+4 -1
src/app/api/works/[workId]/route.js
···
export async function GET(req, ctx) {
const { workId } = await ctx.params
const params = await req.nextUrl.searchParams
+
const domain = await req.nextUrl.hostname
+
const subdomain = domain.split(".").length > 1 ? domain.split(".")[0] : null
const archive = params.get('archive')
+
if (subdomain) setArchiveBaseUrl('https://'+siteMap[subdomain])
if (archive) setArchiveBaseUrl(archive)
const work = await getWork({workId: workId})
-
if (archive) resetArchiveBaseUrl()
+
if (archive || subdomain) resetArchiveBaseUrl()
return Response.json(work)
}
+9
src/lib/siteMap.js
···
+
const siteMap = {
+
superlove: 'superlove.sayitditto.net',
+
sunset: 'sunset.femslash.club',
+
squidgeworld: 'squidgeworld.org',
+
cfaarchive: 'cfaarchive.org',
+
adastra: 'adastrafanfic.com'
+
}
+
+
export default siteMap