redirecter for ao3 that adds opengraph metadata

add back preview folders bc i need those for the generator

Changed files
+123 -44
src
app
generator
series
[seriesId]
works
[workId]
chapters
[chapterId]
preview
+1 -1
src/app/generator/page.js
···
const fn = async () => {
if (!addr) return;
const params = new URLSearchParams(props)
-
const image = await fetch(`/${addr}/opengraph-image?${params.toString()}`)
+
const image = await fetch(`/${addr}/preview?${params.toString()}`)
if (image.status !== 200) return;
const imageBlob = await image.blob()
const reader = new FileReader()
+22 -20
src/app/series/[seriesId]/opengraph-image.jsx
···
export const contentType = 'image/webp'
-
export default async function Image({params}) {
+
const defaults = new URLSearchParams({
+
theme: 'ao3',
+
baseFont: 'bricolagegrotesque',
+
titleFont: 'stacksansnotch',
+
category: true,
+
rating: true,
+
warnings: false,
+
charTags: false,
+
relTags: false,
+
freeTags: false,
+
summary: true,
+
wordcount: true,
+
chapters: true,
+
postedAt: true,
+
updatedAt: false,
+
summaryType: 'basic',
+
customSummary: ''
+
})
+
+
export default async function Image({params, searchParams}) {
const { seriesId } = await params
-
const props = new URLSearchParams({
-
theme: 'ao3',
-
baseFont: 'bricolagegrotesque',
-
titleFont: 'stacksansnotch',
-
category: true,
-
rating: true,
-
warnings: false,
-
charTags: false,
-
relTags: false,
-
freeTags: false,
-
summary: true,
-
wordcount: true,
-
chapters: true,
-
postedAt: true,
-
updatedAt: false,
-
summaryType: 'basic',
-
customSummary: ''
-
})
const addr = `series/${seriesId}`
const data = await getSeries({seriesId: seriesId})
-
const imageParams = await sanitizeData({type: 'series', data: data, props: props})
+
const imageParams = await sanitizeData({type: 'series', data: data, props: defaults})
const theme = imageParams.theme
+
console.log(theme)
const baseFont = baseFonts[imageParams.baseFont].displayName
const titleFont = titleFonts[imageParams.titleFont].displayName
const opts = imageParams.opts
+25
src/app/series/[seriesId]/preview/route.js
···
+
import { getSeries } from "@fujocoded/ao3.js"
+
import sanitizeData from "@/lib/sanitizeData.js"
+
import OGImage from "@/lib/ogimage.js"
+
import baseFonts from "@/lib/baseFonts.js"
+
import titleFonts from "@/lib/titleFonts.js"
+
+
export const size = {
+
width: 1600,
+
height: 900,
+
}
+
+
export const contentType = 'image/webp'
+
+
export async function GET(req, ctx) {
+
const { seriesId } = await ctx.params
+
const props = await req.nextUrl.searchParams
+
const addr = `series/${seriesId}`
+
const data = await getSeries({seriesId: seriesId})
+
const imageParams = await sanitizeData({type: 'series', data: data, props: props})
+
const theme = imageParams.theme
+
const baseFont = baseFonts[imageParams.baseFont].displayName
+
const titleFont = titleFonts[imageParams.titleFont].displayName
+
const opts = imageParams.opts
+
return OGImage({theme: theme, baseFont: baseFont, titleFont: titleFont, image: imageParams, addr: addr, opts: opts})
+
}
+5 -4
src/app/works/[workId]/chapters/[chapterId]/opengraph-image.jsx
···
export const contentType = 'image/webp'
-
export default async function Image({params}) {
-
const { workId, chapterId } = await params
-
const props = new URLSearchParams({
+
const defaults = new URLSearchParams({
theme: 'ao3',
baseFont: 'bricolagegrotesque',
titleFont: 'stacksansnotch',
···
summaryType: 'basic',
customSummary: ''
})
+
+
export default async function Image({params, searchParams}) {
+
const { workId, chapterId } = await params
const addr = `works/${workId}/chapters/${chapterId}`
const data = await getWork({workId: workId, chapterId: chapterId})
-
const imageParams = await sanitizeData({type: 'work', data: data, props: props})
+
const imageParams = await sanitizeData({type: 'work', data: data, props: defaults})
const theme = imageParams.theme
const baseFont = baseFonts[imageParams.baseFont].displayName
const titleFont = titleFonts[imageParams.titleFont].displayName
+25
src/app/works/[workId]/chapters/[chapterId]/preview/route.js
···
+
import { getWork } from "@fujocoded/ao3.js"
+
import sanitizeData from "@/lib/sanitizeData.js"
+
import OGImage from "@/lib/ogimage.js"
+
import baseFonts from "@/lib/baseFonts.js"
+
import titleFonts from "@/lib/titleFonts.js"
+
+
export const size = {
+
width: 1600,
+
height: 900,
+
}
+
+
export const contentType = 'image/webp'
+
+
export async function GET(req, ctx) {
+
const { workId, chapterId } = await ctx.params
+
const props = await req.nextUrl.searchParams
+
const addr = `works/${workId}/chapters/${chapterId}`
+
const data = await getWork({workId: workId, chapterId: chapterId})
+
const imageParams = await sanitizeData({type: 'work', data: data, props: props})
+
const theme = imageParams.theme
+
const baseFont = baseFonts[imageParams.baseFont].displayName
+
const titleFont = titleFonts[imageParams.titleFont].displayName
+
const opts = imageParams.opts
+
return OGImage({theme: theme, baseFont: baseFont, titleFont: titleFont, image: imageParams, addr: addr, opts: opts})
+
}
+20 -19
src/app/works/[workId]/opengraph-image.jsx
···
export const contentType = 'image/webp'
+
const defaults = new URLSearchParams({
+
theme: 'ao3',
+
baseFont: 'bricolagegrotesque',
+
titleFont: 'stacksansnotch',
+
category: true,
+
rating: true,
+
warnings: false,
+
charTags: false,
+
relTags: false,
+
freeTags: false,
+
summary: true,
+
wordcount: true,
+
chapters: true,
+
postedAt: true,
+
updatedAt: false,
+
summaryType: 'basic',
+
customSummary: ''
+
})
+
export default async function Image({params}) {
const { workId } = await params
-
const props = new URLSearchParams({
-
theme: 'ao3',
-
baseFont: 'bricolagegrotesque',
-
titleFont: 'stacksansnotch',
-
category: true,
-
rating: true,
-
warnings: false,
-
charTags: false,
-
relTags: false,
-
freeTags: false,
-
summary: true,
-
wordcount: true,
-
chapters: true,
-
postedAt: true,
-
updatedAt: false,
-
summaryType: 'basic',
-
customSummary: ''
-
})
const addr = `works/${workId}`
const data = await getWork({workId: workId})
-
const imageParams = await sanitizeData({type: 'work', data: data, props: props})
+
const imageParams = await sanitizeData({type: 'work', data: data, props: defaults})
const theme = imageParams.theme
const baseFont = baseFonts[imageParams.baseFont].displayName
const titleFont = titleFonts[imageParams.titleFont].displayName
+25
src/app/works/[workId]/preview/route.js
···
+
import { getWork } from "@fujocoded/ao3.js"
+
import sanitizeData from "@/lib/sanitizeData.js"
+
import OGImage from "@/lib/ogimage.js"
+
import baseFonts from "@/lib/baseFonts.js"
+
import titleFonts from "@/lib/titleFonts.js"
+
+
export const size = {
+
width: 1600,
+
height: 900,
+
}
+
+
export const contentType = 'image/webp'
+
+
export async function GET(req, ctx) {
+
const { workId } = await ctx.params
+
const props = await req.nextUrl.searchParams
+
const addr = `works/${workId}`
+
const data = await getWork({workId: workId})
+
const imageParams = await sanitizeData({type: 'work', data: data, props: props})
+
const theme = imageParams.theme
+
const baseFont = baseFonts[imageParams.baseFont].displayName
+
const titleFont = titleFonts[imageParams.titleFont].displayName
+
const opts = imageParams.opts
+
return OGImage({theme: theme, baseFont: baseFont, titleFont: titleFont, image: imageParams, addr: addr, opts: opts})
+
}