Skip to content

Commit

Permalink
semi-functional ui
Browse files Browse the repository at this point in the history
  • Loading branch information
hans-m-song committed May 6, 2024
1 parent 4faab09 commit 95b4c3e
Show file tree
Hide file tree
Showing 38 changed files with 2,708 additions and 2,315 deletions.
3,272 changes: 1,654 additions & 1,618 deletions package-lock.json

Large diffs are not rendered by default.

23 changes: 14 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
"start": "node dist/index.js",
"debug": "nodemon",
"lint": "eslint \"src/**/*.ts\"",
"lint:fix": "prettier --write ./src && yarn lint --fix"
"lint:fix": "prettier --write ./src && yarn lint --fix",
"test": "jest",
"schema:mermaid": "atlas schema inspect --url sqlite://local.db --format '```mermaid{{ printf \"\\n\" }}{{ mermaid . }}```' > schema.md",
"schema:diff": "atlas schema diff --from sqlite://local.db --to file://schema.hcl --dev-url 'sqlite://dev?mode=memory'",
"schema:apply": "atlas schema apply --url sqlite://local.db --to file://schema.hcl"
},
"dependencies": {
"@discordjs/opus": "^0.8.0",
Expand All @@ -37,20 +41,21 @@
"ts-pattern": "^4.0.1",
"typescript": "^4.9.5",
"utf-8-validate": "^5.0.10",
"zlib-sync": "^0.1.9"
"zlib-sync": "^0.1.9",
"zod": "^3.23.6"
},
"devDependencies": {
"@types/newrelic": "^9.14.3",
"@types/node": "^17.0.23",
"@typescript-eslint/eslint-plugin": "^5.18.0",
"@typescript-eslint/parser": "^5.18.0",
"eslint": "^8.12.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.2.1",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.3",
"nodemon": "^2.0.15",
"pino-pretty": "^11.0.0",
"prettier": "^2.7.1",
"prettier": "3.2.5",
"ts-node": "^10.7.0",
"tsx": "^3.14.0"
}
Expand Down
131 changes: 131 additions & 0 deletions schema.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
schema "main" {
}

table "song" {
schema = schema.main

column "songId" {
type = text
null = false
}

column "songTitle" {
type = text
null = false
}

column "songUrl" {
type = text
null = false
}

column "artistId" {
type = text
null = true
}

column "artistTitle" {
type = text
null = true
}

column "artistUrl" {
type = text
null = true
}

column "thumbnail" {
type = text
null = true
}

column "duration" {
type = integer
null = true
}

column "cachedAt" {
type = integer
null = false
default = "(strftime('%s', 'now'))"
}

primary_key {
columns = [column.songId]
}
}

table "queue" {
schema = schema.main

column "channelId" {
type = text
null = false
}

column "sortOrder" {
type = integer
null = false
}

column "songId" {
type = text
null = false
}

column "played" {
type = boolean
null = false
default = false
}

primary_key {
columns = [column.channelId, column.sortOrder]
}

foreign_key "songId" {
columns = [column.songId]
ref_columns = [table.song.column.songId]
on_update = CASCADE
on_delete = CASCADE
}
}

table "query" {
schema = schema.main

column "queryId" {
type = integer
null = false
auto_increment = true
}

column "query" {
type = text
null = false
}

column "songId" {
type = text
null = false
}

column "hits" {
type = integer
null = false
default = 1
}

primary_key {
columns = [column.queryId]
}

index "index_query" {
columns = [column.query]
unique = true
}

check "query_length" {
expr = "length(query) > 0"
}
}
29 changes: 16 additions & 13 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { FastifyReply, FastifyRequest } from 'fastify';
import pino from 'pino';

import { assertEnv, boolEnv, enumEnv, numEnv, obscure, serialiseError } from './lib/utils';
Expand All @@ -20,25 +21,20 @@ export const config = {
youtubeBaseUrl: process.env.YOUTUBE_BASE_URL ?? 'https://www.googleapis.com/youtube/v3',
youtubeApiKey: assertEnv('YOUTUBE_API_KEY'),
youtubeDLExecutable: process.env.YOUTUBE_DL_EXECUTABLE ?? 'yt-dlp',
youtubeDLMaxConcurrency: numEnv(process.env.YOUTUBE_DL_MAX_CONCURRENCY, {
default: 1,
min: 1,
max: 5,
}),
youtubeDLRetries: numEnv(process.env.YOUTUBE_DL_RETRIES, {
default: 3,
min: 1,
max: 5,
}),
youtubeDLMaxConcurrency: numEnv('YOUTUBE_DL_MAX_CONCURRENCY', { default: 1, min: 1, max: 5 }),
youtubeDLRetries: numEnv('YOUTUBE_DL_RETRIES', { default: 1, min: 1, max: 5 }),

// minio
// Minio
minioEndpoint: process.env.MINIO_ENDPOINT ?? 'api.minio.axatol.xyz',
minioEndpointPort: numEnv(process.env.MINIO_ENDPOINT_PORT, { default: 443 }),
minioEndpointSSL: boolEnv(process.env.MINIO_ENDPOINT_SSL, true),
minioEndpointPort: numEnv('MINIO_ENDPOINT_PORT', { default: 443 }),
minioEndpointSSL: boolEnv('MINIO_ENDPOINT_SSL', true),
minioBucketName: process.env.MINIO_BUCKET_NAME ?? 'huisheng',
minioAccessKey: assertEnv('MINIO_ACCESS_KEY'),
minioSecretKey: assertEnv('MINIO_SECRET_KEY'),

// Web
webPort: numEnv('WEB_PORT', { default: 8000 }),

// Spotify
spotifyBaseUrl: process.env.SPOTIFY_BASE_URL ?? 'https://api.spotify.com/v1',
spotifyClientId: process.env.SPOTIFY_CLIENT_ID,
Expand All @@ -55,6 +51,13 @@ export const log = pino({
serializers: {
error: serialiseError,
err: serialiseError,
req: (req: FastifyRequest) => ({
method: req.method,
url: req.url,
hostname: req.hostname,
htmx: req.headers['hx-request'] === 'true',
body: req.body,
}),
},
redact: {
paths: [
Expand Down
14 changes: 5 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,20 @@ import { Bot } from './Bot';
import { config, log } from './config';
import { dependencyReport } from './lib/audio';
import { Bucket } from './lib/Bucket';
import { Cache } from './lib/Cache';
import { server } from './server/server';

(async () => {
log.info({ event: 'init', report: dependencyReport() });

const bot = new Bot();
await Promise.all([
fs.mkdir(config.cacheDir, { recursive: true }),
Cache.migrate(),
Bucket.ping(),
bot.login(),
]);
await Promise.all([fs.mkdir(config.cacheDir, { recursive: true }), Bucket.ping(), bot.login()]);
server.listen({ port: config.webPort });

await new Promise<void>((resolve) => {
['SIGINT', 'SIGTERM'].forEach((code) => {
process.on(code, async (exitCode) => {
log.info({ event: 'Bot.shutdown', message: 'client shutting down', exitCode });
await bot.shutdown();
log.info({ event: 'shutdown', message: 'client shutting down', exitCode });
await Promise.all([bot.shutdown(), server.close()]);
resolve();
});
});
Expand Down
Loading

0 comments on commit 95b4c3e

Please sign in to comment.