Started on the database

This commit is contained in:
Eclypsed
2024-01-23 01:21:41 -05:00
parent fd489b055c
commit 830ab55023
9 changed files with 528 additions and 37 deletions

0
src/lib/server/users.db Normal file
View File

26
src/lib/server/users.ts Normal file
View File

@@ -0,0 +1,26 @@
import Database from 'better-sqlite3'
import Services from '$lib/services.json'
import { generateUUID } from '$lib/utils'
const db = new Database('./src/lib/server/users.db', { verbose: console.info })
db.pragma('foreign_keys = ON')
const initUsersTable = 'CREATE TABLE IF NOT EXISTS Users(id VARCHAR(36) PRIMARY KEY, username VARCHAR(30) UNIQUE NOT NULL, password VARCHAR(72) NOT NULL)'
db.exec(initUsersTable)
export interface User {
id: string
username: string
password: string
}
export class Users {
static addUser = (username: string, hashedPassword: string): User => {
const userId = generateUUID()
db.prepare('INSERT INTO Users(id, username, password) VALUES(?, ?, ?)').run(userId, username, hashedPassword)
return this.getUser(userId)
}
static getUser = (id: string): User => {
return db.prepare('SELECT * FROM Users WHERE id = ?').get(id) as User
}
}

14
src/lib/services.json Normal file
View File

@@ -0,0 +1,14 @@
{
"jellyfin": {
"displayName": "Jellyfin",
"type": ["streaming"],
"icon": "https://raw.githubusercontent.com/jellyfin/jellyfin-ux/55616553b692b1a6c7d8e786eeb7d8216e9b50df/branding/SVG/icon-transparent.svg",
"primaryColor": "--jellyfin-blue"
},
"youtube-music": {
"displayName": "YouTube Music",
"type": ["streaming"],
"icon": "https://upload.wikimedia.org/wikipedia/commons/6/6a/Youtube_Music_icon.svg",
"primaryColor": "--youtube-red"
}
}

3
src/lib/utils.ts Normal file
View File

@@ -0,0 +1,3 @@
export const generateUUID = (): string => {
return '10000000-1000-4000-8000-100000000000'.replace(/[018]/g, (c: any) => (c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16))
}