WIP: remove drizzle completly, add env variable for api URL
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
DATABASE_URL=local.db
|
||||
PUBLIC_CLIENT_ID=ABCD
|
||||
PUBLIC_API_BASE="http://hitstar.xyz/api/"
|
||||
PUBLIC_API_WS_BASE="ws://hitstar.xyz/api/"
|
||||
|
||||
@@ -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
|
||||
});
|
||||
@@ -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
|
||||
);
|
||||
@@ -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": {}
|
||||
}
|
||||
}
|
||||
@@ -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
1591
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -11,11 +11,7 @@
|
||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
||||
"format": "prettier --write .",
|
||||
"lint": "prettier --check . && eslint .",
|
||||
"db:push": "drizzle-kit push",
|
||||
"db:generate": "drizzle-kit generate",
|
||||
"db:migrate": "drizzle-kit migrate",
|
||||
"db:studio": "drizzle-kit studio"
|
||||
"lint": "prettier --check . && eslint ."
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/compat": "^1.2.5",
|
||||
@@ -25,7 +21,6 @@
|
||||
"@sveltejs/vite-plugin-svelte": "^6.0.0",
|
||||
"@types/better-sqlite3": "^7.6.12",
|
||||
"@types/node": "^22",
|
||||
"drizzle-kit": "^0.30.2",
|
||||
"eslint": "^9.18.0",
|
||||
"eslint-config-prettier": "^10.0.1",
|
||||
"eslint-plugin-svelte": "^3.0.0",
|
||||
@@ -40,8 +35,6 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@tailwindcss/vite": "^4.1.14",
|
||||
"better-sqlite3": "^11.8.0",
|
||||
"drizzle-orm": "^0.40.0",
|
||||
"tailwindcss": "^4.1.14"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 }) => {
|
||||
const sessionId = event.cookies.get('session_id');
|
||||
event.locals.user = null;
|
||||
|
||||
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(
|
||||
'cookie',
|
||||
event.cookies
|
||||
|
||||
@@ -2,38 +2,42 @@ import { redirect } from '@sveltejs/kit';
|
||||
import type { PageServerLoad } from './$types';
|
||||
import type { User } from '../../../app';
|
||||
import type { Settings } from '$lib/types';
|
||||
import { env } from '$env/dynamic/public';
|
||||
|
||||
export const load: PageServerLoad = async ({ params, fetch, locals: { user } }) => {
|
||||
if (!user) {
|
||||
redirect(307, '/');
|
||||
}
|
||||
if (!user) {
|
||||
redirect(307, '/');
|
||||
}
|
||||
|
||||
const response = await fetch(`http://hitstar.xyz/api/lobby/${params.id}`, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
if (!env.PUBLIC_API_BASE) redirect(307, '/error');
|
||||
|
||||
if (response.status != 200) {
|
||||
redirect(307, '/');
|
||||
}
|
||||
const u = new URL(`lobby/${params.id}`, env.PUBLIC_API_BASE);
|
||||
const response = await fetch(u, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
const {
|
||||
id,
|
||||
host,
|
||||
players,
|
||||
gameSettings
|
||||
}: { id: string; host: User; players: User[]; gameSettings: Settings } = await response.json();
|
||||
console.log('Successful request for lobby');
|
||||
console.log(id);
|
||||
if (response.status != 200) {
|
||||
redirect(307, '/');
|
||||
}
|
||||
|
||||
return {
|
||||
user: user,
|
||||
lobby: {
|
||||
id,
|
||||
host,
|
||||
players,
|
||||
gameSettings
|
||||
}
|
||||
};
|
||||
const {
|
||||
id,
|
||||
host,
|
||||
players,
|
||||
gameSettings
|
||||
}: { id: string; host: User; players: User[]; gameSettings: Settings } = await response.json();
|
||||
console.log('Successful request for lobby');
|
||||
console.log(id);
|
||||
|
||||
return {
|
||||
user: user,
|
||||
lobby: {
|
||||
id,
|
||||
host,
|
||||
players,
|
||||
gameSettings
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
import PlayerList from '$lib/components/PlayerList.svelte';
|
||||
import GameSettings from '$lib/components/GameSettings.svelte';
|
||||
import type { PageProps } from './$types';
|
||||
import { env } from '$env/dynamic/public';
|
||||
import { goto } from '$app/navigation';
|
||||
|
||||
// Create WebSocket client
|
||||
|
||||
@@ -12,7 +14,7 @@
|
||||
|
||||
let { data }: PageProps = $props();
|
||||
|
||||
let lobbyCode = $state(data.lobby.id);
|
||||
let lobbyCode = $state(data.lobby.id);
|
||||
let isHost = $state(data.user.email === data.lobby.host.email); // Assume current user is host for this example
|
||||
|
||||
// Available options for settings
|
||||
@@ -84,8 +86,14 @@
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
wsClient.connect(`ws://hitstar.xyz/api/lobby?id=${lobbyCode}`);
|
||||
wsClient.gameSettings = data.lobby.gameSettings
|
||||
if (!env.PUBLIC_API_WS_BASE) {
|
||||
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(() => {
|
||||
@@ -130,7 +138,11 @@
|
||||
<!-- Left column: Player list -->
|
||||
<div class="md:col-span-1">
|
||||
{#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}
|
||||
<div class="bg-white rounded-lg shadow-sm p-5 flex items-center justify-center">
|
||||
<div class="flex items-center text-amber-600">
|
||||
|
||||
Reference in New Issue
Block a user