core/pages/bots/[id]/invite.tsx
Eunwoo Choi 2d68f7aadd
deps: update outdated and critical dependencies (#532)
* deps: bump critical deps version

* chore: specify sentry and dd debug mode

* chore: enable SwcMinify

* chore: casing

* deps: bump mongoose version to 6.8.3

* Revert "deps: bump mongoose version to 6.8.3"

This reverts commit d5b90b5c0909545d4d21553d50c5681bd93a57a4.

* deps: change mongoose version to 5.13.15

* fix: typing

* deps: update audited deps

* deps: update next-pwa and dd-trace@2

* deps: update dd-trace@3 and sentry

* fix: redirects

* fix: style

* feat: redirect using next config

* deps: update mongoose to 6.9.0

* chore: change next version in package.json

* chore: change next version to 12.3.2

* fix: model compile issue

* chore: lint

* chore: remove any

* deps: update jest version to 29

* deps: resolve remaining vulnerabilities

---------

Co-authored-by: skinmaker1345 <me@skinmaker.dev>
2023-02-01 01:34:30 +09:00

20 lines
867 B
TypeScript

import { NextPage, GetServerSideProps } from 'next'
import NotFound from 'pages/404'
import { get } from '@utils/Query'
import { Bots } from '@utils/Mongo'
import { getYYMMDD } from '@utils/Tools'
const Invite: NextPage = () => <NotFound />
export const getServerSideProps: GetServerSideProps = async (ctx) => {
const data = await get.bot.load(ctx.query.id as string)
if(!data) return { props: {} }
const record = await Bots.updateOne({ _id: data.id, 'inviteMetrix.day': getYYMMDD() }, { $inc: { 'inviteMetrix.$.count': 1 } })
if(record.matchedCount === 0) await Bots.findByIdAndUpdate(data.id, { $push: { inviteMetrix: { count: 1 } } }, { upsert: true })
ctx.res.statusCode = 307
ctx.res.setHeader('Location', data.url || `https://discordapp.com/oauth2/authorize?client_id=${data.id}&scope=bot&permissions=0`)
return {
props: {}
}
}
export default Invite