mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-30 21:35:39 +01:00
feat: patreon check
This commit is contained in:
1 parent
cb09f57a91
commit
0a0376312b
8 files changed
+114
-19
No files matched your search
File renamed without changes.
@@ -0,0 +1,75 @@
|
|||||||
|
import { NextResponse } from 'next/server';
|
||||||
|
|
||||||
|
interface PatreonMembershipResponse {
|
||||||
|
data: {
|
||||||
|
attributes: unknown;
|
||||||
|
id: `${number}`;
|
||||||
|
relationships: {
|
||||||
|
memberships: {
|
||||||
|
data: {
|
||||||
|
id: string; // uuid
|
||||||
|
type: 'member';
|
||||||
|
}[];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
type: 'user';
|
||||||
|
};
|
||||||
|
included: (
|
||||||
|
| {
|
||||||
|
attributes: {
|
||||||
|
patron_status:
|
||||||
|
| 'active_patron'
|
||||||
|
| 'declined_patron'
|
||||||
|
| 'former_patron'
|
||||||
|
| null; // null = never a paid member
|
||||||
|
};
|
||||||
|
id: string; // uuid
|
||||||
|
relationships: {
|
||||||
|
campaign: {
|
||||||
|
data: {
|
||||||
|
id: `${number}`; // id of my campaign to check against
|
||||||
|
type: 'campaign';
|
||||||
|
};
|
||||||
|
links: {
|
||||||
|
related: string; // url
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
type: 'member';
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
attributes: {};
|
||||||
|
id: `${number}`;
|
||||||
|
type: 'campaign'; // ignore this discriminator
|
||||||
|
}
|
||||||
|
)[];
|
||||||
|
links: {
|
||||||
|
self: 'https://www.patreon.com/api/oauth2/v2/user/124201389';
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function GET(
|
||||||
|
request: Request,
|
||||||
|
{ params }: { params: { token: string } },
|
||||||
|
) {
|
||||||
|
const response = await fetch(
|
||||||
|
encodeURI(
|
||||||
|
'https://www.patreon.com/api/oauth2/v2/identity?include=memberships.campaign&fields[member]=patron_status',
|
||||||
|
),
|
||||||
|
{ headers: { Authorization: `Bearer ${params.token}` } },
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!response.ok) return NextResponse.json(false);
|
||||||
|
|
||||||
|
const json = (await response.json()) as PatreonMembershipResponse;
|
||||||
|
|
||||||
|
return NextResponse.json(
|
||||||
|
json.included.some(
|
||||||
|
(item) =>
|
||||||
|
item.type === 'member' &&
|
||||||
|
item.relationships.campaign.data.id ===
|
||||||
|
process.env.PATREON_CAMPAIGN_ID &&
|
||||||
|
item.attributes.patron_status === 'active_patron',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
File renamed without changes.
@@ -51,7 +51,7 @@ export default function Page({
|
|||||||
if (!searchParams.code) break;
|
if (!searchParams.code) break;
|
||||||
|
|
||||||
const data = (await fetch(
|
const data = (await fetch(
|
||||||
`/api/auth/patreon/${searchParams.code}`,
|
`/api/patreon/auth/${searchParams.code}`,
|
||||||
).then((response) => response.json())) as PatreonAuthResponse;
|
).then((response) => response.json())) as PatreonAuthResponse;
|
||||||
|
|
||||||
mutateApp((draft) => {
|
mutateApp((draft) => {
|
||||||
|
|||||||
+14
-12
@@ -1,10 +1,11 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { Box, BoxProps, Flex, Text } from '@radix-ui/themes';
|
import { Box, BoxProps, Text } from '@radix-ui/themes';
|
||||||
import { uniqueId } from 'lodash';
|
import { uniqueId } from 'lodash';
|
||||||
import { useEffect, useRef } from 'react';
|
import { useEffect, useRef } from 'react';
|
||||||
import { Vector2Tuple } from 'three';
|
import { Vector2Tuple } from 'three';
|
||||||
import { imgur } from '../core/blitzkit/imgur';
|
import { imgur } from '../core/blitzkit/imgur';
|
||||||
|
import { useAdExempt } from '../hooks/useAdExempt';
|
||||||
|
|
||||||
export enum AdType {
|
export enum AdType {
|
||||||
MediumRectangleHorizontalPurple = 738182777,
|
MediumRectangleHorizontalPurple = 738182777,
|
||||||
@@ -28,6 +29,8 @@ export function Ad({ type, style, ...props }: AdProps) {
|
|||||||
const id = useRef(uniqueId());
|
const id = useRef(uniqueId());
|
||||||
const dimensions = AD_DIMENSIONS[type];
|
const dimensions = AD_DIMENSIONS[type];
|
||||||
|
|
||||||
|
useAdExempt();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(window as any).msAdsQueue.push(function () {
|
(window as any).msAdsQueue.push(function () {
|
||||||
(window as any).mmnow.render({
|
(window as any).mmnow.render({
|
||||||
@@ -51,19 +54,18 @@ export function Ad({ type, style, ...props }: AdProps) {
|
|||||||
}}
|
}}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
<Flex
|
<Text
|
||||||
position="absolute"
|
color="gray"
|
||||||
top="50%"
|
style={{
|
||||||
left="50%"
|
position: 'absolute',
|
||||||
style={{ transform: 'translate(-50%, -50%)' }}
|
top: '50%',
|
||||||
direction="column"
|
left: '50%',
|
||||||
|
transform: 'translate(-50%, -50%)',
|
||||||
|
}}
|
||||||
align="center"
|
align="center"
|
||||||
>
|
>
|
||||||
<Text color="gray">Advertisement</Text>
|
Advertisement
|
||||||
<Text size="1" color="gray">
|
</Text>
|
||||||
{dimensions[0]}x{dimensions[1]}
|
|
||||||
</Text>
|
|
||||||
</Flex>
|
|
||||||
|
|
||||||
<Box
|
<Box
|
||||||
width={`${dimensions[0]}px`}
|
width={`${dimensions[0]}px`}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Cross1Icon,
|
Cross1Icon,
|
||||||
DiscordLogoIcon,
|
DiscordLogoIcon,
|
||||||
@@ -16,7 +18,7 @@ import {
|
|||||||
Separator,
|
Separator,
|
||||||
Text,
|
Text,
|
||||||
} from '@radix-ui/themes';
|
} from '@radix-ui/themes';
|
||||||
import { usePathname } from 'next/navigation';
|
import { usePathname, useRouter } from 'next/navigation';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { REGIONS } from '../../constants/regions';
|
import { REGIONS } from '../../constants/regions';
|
||||||
import { TOOLS } from '../../constants/tools';
|
import { TOOLS } from '../../constants/tools';
|
||||||
@@ -35,6 +37,7 @@ import * as styles from './index.css';
|
|||||||
export const NAVBAR_HEIGHT = 64;
|
export const NAVBAR_HEIGHT = 64;
|
||||||
|
|
||||||
export default function Navbar() {
|
export default function Navbar() {
|
||||||
|
const router = useRouter();
|
||||||
const [showHamburgerMenu, setShowHamburgerMenu] = useState(false);
|
const [showHamburgerMenu, setShowHamburgerMenu] = useState(false);
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const logins = useApp((state) => state.logins);
|
const logins = useApp((state) => state.logins);
|
||||||
@@ -191,7 +194,7 @@ export default function Navbar() {
|
|||||||
{!logins.patreon && (
|
{!logins.patreon && (
|
||||||
<Link
|
<Link
|
||||||
style={{ width: '100%' }}
|
style={{ width: '100%' }}
|
||||||
href={`https://www.patreon.com/oauth2/authorize?response_type=code&client_id=${process.env.NEXT_PUBLIC_PATREON_CLIENT_ID}&redirect_uri=${process.env.NEXT_PUBLIC_PATREON_REDIRECT_URI}`}
|
href={`https://www.patreon.com/oauth2/authorize?response_type=code&client_id=${process.env.NEXT_PUBLIC_PATREON_CLIENT_ID}&redirect_uri=${process.env.NEXT_PUBLIC_PATREON_REDIRECT_URI}&scope=identity`}
|
||||||
>
|
>
|
||||||
<Button style={{ width: '100%' }} color="tomato">
|
<Button style={{ width: '100%' }} color="tomato">
|
||||||
<PatreonIcon width={15} height={15} /> Patreon
|
<PatreonIcon width={15} height={15} /> Patreon
|
||||||
@@ -215,9 +218,13 @@ export default function Navbar() {
|
|||||||
{REGIONS.map((region) => (
|
{REGIONS.map((region) => (
|
||||||
<Dialog.Close>
|
<Dialog.Close>
|
||||||
<Link
|
<Link
|
||||||
href={`https://api.worldoftanks.${region}/wot/auth/login/?application_id=${WARGAMING_APPLICATION_ID}&redirect_uri=${encodeURIComponent(
|
href={
|
||||||
`${location.origin}/auth/wargaming?return=${location.origin}${location.pathname}`,
|
typeof window?.location === undefined
|
||||||
)}`}
|
? undefined
|
||||||
|
: `https://api.worldoftanks.${region}/wot/auth/login/?application_id=${WARGAMING_APPLICATION_ID}&redirect_uri=${encodeURIComponent(
|
||||||
|
`${location.origin}/auth/wargaming?return=${location.origin}${location.pathname}`,
|
||||||
|
)}`
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<Button color="red">
|
<Button color="red">
|
||||||
{strings.common.regions.normal[region]}
|
{strings.common.regions.normal[region]}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ export async function extendAuthPatreon() {
|
|||||||
if (!patreon) return;
|
if (!patreon) return;
|
||||||
|
|
||||||
const data = (await fetch(
|
const data = (await fetch(
|
||||||
`/api/auth/patreon/refresh/${patreon.refreshToken}`,
|
`/api/patreon/refresh/${patreon.refreshToken}`,
|
||||||
).then((response) => response.json())) as PatreonAuthResponse;
|
).then((response) => response.json())) as PatreonAuthResponse;
|
||||||
|
|
||||||
mutateApp((draft) => {
|
mutateApp((draft) => {
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { useApp } from '../stores/app';
|
||||||
|
|
||||||
|
export function useAdExempt() {
|
||||||
|
const patreon = useApp((state) => state.logins.patreon);
|
||||||
|
|
||||||
|
if (!patreon) return false;
|
||||||
|
|
||||||
|
fetch(`/api/patreon/membership/${patreon.token}`)
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then(console.log);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user