-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: various social image improvements #270
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
User-agent: * | ||
Allow: / |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,7 @@ import { Redis } from "@upstash/redis"; | |
|
||
const redis = Redis.fromEnv(); | ||
|
||
export async function GET(request: Request, { params }: { params: { id: string } }) { | ||
export async function GET(_: Request, { params }: { params: { id: string } }) { | ||
const shortLink = await redis.get<string>(getShortLinkPersistenceKey(params.id)); | ||
return NextResponse.redirect(shortLink || "/", { | ||
headers: { | ||
"Cache-Control": "public, max-age=3600, stale-while-revalidate=3600, stale-if-error=3600", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can actually cause issues without the correct |
||
}, | ||
}); | ||
return NextResponse.redirect(shortLink || "/"); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ import { Redis } from "@upstash/redis"; | |
import * as crypto from "crypto"; | ||
import { Ratelimit } from "@upstash/ratelimit"; | ||
import { type NextRequest, NextResponse } from "next/server"; | ||
import * as process from "process"; | ||
import { getShortLinkPersistenceKey } from "~/lib/shortLink"; | ||
import { getUserIdentifier } from "~/lib/userIdentifier"; | ||
|
||
|
@@ -55,13 +54,14 @@ export async function POST(request: NextRequest): Promise<NextResponse> { | |
); | ||
} | ||
|
||
const uuid = crypto.randomUUID(); | ||
await redis.set(getShortLinkPersistenceKey(uuid), longURL); | ||
const id = crypto.createHash("sha1").update(longURL).digest("hex"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This ensures that there are fewer short link permutations for the same data. |
||
await redis.set(getShortLinkPersistenceKey(id), longURL); | ||
|
||
const shortURL = `${process.env.DEPLOYMENT_ORIGIN}/s/${uuid}`; | ||
const shortURL = new URL(`/s/${id}`, request.nextUrl.origin); | ||
return NextResponse.json( | ||
{ | ||
shortLink: shortURL, | ||
shortLink: shortURL.href, | ||
imgURL: `${shortURL.href}/img`, | ||
}, | ||
{ | ||
headers: { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This caused warnings in the logic because of an unknown tailwind utility called
undefined