-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
100 additions
and
110 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,27 +1,3 @@ | ||
# visit https://giscus.app to get your Giscus ids | ||
NEXT_PUBLIC_GISCUS_REPO= | ||
NEXT_PUBLIC_GISCUS_REPOSITORY_ID= | ||
NEXT_PUBLIC_GISCUS_CATEGORY= | ||
NEXT_PUBLIC_GISCUS_CATEGORY_ID= | ||
NEXT_PUBLIC_UTTERANCES_REPO= | ||
NEXT_PUBLIC_DISQUS_SHORTNAME= | ||
|
||
NEXT_PUBLIC_LANYARD_KV_KEY= | ||
|
||
MAILCHIMP_API_KEY= | ||
MAILCHIMP_API_SERVER= | ||
MAILCHIMP_AUDIENCE_ID= | ||
|
||
BUTTONDOWN_API_KEY= | ||
|
||
CONVERTKIT_API_KEY= | ||
# curl https://api.convertkit.com/v3/forms?api_key=<your_public_api_key> to get your form ID | ||
CONVERTKIT_FORM_ID= | ||
|
||
KLAVIYO_API_KEY= | ||
KLAVIYO_LIST_ID= | ||
|
||
REVUE_API_KEY= | ||
|
||
EMAILOCTOPUS_API_KEY= | ||
EMAILOCTOPUS_LIST_ID= | ||
UPSTASH_REDIS_REST_URL= | ||
UPSTASH_REDIS_REST_TOKEN= |
Large diffs are not rendered by default.
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 |
---|---|---|
@@ -1,42 +1,39 @@ | ||
import { Redis } from "@upstash/redis"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
import { Redis } from '@upstash/redis' | ||
import { NextRequest, NextResponse } from 'next/server' | ||
|
||
const redis = Redis.fromEnv(); | ||
export const runtime = "edge"; | ||
const redis = Redis.fromEnv() | ||
export const runtime = 'edge' | ||
|
||
export async function POST(req: NextRequest): Promise<NextResponse> { | ||
if (req.headers.get("Content-Type") !== "application/json") { | ||
return new NextResponse("content type must be json", { status: 400 }); | ||
if (req.headers.get('Content-Type') !== 'application/json') { | ||
return new NextResponse('content type must be json', { status: 400 }) | ||
} | ||
|
||
const body = await req.json(); | ||
let slug: string | undefined = undefined; | ||
const body = await req.json() | ||
let slug: string | undefined = undefined | ||
|
||
if ("slug" in body) slug = body.slug; | ||
if ('slug' in body) slug = body.slug | ||
|
||
if (!slug) return new NextResponse("slug not found", { status: 400 }); | ||
if (!slug) return new NextResponse('slug not found', { status: 400 }) | ||
|
||
const ip = req.ip; | ||
const ip = req.ip | ||
|
||
if (ip) { | ||
const buf = await crypto.subtle.digest( | ||
"SHA-256", | ||
new TextEncoder().encode(ip), | ||
); | ||
const buf = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(ip)) | ||
const hash = Array.from(new Uint8Array(buf)) | ||
.map((b) => b.toString(16).padStart(2, "0")) | ||
.join(""); | ||
.map((b) => b.toString(16).padStart(2, '0')) | ||
.join('') | ||
|
||
const isNew = await redis.set(["deduplicate", hash, slug].join(":"), true, { | ||
const isNew = await redis.set(['deduplicate', hash, slug].join(':'), true, { | ||
nx: true, | ||
ex: 24 * 60 * 60, | ||
}); | ||
}) | ||
|
||
if (!isNew) { | ||
new NextResponse(null, { status: 202 }); | ||
new NextResponse(null, { status: 202 }) | ||
} | ||
} | ||
|
||
await redis.incr(["pageviews", "projects", slug].join(":")); | ||
return new NextResponse(null, { status: 202 }); | ||
} | ||
await redis.incr(['pageviews', 'projects', slug].join(':')) | ||
return new NextResponse(null, { status: 202 }) | ||
} |
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 |
---|---|---|
@@ -1,17 +1,17 @@ | ||
"use client"; | ||
'use client' | ||
|
||
import { useEffect } from "react"; | ||
import { useEffect } from 'react' | ||
|
||
export const ReportView: React.FC<{ slug: string }> = ({ slug }) => { | ||
useEffect(() => { | ||
fetch("/api/incr", { | ||
method: "POST", | ||
fetch('/api/incr', { | ||
method: 'POST', | ||
headers: { | ||
"Content-Type": "application/json", | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ slug }), | ||
}); | ||
}, [slug]); | ||
}) | ||
}, [slug]) | ||
|
||
return null; | ||
}; | ||
return null | ||
} |
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 |
---|---|---|
|
@@ -139,4 +139,4 @@ module.exports = [ | |
destination: '/blog/wolvctf-2023/wannaflag-series/', | ||
permanent: true, | ||
}, | ||
] | ||
] |
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