Skip to content

Commit

Permalink
chore: caching requests to optmimize load times and avoid rate limits (
Browse files Browse the repository at this point in the history
…#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
ximxim authored Aug 10, 2023
1 parent e7e5612 commit 70b72cc
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 213 deletions.
1 change: 0 additions & 1 deletion generated/arweave.ts

This file was deleted.

1 change: 0 additions & 1 deletion generated/tweets.ts

This file was deleted.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"start": "next start",
"lint": "next lint",
"prepare": "husky install",
"generate:tweets": "npx node scripts/generateHighlightedTweets.js",
"generate": "yarn graphql-codegen --config codegen.ts"
},
"dependencies": {
Expand Down Expand Up @@ -76,4 +75,4 @@
"tsc-files": "^1.1.3",
"typescript": "5.0.4"
}
}
}
70 changes: 0 additions & 70 deletions scripts/generateHighlightedTweets.js

This file was deleted.

7 changes: 3 additions & 4 deletions src/app/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Metadata, ResolvingMetadata } from 'next'
import { website } from '@/config/website'
import { getDrops } from '@/utils/getDrops'
import { getNow } from '@/utils/getNow'
import { getArweaves } from '@/utils/getArweaves'
import { getArweaveById } from '@/utils/getArweaveById'
import { getDropDate } from '@/utils/getDropDate'

type Props = {
Expand Down Expand Up @@ -67,7 +67,7 @@ const Page = async ({ params, searchParams }: Props) => {
</div>
</div>
</div>
{article && (
{!!article?.content && (
<div className="p-6 md:px-16 lg:px-32 md:py-[54px] rounded-2xl break-words m-4">
<div className="prose mx-auto">
<h2 className="text-[32px] leading-8 md:text-[46px] md:leading-[180%] font-display">
Expand Down Expand Up @@ -160,8 +160,7 @@ async function getPartner(slug: string, spoofDate?: string) {
return notFound()
}

const arweaves = await getArweaves()
const article = get(arweaves, partner.aarweaveDigest)
const article = await getArweaveById(partner.aarweaveDigest)

return { partner, article }
}
Expand Down
35 changes: 35 additions & 0 deletions src/app/api/arweave/route.ts
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 })
}
}
54 changes: 0 additions & 54 deletions src/app/api/generateArweave/route.ts

This file was deleted.

Loading

0 comments on commit 70b72cc

Please sign in to comment.