refactor: api to app route (#502)
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import { NextResponse } from "next/server"
|
||||
|
||||
import { NextServerResponse, getQuery } from "~/lib/server-helper"
|
||||
import { checkDomainServer } from "~/models/site.model"
|
||||
|
||||
export async function GET(req: Request) {
|
||||
const { handle, domain } = getQuery(req)
|
||||
|
||||
if (!handle || !domain) {
|
||||
NextResponse.json({ error: "Missing characterId or domain" })
|
||||
return
|
||||
}
|
||||
const res = new NextServerResponse()
|
||||
|
||||
return res.status(200).json({
|
||||
data: await checkDomainServer(domain as string, handle as string),
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { NextServerResponse } from "~/lib/server-helper"
|
||||
|
||||
export async function GET() {
|
||||
const res = new NextServerResponse()
|
||||
return res.status(200).json({
|
||||
ok: true,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import { OUR_DOMAIN } from "~/lib/env"
|
||||
import { cacheGet } from "~/lib/redis.server"
|
||||
import { NextServerResponse, getQuery } from "~/lib/server-helper"
|
||||
import { checkDomainServer, fetchTenant } from "~/models/site.model"
|
||||
|
||||
export async function GET(req: Request) {
|
||||
let { host } = getQuery(req)
|
||||
|
||||
let realHost: string
|
||||
if (Array.isArray(host)) {
|
||||
realHost = host[0]
|
||||
} else {
|
||||
realHost = host || ""
|
||||
}
|
||||
let result = {}
|
||||
|
||||
const OUR_DOMAIN_SUFFIX = `.${OUR_DOMAIN}`
|
||||
if (realHost && realHost !== OUR_DOMAIN) {
|
||||
result = await cacheGet({
|
||||
key: ["host2handle", realHost],
|
||||
getValueFun: async () => {
|
||||
if (realHost.endsWith(OUR_DOMAIN_SUFFIX)) {
|
||||
const subdomain = realHost.replace(OUR_DOMAIN_SUFFIX, "")
|
||||
const res = await fetch(
|
||||
`https://indexer.crossbell.io/v1/handles/${subdomain}/character`,
|
||||
)
|
||||
const char = await res.json()
|
||||
const customDomain =
|
||||
char?.metadata?.content?.attributes?.find(
|
||||
(a: any) => a.trait_type === "xlog_custom_domain",
|
||||
)?.value || ""
|
||||
if (
|
||||
customDomain &&
|
||||
(await checkDomainServer(customDomain, subdomain))
|
||||
) {
|
||||
return {
|
||||
redirect: /^https?:\/\//.test(customDomain)
|
||||
? customDomain
|
||||
: `https://${customDomain}`,
|
||||
subdomain: subdomain,
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
subdomain: subdomain,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const tenant = await fetchTenant(realHost, 5)
|
||||
return {
|
||||
subdomain: tenant,
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
const res = new NextServerResponse()
|
||||
return res.status(200).json(result)
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { NextServerResponse, getQuery } from "~/lib/server-helper"
|
||||
|
||||
export async function GET(req: Request) {
|
||||
const { address } = getQuery(req)
|
||||
|
||||
const result = await (
|
||||
await fetch("https://mirror.xyz/api/graphql", {
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
Referer: `https://mirror.xyz/${address}/`,
|
||||
origin: "https://mirror.xyz",
|
||||
"user-agent":
|
||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36",
|
||||
},
|
||||
body: `{"operationName":"ProjectPage","variables":{"projectAddress":"${address}","limit":1000},"query":"query ProjectPage($projectAddress: String\u0021, $limit: Int, $cursor: Int) {\\n projectFeed(projectAddress: $projectAddress, limit: $limit, cursor: $cursor) {\\n _id\\n domain\\n ens\\n theme {\\n accent\\n colorMode\\n __typename\\n }\\n displayName\\n ens\\n address\\n ...projectPage\\n ...publicationLayoutProject\\n __typename\\n }\\n}\\n\\nfragment projectPage on ProjectType {\\n _id\\n address\\n avatarURL\\n description\\n displayName\\n domain\\n ens\\n theme {\\n accent\\n colorMode\\n __typename\\n }\\n headerImage {\\n id\\n url\\n __typename\\n }\\n posts {\\n ... on crowdfund {\\n _id\\n id\\n __typename\\n }\\n ... on entry {\\n _id\\n id\\n body\\n digest\\n title\\n publishedAtTimestamp\\n writingNFT {\\n _id\\n optimisticNumSold\\n proxyAddress\\n purchases {\\n numSold\\n __typename\\n }\\n __typename\\n }\\n featuredImage {\\n mimetype\\n url\\n __typename\\n }\\n publisher {\\n ...publisherDetails\\n __typename\\n }\\n settings {\\n ...entrySettingsDetails\\n __typename\\n }\\n __typename\\n }\\n ... on SubscriberEditionType {\\n _id\\n __typename\\n }\\n __typename\\n }\\n __typename\\n}\\n\\nfragment publisherDetails on PublisherType {\\n project {\\n ...projectDetails\\n __typename\\n }\\n member {\\n ...projectDetails\\n __typename\\n }\\n __typename\\n}\\n\\nfragment projectDetails on ProjectType {\\n _id\\n address\\n avatarURL\\n description\\n displayName\\n domain\\n ens\\n gaTrackingID\\n mailingListURL\\n headerImage {\\n ...mediaAsset\\n __typename\\n }\\n theme {\\n ...themeDetails\\n __typename\\n }\\n __typename\\n}\\n\\nfragment mediaAsset on MediaAssetType {\\n id\\n cid\\n mimetype\\n sizes {\\n ...mediaAssetSizes\\n __typename\\n }\\n url\\n __typename\\n}\\n\\nfragment mediaAssetSizes on MediaAssetSizesType {\\n og {\\n ...mediaAssetSize\\n __typename\\n }\\n lg {\\n ...mediaAssetSize\\n __typename\\n }\\n md {\\n ...mediaAssetSize\\n __typename\\n }\\n sm {\\n ...mediaAssetSize\\n __typename\\n }\\n __typename\\n}\\n\\nfragment mediaAssetSize on MediaAssetSizeType {\\n src\\n height\\n width\\n __typename\\n}\\n\\nfragment themeDetails on UserProfileThemeType {\\n accent\\n colorMode\\n __typename\\n}\\n\\nfragment entrySettingsDetails on EntrySettingsType {\\n description\\n metaImage {\\n ...mediaAsset\\n __typename\\n }\\n title\\n __typename\\n}\\n\\nfragment publicationLayoutProject on ProjectType {\\n _id\\n avatarURL\\n displayName\\n domain\\n address\\n ens\\n gaTrackingID\\n mailingListURL\\n description\\n __typename\\n}\\n"}`,
|
||||
method: "POST",
|
||||
})
|
||||
).json()
|
||||
|
||||
return new NextServerResponse().status(200).json(result)
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import { Asset } from "unidata.js"
|
||||
|
||||
import { IPFS_GATEWAY } from "~/lib/env"
|
||||
import { cacheGet, getRedis } from "~/lib/redis.server"
|
||||
import { NextServerResponse, getQuery } from "~/lib/server-helper"
|
||||
import { getNFTs } from "~/models/site.model"
|
||||
|
||||
export async function GET(req: Request): Promise<Response> {
|
||||
const query = getQuery(req)
|
||||
const res = new NextServerResponse()
|
||||
if (!query.address) {
|
||||
return res.status(400).end()
|
||||
}
|
||||
|
||||
const redis = await getRedis()
|
||||
const redisKey = `nfts/${query.address}`
|
||||
|
||||
let cache
|
||||
try {
|
||||
cache = await redis?.get(redisKey)
|
||||
} catch (error) {}
|
||||
if (cache) {
|
||||
return res.status(200).json(JSON.parse(cache))
|
||||
} else {
|
||||
const result = await getNFTs(query.address as string)
|
||||
await Promise.all(
|
||||
result.list.map(async (nft: Asset) => {
|
||||
if (!nft.items?.[0].mime_type && nft.items?.[0]?.address) {
|
||||
try {
|
||||
new URL(nft.items[0].address)
|
||||
} catch (error) {
|
||||
return nft
|
||||
}
|
||||
try {
|
||||
const mime_type = await cacheGet({
|
||||
key: `nft-mimetype/${nft.items[0].address}`,
|
||||
getValueFun: async () => {
|
||||
const head = await fetch(
|
||||
`${nft.items![0].address!.replace(
|
||||
IPFS_GATEWAY,
|
||||
"https://gateway.ipfs.io/ipfs/",
|
||||
)}`,
|
||||
{
|
||||
method: "HEAD",
|
||||
},
|
||||
)
|
||||
return head.headers.get("content-type")
|
||||
},
|
||||
})
|
||||
nft.items[0].mime_type = mime_type
|
||||
} catch (error) {
|
||||
console.warn(error)
|
||||
}
|
||||
}
|
||||
return nft
|
||||
}),
|
||||
)
|
||||
redis?.set(redisKey, JSON.stringify(result), "EX", 60 * 60 * 24)
|
||||
return res.status(200).json({
|
||||
list: [],
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { NextServerResponse, getQuery } from "~/lib/server-helper"
|
||||
import { PageVisibilityEnum } from "~/lib/types"
|
||||
import { getPagesBySite } from "~/models/page.model"
|
||||
|
||||
export async function GET(req: Request) {
|
||||
const query = getQuery(req)
|
||||
|
||||
const result = await getPagesBySite({
|
||||
characterId: +(query.characterId || 0) as number,
|
||||
type: query.type as "post" | "page",
|
||||
visibility: query.visibility as PageVisibilityEnum,
|
||||
limit: query.take ? parseInt(query.take as string) : undefined,
|
||||
cursor: query.cursor as string,
|
||||
useStat: true,
|
||||
...(query.tags && {
|
||||
tags: Array.isArray(query.tags)
|
||||
? (query.tags as string[])
|
||||
: [query.tags as string],
|
||||
}),
|
||||
})
|
||||
|
||||
const res = new NextServerResponse()
|
||||
return res.status(200).json(result)
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
import { NoteEntity } from "crossbell.js"
|
||||
import { redirect } from "next/navigation"
|
||||
|
||||
import { IS_VERCEL_PREVIEW } from "~/lib/constants"
|
||||
import { getDefaultSlug } from "~/lib/default-slug"
|
||||
import { getSiteLink } from "~/lib/helpers"
|
||||
import { NextServerResponse, getQuery } from "~/lib/server-helper"
|
||||
import { checkDomainServer } from "~/models/site.model"
|
||||
|
||||
async function getOriginalNote(
|
||||
characterId: string,
|
||||
noteId: string,
|
||||
): Promise<NoteEntity> {
|
||||
const note = await (
|
||||
await fetch(
|
||||
`https://indexer.crossbell.io/v1/characters/${characterId}/notes/${noteId}`,
|
||||
)
|
||||
).json()
|
||||
|
||||
if (note?.toNote) {
|
||||
if (note?.toNote.toNoteId) {
|
||||
return await getOriginalNote(
|
||||
note?.toNote.toCharacterId,
|
||||
note?.toNote.toNoteId,
|
||||
)
|
||||
} else {
|
||||
return note.toNote
|
||||
}
|
||||
} else {
|
||||
return note
|
||||
}
|
||||
}
|
||||
|
||||
export async function GET(req: Request): Promise<Response> {
|
||||
let { characterId, noteId } = getQuery(req)
|
||||
|
||||
const res = new NextServerResponse()
|
||||
if (!characterId || typeof characterId !== "string") {
|
||||
return res.status(400).json({ error: "Missing characterId" })
|
||||
}
|
||||
|
||||
let character
|
||||
let note
|
||||
|
||||
if (noteId && typeof noteId === "string") {
|
||||
note = await getOriginalNote(characterId, noteId)
|
||||
characterId = note.characterId + ""
|
||||
}
|
||||
|
||||
character = await (
|
||||
await fetch(`https://indexer.crossbell.io/v1/characters/${characterId}`)
|
||||
).json()
|
||||
|
||||
let domain = character?.metadata?.content?.attributes?.find(
|
||||
(a: any) => a.trait_type === "xlog_custom_domain",
|
||||
)?.value
|
||||
if (domain && !(await checkDomainServer(domain, character.handle))) {
|
||||
domain = undefined
|
||||
}
|
||||
let link = getSiteLink({
|
||||
domain,
|
||||
subdomain: character?.handle,
|
||||
})
|
||||
|
||||
if (note) {
|
||||
const slug =
|
||||
note?.metadata?.content?.attributes?.find(
|
||||
(a: any) => a.trait_type === "xlog_slug",
|
||||
)?.value ||
|
||||
getDefaultSlug(
|
||||
note?.metadata?.content?.title || "",
|
||||
`${characterId}-${noteId}`,
|
||||
)
|
||||
|
||||
link += `/${encodeURIComponent(slug)}`
|
||||
|
||||
if (note.noteId + "" !== noteId) {
|
||||
link += `#comments`
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_VERCEL_PREVIEW) {
|
||||
const path = new URL(link).pathname
|
||||
|
||||
redirect(`/_site/${character.handle}${path}`)
|
||||
} else {
|
||||
redirect(link)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
import { toGateway } from "~/lib/ipfs-parser"
|
||||
import prisma from "~/lib/prisma.server"
|
||||
import { cacheGet } from "~/lib/redis.server"
|
||||
import { NextServerResponse, getQuery } from "~/lib/server-helper"
|
||||
|
||||
const getOriginalScore = async (cid: string) => {
|
||||
try {
|
||||
let { content } = await (await fetch(toGateway(`ipfs://${cid}`))).json()
|
||||
|
||||
if (content?.length > 5000) {
|
||||
content = content.slice(0, 5000)
|
||||
}
|
||||
|
||||
if (content?.length > 200) {
|
||||
console.time(`fetching score ${cid}`)
|
||||
|
||||
const prompt = `According to rule 1 not too short content, rule 2 good originality and innovation, and rule 3 good fun or logic, give this article a score in the range of 0-100 and explain the reason:
|
||||
"${content}"
|
||||
Score:`
|
||||
const response = await (
|
||||
await fetch("https://api.openai.com/v1/chat/completions", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
model: "gpt-4",
|
||||
temperature: 0,
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
content: prompt,
|
||||
},
|
||||
],
|
||||
}),
|
||||
})
|
||||
).json()
|
||||
|
||||
console.timeEnd(`fetching score ${cid}`)
|
||||
|
||||
return {
|
||||
number: parseInt(response.choices?.[0]?.message?.content?.trim()),
|
||||
reason: response.choices?.[0]?.message?.content
|
||||
?.trim()
|
||||
.replace(/^\d+([,.\s]*)/, "")
|
||||
.trim()
|
||||
.replace(/^Reason:/, "")
|
||||
.trim(),
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
number: 0,
|
||||
reason: "Content too short",
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
console.timeEnd(`fetching score ${cid}`)
|
||||
}
|
||||
}
|
||||
|
||||
async function getScore(cid: string) {
|
||||
const score = await cacheGet({
|
||||
key: ["summary_score", cid],
|
||||
getValueFun: async () => {
|
||||
const meta = await prisma.metadata.findFirst({
|
||||
where: {
|
||||
uri: `ipfs://${cid}`,
|
||||
},
|
||||
})
|
||||
if (meta) {
|
||||
if (meta?.ai_score !== null) {
|
||||
return {
|
||||
number: meta.ai_score,
|
||||
reason: meta.ai_score_reason,
|
||||
}
|
||||
} else {
|
||||
const score = await getOriginalScore(cid)
|
||||
if (score) {
|
||||
await prisma.metadata.update({
|
||||
where: {
|
||||
uri: `ipfs://${cid}`,
|
||||
},
|
||||
data: {
|
||||
ai_score: score.number,
|
||||
ai_score_reason: score.reason,
|
||||
},
|
||||
})
|
||||
|
||||
return score
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const score = await getOriginalScore(cid)
|
||||
if (score) {
|
||||
await prisma.metadata.create({
|
||||
data: {
|
||||
uri: `ipfs://${cid}`,
|
||||
ai_score: score.number,
|
||||
ai_score_reason: score.reason,
|
||||
},
|
||||
})
|
||||
|
||||
return score
|
||||
}
|
||||
}
|
||||
},
|
||||
noUpdate: true,
|
||||
})
|
||||
|
||||
return score
|
||||
}
|
||||
|
||||
export async function GET(req: Request): Promise<Response> {
|
||||
let { cid } = getQuery(req)
|
||||
|
||||
const res = new NextServerResponse()
|
||||
|
||||
if (!cid) {
|
||||
return res.status(400).send("Bad Request")
|
||||
}
|
||||
|
||||
return res.status(200).json({
|
||||
data: await getScore(cid as string),
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
import { getNoteSlug } from "~/lib/helpers"
|
||||
import { cacheDelete, cacheGet } from "~/lib/redis.server"
|
||||
import { NextServerResponse, getQuery } from "~/lib/server-helper"
|
||||
|
||||
export async function getIdBySlug(slug: string, characterId: string | number) {
|
||||
slug = (slug as string)?.toLowerCase?.()
|
||||
|
||||
const result = (await cacheGet({
|
||||
key: ["slug2id", characterId, slug],
|
||||
getValueFun: async () => {
|
||||
let note
|
||||
let cursor = ""
|
||||
|
||||
do {
|
||||
const response = await (
|
||||
await fetch(
|
||||
`https://indexer.crossbell.io/v1/notes?characterId=${characterId}&sources=xlog&cursor=${cursor}&limit=100`,
|
||||
)
|
||||
).json()
|
||||
cursor = response.cursor
|
||||
note = response?.list?.find(
|
||||
(item: any) =>
|
||||
slug === getNoteSlug(item) ||
|
||||
slug === `${characterId}-${item.noteId}`,
|
||||
)
|
||||
} while (!note && cursor)
|
||||
|
||||
return {
|
||||
noteId: note?.noteId,
|
||||
}
|
||||
},
|
||||
noUpdate: true,
|
||||
})) as {
|
||||
noteId: number
|
||||
}
|
||||
|
||||
// revalidate
|
||||
if (result) {
|
||||
const noteIdMatch = slug.match(`^${characterId}-(\\d+)$`)
|
||||
if (!noteIdMatch?.[1]) {
|
||||
fetch(
|
||||
`https://indexer.crossbell.io/v1/characters/${characterId}/notes/${result.noteId}`,
|
||||
)
|
||||
.then((res) => res.json())
|
||||
.then((note) => {
|
||||
if ((note && getNoteSlug(note) !== slug) || note.deleted) {
|
||||
cacheDelete(["slug2id", characterId + "", slug])
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// GET /api/slug2id?characterId=52055&slug=note-144
|
||||
export async function GET(req: Request): Promise<Response> {
|
||||
let { characterId, slug } = getQuery(req)
|
||||
const res = new NextServerResponse()
|
||||
if (!slug || !characterId) {
|
||||
return res.status(400).send("Bad Request")
|
||||
}
|
||||
|
||||
return res
|
||||
.status(200)
|
||||
.send(await getIdBySlug(slug as string, characterId as string))
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
import { OpenAI } from "langchain"
|
||||
import { AnalyzeDocumentChain, loadSummarizationChain } from "langchain/chains"
|
||||
import { PromptTemplate } from "langchain/prompts"
|
||||
import removeMarkdown from "remove-markdown"
|
||||
|
||||
import { Metadata } from "@prisma/client"
|
||||
|
||||
import { toGateway } from "~/lib/ipfs-parser"
|
||||
import prisma from "~/lib/prisma.server"
|
||||
import { cacheGet } from "~/lib/redis.server"
|
||||
import { NextServerResponse, getQuery } from "~/lib/server-helper"
|
||||
|
||||
const model = new OpenAI({
|
||||
openAIApiKey: process.env.OPENAI_API_KEY,
|
||||
modelName: "gpt-3.5-turbo",
|
||||
temperature: 0.3,
|
||||
maxTokens: 400,
|
||||
})
|
||||
|
||||
const chains = new Map<string, AnalyzeDocumentChain>()
|
||||
|
||||
const getOriginalSummary = async (cid: string, lang: string) => {
|
||||
try {
|
||||
let { content } = await (await fetch(toGateway(`ipfs://${cid}`))).json()
|
||||
|
||||
if (content?.length > 5000) {
|
||||
content = content.slice(0, 5000)
|
||||
}
|
||||
if (content?.length < 200) {
|
||||
return ""
|
||||
} else if (content) {
|
||||
console.time(`fetching summary ${cid}, ${lang}`)
|
||||
|
||||
let chain = chains.get(lang)
|
||||
if (!chain) {
|
||||
const prompt = new PromptTemplate({
|
||||
template: `Summarize this in "${lang}" language:
|
||||
"{text}"
|
||||
CONCISE SUMMARY:`,
|
||||
inputVariables: ["text"],
|
||||
})
|
||||
|
||||
const combineDocsChain = loadSummarizationChain(model, {
|
||||
prompt,
|
||||
combineMapPrompt: prompt,
|
||||
combinePrompt: prompt,
|
||||
})
|
||||
|
||||
chain = new AnalyzeDocumentChain({
|
||||
combineDocumentsChain: combineDocsChain,
|
||||
})
|
||||
|
||||
chains.set(lang, chain)
|
||||
}
|
||||
|
||||
const res = await chain.call({
|
||||
input_document: removeMarkdown(content, {
|
||||
useImgAltText: true,
|
||||
gfm: true,
|
||||
}),
|
||||
})
|
||||
|
||||
console.timeEnd(`fetching summary ${cid}, ${lang}`)
|
||||
|
||||
return res?.text
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
console.timeEnd(`fetching summary ${cid}, ${lang}`)
|
||||
}
|
||||
}
|
||||
|
||||
export async function getSummary(cid: string, lang: string = "en") {
|
||||
const summary = await cacheGet({
|
||||
key: ["summary", cid, lang],
|
||||
getValueFun: async () => {
|
||||
if (["en", "zh", "zh-TW", "ja"].includes(lang)) {
|
||||
const key = `ai_summary_${lang.replace("-", "").toLowerCase()}`
|
||||
const meta = await prisma.metadata.findFirst({
|
||||
where: {
|
||||
uri: `ipfs://${cid}`,
|
||||
},
|
||||
})
|
||||
if (meta) {
|
||||
if (meta?.[key as keyof Metadata]) {
|
||||
return meta?.[key as keyof Metadata]
|
||||
} else {
|
||||
const summary = await getOriginalSummary(cid, lang)
|
||||
if (summary) {
|
||||
await prisma.metadata.update({
|
||||
where: {
|
||||
uri: `ipfs://${cid}`,
|
||||
},
|
||||
data: {
|
||||
[key as keyof Metadata]: summary,
|
||||
},
|
||||
})
|
||||
|
||||
return summary
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const summary = await getOriginalSummary(cid, lang)
|
||||
if (summary) {
|
||||
await prisma.metadata.create({
|
||||
data: {
|
||||
uri: `ipfs://${cid}`,
|
||||
[key as keyof Metadata]: summary,
|
||||
},
|
||||
})
|
||||
|
||||
return summary
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
noUpdate: true,
|
||||
})
|
||||
|
||||
return summary
|
||||
}
|
||||
|
||||
export async function GET(req: Request): Promise<Response> {
|
||||
let { cid, lang } = getQuery(req)
|
||||
const res = new NextServerResponse()
|
||||
|
||||
if (!cid) {
|
||||
return res.status(400).send("Bad Request")
|
||||
}
|
||||
|
||||
return res.status(200).json({
|
||||
data: await getSummary(cid as string, lang as string),
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user