Add get-verify-code endpoint

This commit is contained in:
2026-01-22 14:27:23 -07:00
parent 126a6421d8
commit e2545a0f10
8 changed files with 176 additions and 2 deletions

View File

@@ -65,6 +65,14 @@ export const launcherVersionManifest = mysqlTable('launcherversionmanifest', {
changelog: text('changelog')
})
export const verifyCodes = mysqlTable('verifycodes', {
id: int('id').primaryKey().autoincrement().notNull(),
code: varchar('code', { length: 16 }).notNull(),
ip: varchar('ip', { length: 255 }),
timestamp: int('timestamp').notNull(),
used: boolean('used').default(false).notNull()
})
// berrydashdatabase
export const berryDashUserData = mysqlTable('userdata', {

View File

@@ -7,6 +7,8 @@ import {
latestVersion
} from '../info/general'
import { Context } from 'elysia'
import axios from 'axios'
import FormData from 'form-data'
export function jsonResponse (data: any, status = 200) {
return new Response(JSON.stringify(data, null, 2), {
@@ -104,3 +106,20 @@ export const getClientIp = (context: Context) => {
null
)
}
export const validateTurnstile = async (token: string, remoteip: string) => {
const form = new FormData()
form.append('secret', process.env.TURNSTILE_SECRET_KEY!)
form.append('response', token)
form.append('remoteip', remoteip)
const response = await axios.post(
'https://challenges.cloudflare.com/turnstile/v0/siteverify',
form,
{
headers: form.getHeaders()
}
)
return response.data
}