WIP: remove drizzle completly, add env variable for api URL

This commit is contained in:
Pablu23
2025-10-10 17:03:30 +02:00
parent 5270368cec
commit 79138f4b4c
10 changed files with 67 additions and 1900 deletions

View File

@@ -1,2 +1,2 @@
DATABASE_URL=local.db PUBLIC_API_BASE="http://hitstar.xyz/api/"
PUBLIC_CLIENT_ID=ABCD PUBLIC_API_WS_BASE="ws://hitstar.xyz/api/"

View File

@@ -1,11 +0,0 @@
import { defineConfig } from 'drizzle-kit';
if (!process.env.DATABASE_URL) throw new Error('DATABASE_URL is not set');
export default defineConfig({
schema: './src/lib/server/db/schema.ts',
dialect: 'sqlite',
dbCredentials: { url: process.env.DATABASE_URL },
verbose: true,
strict: true
});

View File

@@ -1,31 +0,0 @@
CREATE TABLE `lobbys` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`host_email` text,
FOREIGN KEY (`host_email`) REFERENCES `users`(`email`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `sessions` (
`id` text PRIMARY KEY NOT NULL,
`access_token` text,
`refresh_token` text,
`user_email` text,
FOREIGN KEY (`user_email`) REFERENCES `users`(`email`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `auth_states` (
`id` text PRIMARY KEY NOT NULL,
`code_verifier` text NOT NULL
);
--> statement-breakpoint
CREATE TABLE `user_in_lobby` (
`user_email` text NOT NULL,
`lobby_id` integer NOT NULL,
PRIMARY KEY(`user_email`, `lobby_id`),
FOREIGN KEY (`user_email`) REFERENCES `users`(`email`) ON UPDATE no action ON DELETE no action,
FOREIGN KEY (`lobby_id`) REFERENCES `lobbys`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `users` (
`email` text PRIMARY KEY NOT NULL,
`username` text
);

View File

@@ -1,215 +0,0 @@
{
"version": "6",
"dialect": "sqlite",
"id": "6bf15c3f-ef71-4979-b04a-1a93b3274a23",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"lobbys": {
"name": "lobbys",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": true
},
"host_email": {
"name": "host_email",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"lobbys_host_email_users_email_fk": {
"name": "lobbys_host_email_users_email_fk",
"tableFrom": "lobbys",
"tableTo": "users",
"columnsFrom": [
"host_email"
],
"columnsTo": [
"email"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"sessions": {
"name": "sessions",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"access_token": {
"name": "access_token",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"refresh_token": {
"name": "refresh_token",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"user_email": {
"name": "user_email",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"sessions_user_email_users_email_fk": {
"name": "sessions_user_email_users_email_fk",
"tableFrom": "sessions",
"tableTo": "users",
"columnsFrom": [
"user_email"
],
"columnsTo": [
"email"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"auth_states": {
"name": "auth_states",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"code_verifier": {
"name": "code_verifier",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"user_in_lobby": {
"name": "user_in_lobby",
"columns": {
"user_email": {
"name": "user_email",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"lobby_id": {
"name": "lobby_id",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"user_in_lobby_user_email_users_email_fk": {
"name": "user_in_lobby_user_email_users_email_fk",
"tableFrom": "user_in_lobby",
"tableTo": "users",
"columnsFrom": [
"user_email"
],
"columnsTo": [
"email"
],
"onDelete": "no action",
"onUpdate": "no action"
},
"user_in_lobby_lobby_id_lobbys_id_fk": {
"name": "user_in_lobby_lobby_id_lobbys_id_fk",
"tableFrom": "user_in_lobby",
"tableTo": "lobbys",
"columnsFrom": [
"lobby_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {
"user_in_lobby_user_email_lobby_id_pk": {
"columns": [
"user_email",
"lobby_id"
],
"name": "user_in_lobby_user_email_lobby_id_pk"
}
},
"uniqueConstraints": {},
"checkConstraints": {}
},
"users": {
"name": "users",
"columns": {
"email": {
"name": "email",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"username": {
"name": "username",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
}
},
"views": {},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
},
"internal": {
"indexes": {}
}
}

View File

@@ -1,13 +0,0 @@
{
"version": "7",
"dialect": "sqlite",
"entries": [
{
"idx": 0,
"version": "6",
"when": 1758887320368,
"tag": "0000_numerous_chronomancer",
"breakpoints": true
}
]
}

1591
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -11,11 +11,7 @@
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"format": "prettier --write .", "format": "prettier --write .",
"lint": "prettier --check . && eslint .", "lint": "prettier --check . && eslint ."
"db:push": "drizzle-kit push",
"db:generate": "drizzle-kit generate",
"db:migrate": "drizzle-kit migrate",
"db:studio": "drizzle-kit studio"
}, },
"devDependencies": { "devDependencies": {
"@eslint/compat": "^1.2.5", "@eslint/compat": "^1.2.5",
@@ -25,7 +21,6 @@
"@sveltejs/vite-plugin-svelte": "^6.0.0", "@sveltejs/vite-plugin-svelte": "^6.0.0",
"@types/better-sqlite3": "^7.6.12", "@types/better-sqlite3": "^7.6.12",
"@types/node": "^22", "@types/node": "^22",
"drizzle-kit": "^0.30.2",
"eslint": "^9.18.0", "eslint": "^9.18.0",
"eslint-config-prettier": "^10.0.1", "eslint-config-prettier": "^10.0.1",
"eslint-plugin-svelte": "^3.0.0", "eslint-plugin-svelte": "^3.0.0",
@@ -40,8 +35,6 @@
}, },
"dependencies": { "dependencies": {
"@tailwindcss/vite": "^4.1.14", "@tailwindcss/vite": "^4.1.14",
"better-sqlite3": "^11.8.0",
"drizzle-orm": "^0.40.0",
"tailwindcss": "^4.1.14" "tailwindcss": "^4.1.14"
} }
} }

View File

@@ -1,11 +1,20 @@
import { type Handle, type HandleFetch } from '@sveltejs/kit'; import { type Handle } from '@sveltejs/kit';
import { env } from '$env/dynamic/public';
export const handle: Handle = async ({ event, resolve }) => { export const handle: Handle = async ({ event, resolve }) => {
const sessionId = event.cookies.get('session_id'); const sessionId = event.cookies.get('session_id');
event.locals.user = null; event.locals.user = null;
if (sessionId) { if (sessionId) {
const request = new Request('http://hitstar.xyz/api/user/me'); if (!env.PUBLIC_API_BASE) throw new Error('PUBLIC_API_BASE is not set');
console.log(env.PUBLIC_API_BASE);
const u = new URL('user/me', env.PUBLIC_API_BASE);
console.log(u);
const request = new Request(u);
request.headers.set( request.headers.set(
'cookie', 'cookie',
event.cookies event.cookies

View File

@@ -2,13 +2,17 @@ import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types'; import type { PageServerLoad } from './$types';
import type { User } from '../../../app'; import type { User } from '../../../app';
import type { Settings } from '$lib/types'; import type { Settings } from '$lib/types';
import { env } from '$env/dynamic/public';
export const load: PageServerLoad = async ({ params, fetch, locals: { user } }) => { export const load: PageServerLoad = async ({ params, fetch, locals: { user } }) => {
if (!user) { if (!user) {
redirect(307, '/'); redirect(307, '/');
} }
const response = await fetch(`http://hitstar.xyz/api/lobby/${params.id}`, { if (!env.PUBLIC_API_BASE) redirect(307, '/error');
const u = new URL(`lobby/${params.id}`, env.PUBLIC_API_BASE);
const response = await fetch(u, {
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
} }

View File

@@ -5,6 +5,8 @@
import PlayerList from '$lib/components/PlayerList.svelte'; import PlayerList from '$lib/components/PlayerList.svelte';
import GameSettings from '$lib/components/GameSettings.svelte'; import GameSettings from '$lib/components/GameSettings.svelte';
import type { PageProps } from './$types'; import type { PageProps } from './$types';
import { env } from '$env/dynamic/public';
import { goto } from '$app/navigation';
// Create WebSocket client // Create WebSocket client
@@ -84,8 +86,14 @@
} }
onMount(() => { onMount(() => {
wsClient.connect(`ws://hitstar.xyz/api/lobby?id=${lobbyCode}`); if (!env.PUBLIC_API_WS_BASE) {
wsClient.gameSettings = data.lobby.gameSettings goto('/error');
return;
}
const u = new URL(`lobby?id=${lobbyCode}`, env.PUBLIC_API_WS_BASE);
wsClient.connect(u.href);
wsClient.gameSettings = data.lobby.gameSettings;
}); });
onDestroy(() => { onDestroy(() => {
@@ -130,7 +138,11 @@
<!-- Left column: Player list --> <!-- Left column: Player list -->
<div class="md:col-span-1"> <div class="md:col-span-1">
{#if wsClient.connected} {#if wsClient.connected}
<PlayerList players={wsClient.players} maxPlayers={wsClient.gameSettings.maxPlayers} host={data.lobby.host} /> <PlayerList
players={wsClient.players}
maxPlayers={wsClient.gameSettings.maxPlayers}
host={data.lobby.host}
/>
{:else} {:else}
<div class="bg-white rounded-lg shadow-sm p-5 flex items-center justify-center"> <div class="bg-white rounded-lg shadow-sm p-5 flex items-center justify-center">
<div class="flex items-center text-amber-600"> <div class="flex items-center text-amber-600">