-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: caching requests to optmimize load times and avoid rate limits (…
…#179) * chore: caching requests to optmimize load times and avoid rate limits * chore: caching working * chore: changed MINT_DOT_FUN env var * chore: using OCS api key * chore: hardcoded onchainsummer.xyz as a default if VERCEL_URL is missing
- Loading branch information
Showing
14 changed files
with
142 additions
and
213 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { NextResponse, NextRequest } from 'next/server' | ||
import { SDK } from '@/utils/graphqlSdk' | ||
|
||
type ArticleType = { content: { body: string; title: string } } | undefined | ||
|
||
export async function POST(request: NextRequest) { | ||
try { | ||
if (request.headers.get('x-api-key') !== process.env.OCS_API_KEY) | ||
return NextResponse.json({}, { status: 401 }) | ||
|
||
const { digestId } = await request.json() | ||
|
||
if (!digestId) return NextResponse.json({}, { status: 400 }) | ||
|
||
let article: ArticleType | ||
const digest = await SDK.GetMirrorTransactions({ digest: digestId }) | ||
console.log('digest', digest) | ||
|
||
const articleId = digest?.transactions?.edges[0]?.node?.id | ||
|
||
if (articleId) { | ||
const res = await fetch(`https://arweave.net/${articleId}`, { | ||
// Revalidate every minute | ||
next: { revalidate: 1 * 60 }, | ||
}) | ||
article = (await res?.json()) as { | ||
content: { body: string; title: string } | ||
} | ||
} | ||
|
||
return NextResponse.json(article, { status: 200 }) | ||
} catch { | ||
return NextResponse.json({}, { status: 400 }) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.