Merge branch 'main' into linked-notifications

This commit is contained in:
Face 2025-07-15 18:22:23 +03:00 committed by GitHub
commit 159d371655
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 390 additions and 83 deletions

View file

@ -3,7 +3,7 @@ import { error, json } from '@sveltejs/kit';
import { db } from '$lib/server/db';
import { user } from '$lib/server/db/schema';
import { eq } from 'drizzle-orm';
import { randomBytes } from 'crypto';
import { randomInt } from 'crypto';
import type { RequestHandler } from './$types';
interface DiceRequest {
@ -54,7 +54,7 @@ export const POST: RequestHandler = async ({ request }) => {
throw new Error(`Insufficient funds. You need *${roundedAmount.toFixed(2)} but only have *${roundedBalance.toFixed(2)}`);
}
const gameResult = Math.floor(randomBytes(1)[0] / 42.67) + 1; // This gives us a number between 1-6
const gameResult = randomInt(1, 6);
const won = gameResult === selectedNumber;
const multiplier = 3;

View file

@ -8,6 +8,8 @@ import { getSessionKey } from '$lib/server/games/mines';
import type { RequestHandler } from './$types';
export const POST: RequestHandler = async ({ request }) => {
throw error(503, 'Service temporarily unavailable');
const session = await auth.api.getSession({
headers: request.headers
});

View file

@ -9,6 +9,8 @@ import { redis, } from '$lib/server/redis';
import { getSessionKey } from '$lib/server/games/mines';
export const POST: RequestHandler = async ({ request }) => {
throw error(503, 'Service temporarily unavailable');
const session = await auth.api.getSession({
headers: request.headers
});
@ -40,7 +42,7 @@ export const POST: RequestHandler = async ({ request }) => {
if (game.minePositions.includes(tileIndex)) {
game.status = 'lost';
const minePositions = game.minePositions;
const userId = Number(session.user.id);
const [userData] = await db
.select({ baseCurrencyBalance: user.baseCurrencyBalance })
@ -58,9 +60,9 @@ export const POST: RequestHandler = async ({ request }) => {
updatedAt: new Date()
})
.where(eq(user.id, userId));
await redis.del(getSessionKey(sessionToken));
return json({
hitMine: true,
minePositions,

View file

@ -8,6 +8,8 @@ import { getSessionKey } from '$lib/server/games/mines';
import type { RequestHandler } from './$types';
export const POST: RequestHandler = async ({ request }) => {
throw error(503, 'Service temporarily unavailable');
const session = await auth.api.getSession({
headers: request.headers
});
@ -51,7 +53,7 @@ export const POST: RequestHandler = async ({ request }) => {
}
// transaction token for authentication stuff
const randomBytes = new Uint8Array(8);
const randomBytes = new Uint8Array(8);
crypto.getRandomValues(randomBytes);
const sessionToken = Array.from(randomBytes)
.map(b => b.toString(16).padStart(2, '0'))
@ -85,7 +87,7 @@ export const POST: RequestHandler = async ({ request }) => {
})
.where(eq(user.id, userId));
return {
return {
sessionToken,
newBalance
};