From 5820b70afdb4461868962f7dc48e8dfb15c7aa4f Mon Sep 17 00:00:00 2001 From: wonderlandpark Date: Wed, 2 Jun 2021 12:53:00 +0900 Subject: [PATCH 1/5] fix: adsense --- components/Advertisement.tsx | 34 ++++++++-------------------------- package.json | 1 + pages/bots/[id]/index.tsx | 13 ++++--------- yarn.lock | 5 +++++ 4 files changed, 18 insertions(+), 35 deletions(-) diff --git a/components/Advertisement.tsx b/components/Advertisement.tsx index 841714b..85b3580 100644 --- a/components/Advertisement.tsx +++ b/components/Advertisement.tsx @@ -1,37 +1,19 @@ -import { useEffect } from 'react' -import Logger from '@utils/Logger' +import AdSense from 'react-adsense' const Advertisement: React.FC = ({ size = 'short' }) => { - useEffect(() => { - if (process.env.NODE_ENV === 'production') { - window.adsbygoogle = window.adsbygoogle || [] - try { - window.adsbygoogle.push({}) - Logger.debug('Ad Pushed') - } - catch { - Logger.debug('Ad Push Fail') - } - } - - }, []) - return
- {process.env.NODE_ENV === 'production' ? ( - ) : ( 'Advertisement' diff --git a/package.json b/package.json index c85b06e..9790af9 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "postcss-preset-env": "6.7.0", "rc-tooltip": "5.1.1", "react": "17.0.2", + "react-adsense": "0.1.0", "react-dom": "17.0.2", "react-hotkeys": "2.0.0", "react-responsive-modal": "6.0.1", diff --git a/pages/bots/[id]/index.tsx b/pages/bots/[id]/index.tsx index dbae0ba..c8daf14 100644 --- a/pages/bots/[id]/index.tsx +++ b/pages/bots/[id]/index.tsx @@ -322,16 +322,11 @@ const Bots: NextPage = ({ data, desc, date, user, theme, csrfToken })

자세한 내용은 해당 글을 확인해주세요.

: '' } -
- - - -
+ + + +
- -
-
-
} diff --git a/yarn.lock b/yarn.lock index e4a6fa0..b0f2e29 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7931,6 +7931,11 @@ re2@^1.15.9: nan "^2.14.2" node-gyp "^7.1.2" +react-adsense@0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/react-adsense/-/react-adsense-0.1.0.tgz#f170007a9ab05ee2cd1c915cdc9788624658e3c1" + integrity sha512-VzGMH9qA7bBKAveK1joFWphhB7e2Y1ToSGzUa8b7eit3+VSkg/2MSvKxe5d/r4mcmkOHu6CHNJW0nn6RQC3IZA== + react-dom@17.0.2: version "17.0.2" resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-17.0.2.tgz#ecffb6845e3ad8dbfcdc498f0d0a939736502c23" From 86621cc4a59be9746aad6b47cfc4f02e2f9cc254 Mon Sep 17 00:00:00 2001 From: wonderlandpark Date: Wed, 2 Jun 2021 13:14:48 +0900 Subject: [PATCH 2/5] fix(Advertisement): checking if it is production --- components/Advertisement.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/Advertisement.tsx b/components/Advertisement.tsx index 85b3580..d24bba0 100644 --- a/components/Advertisement.tsx +++ b/components/Advertisement.tsx @@ -4,11 +4,11 @@ const Advertisement: React.FC = ({ size = 'short' }) => { return
- {true ? ( + {process.env.NODE_ENV === 'production' ? ( Date: Wed, 2 Jun 2021 13:50:22 +0900 Subject: [PATCH 3/5] feat(api): blocking unverified user --- pages/api/auth/discord/callback.ts | 3 +++ pages/callback/discord.tsx | 2 +- types/index.ts | 1 + utils/Query.ts | 3 ++- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pages/api/auth/discord/callback.ts b/pages/api/auth/discord/callback.ts index 218eaec..7382e72 100644 --- a/pages/api/auth/discord/callback.ts +++ b/pages/api/auth/discord/callback.ts @@ -53,7 +53,10 @@ const Callback = RequestHandler().get(async (req: ApiRequest, res) => { email: user.email, username: user.username, discriminator: user.discriminator, + verified: user.verified }) + + if(!userToken) return res.redirect(301, 'https://docs.koreanbots.dev/bots/account/unverified') const info = verify(userToken) res.setHeader( 'set-cookie', diff --git a/pages/callback/discord.tsx b/pages/callback/discord.tsx index e8d19f4..0d44875 100644 --- a/pages/callback/discord.tsx +++ b/pages/callback/discord.tsx @@ -1,4 +1,4 @@ -import { NextPage} from 'next' +import { NextPage } from 'next' import dynamic from 'next/dynamic' import { useRouter } from 'next/router' import { useEffect, useState } from 'react' diff --git a/types/index.ts b/types/index.ts index 5d7d1dc..bd1314b 100644 --- a/types/index.ts +++ b/types/index.ts @@ -130,6 +130,7 @@ export interface TokenRegister { email: string username: string discriminator: string + verified: boolean } export interface DiscordUserInfo { diff --git a/utils/Query.ts b/utils/Query.ts index 1ac3b0f..9d0b5cf 100644 --- a/utils/Query.ts +++ b/utils/Query.ts @@ -324,9 +324,10 @@ async function getDiscordUser(id: string):Promise { return DiscordBot.users.cache.get(id) ?? await DiscordBot.users.fetch(id, false, true).then(u => u.toJSON()).catch(()=>null) } -async function assignToken(info: TokenRegister):Promise { +async function assignToken(info: TokenRegister):Promise { let token = await knex('users').select(['token']).where({ id: info.id }) let t: string + if(!info.verified) return null if(token.length === 0) { t = sign({ id: info.id }, { expiresIn: '30d' }) await knex('users').insert({ token: t, date: Math.round(Number(new Date()) / 1000), id: info.id, email: info.email, tag: info.discriminator, username: info.username, discord: sign({ access_token: info.access_token, expires_in: info.expires_in, refresh_token: info.refresh_token }) }) From e5a5f0534d6c16b081460b731863fde371edcf4a Mon Sep 17 00:00:00 2001 From: wonderlandpark Date: Wed, 2 Jun 2021 14:56:05 +0900 Subject: [PATCH 4/5] feat(api): blocking blocked user --- pages/api/auth/discord/callback.ts | 3 ++- utils/Query.ts | 13 ++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pages/api/auth/discord/callback.ts b/pages/api/auth/discord/callback.ts index 7382e72..352cfca 100644 --- a/pages/api/auth/discord/callback.ts +++ b/pages/api/auth/discord/callback.ts @@ -56,7 +56,8 @@ const Callback = RequestHandler().get(async (req: ApiRequest, res) => { verified: user.verified }) - if(!userToken) return res.redirect(301, 'https://docs.koreanbots.dev/bots/account/unverified') + if(userToken === 1) return res.redirect(301, 'https://docs.koreanbots.dev/bots/account/unverified') + else if(userToken === 2) return res.redirect(301, 'https://docs.koreanbots.dev/bots/account/blocked') const info = verify(userToken) res.setHeader( 'set-cookie', diff --git a/utils/Query.ts b/utils/Query.ts index 9d0b5cf..2e0862c 100644 --- a/utils/Query.ts +++ b/utils/Query.ts @@ -324,15 +324,22 @@ async function getDiscordUser(id: string):Promise { return DiscordBot.users.cache.get(id) ?? await DiscordBot.users.fetch(id, false, true).then(u => u.toJSON()).catch(()=>null) } -async function assignToken(info: TokenRegister):Promise { - let token = await knex('users').select(['token']).where({ id: info.id }) +/** + * + * @param info + * @returns 1 - UnVerified + * @returns 2 - Blocked + */ +async function assignToken(info: TokenRegister):Promise { + let token = await knex('users').select(['token', 'perm']).where({ id: info.id }) let t: string - if(!info.verified) return null + if(!info.verified) return 1 if(token.length === 0) { t = sign({ id: info.id }, { expiresIn: '30d' }) await knex('users').insert({ token: t, date: Math.round(Number(new Date()) / 1000), id: info.id, email: info.email, tag: info.discriminator, username: info.username, discord: sign({ access_token: info.access_token, expires_in: info.expires_in, refresh_token: info.refresh_token }) }) token = await knex('users').select(['token']).where({ id: info.id }) } else await knex('users').update({ email: info.email, tag: info.discriminator, username: info.username, discord: sign({ access_token: info.access_token, expires_in: info.expires_in, refresh_token: info.refresh_token }) }).where({ id: info.id }) + if(token[0].perm !== 'user') return 2 if(!verify(token[0]?.token ?? '')) { t = sign({ id: info.id }, { expiresIn: '30d' }) await knex('users').update({ token: t }).where({ id: info.id }) From ea40ea1c10112208bfc8e8b973b3f38eb965e823 Mon Sep 17 00:00:00 2001 From: wonderlandpark Date: Wed, 2 Jun 2021 14:56:17 +0900 Subject: [PATCH 5/5] chore: updated api-docs hash --- api-docs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api-docs b/api-docs index 6d23d85..3636d4a 160000 --- a/api-docs +++ b/api-docs @@ -1 +1 @@ -Subproject commit 6d23d8547697557601eb763eb3af9d318d2610d7 +Subproject commit 3636d4a1519f412ede7ab0b301dd8ca4bdd16a7b