Channel listing without db

This commit is contained in:
shockrah 2025-04-24 20:45:56 -07:00
parent 836beda422
commit 0ea65a665d
6 changed files with 1302 additions and 5 deletions

1238
api/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,13 @@
{ {
"dependencies": { "dependencies": {
"@types/express": "^5.0.0",
"@types/node": "^22.13.10",
"express": "^4.21.2",
"node": "^23.9.0", "node": "^23.9.0",
"npm": "^11.2.0" "npm": "^11.2.0",
"pg-promise": "^11.13.0",
"ts-node": "^10.9.2",
"tslib": "^2.8.1"
}, },
"name": "api", "name": "api",
"version": "1.0.0", "version": "1.0.0",

30
api/src/channels.ts Normal file
View File

@ -0,0 +1,30 @@
import { Request, Response } from 'express'
import {values_present} from './common'
export enum Type {
Text = 'text',
Voice = 'voice',
}
function valid_channel(ch: string) : boolean {
return ch === Type.Text || ch === Type.Voice
}
export async function list(req: Request, res: Response, db) : Promise<void> {
const channels = await db.one('SELECT * from channels')
res.send({path: req.path, data: channels.value})
}
export async function create(req: Request, res: Response) : Promise<void> {
const { name, description, type } = req.query
if (values_present([name, description, type])|| !valid_channel(type.toString()) ) {
res.status(400).send({ error: 'Invalid query string params' })
return
}
res.send({
id: 123,
name: name,
description: description,
type: type
})
}

5
api/src/invites.ts Normal file
View File

@ -0,0 +1,5 @@
import { Request, Response } from 'express'
export async function code(req: Request, res: Response) : Promise<void> {
res.send({path: req.path})
}

View File

@ -1 +1,22 @@
console.log('asdf') import process from 'process'
import express from 'express'
import * as channels from './channels'
import * as invites from './invites'
const pgPromise = require('pg-promise')()
const DB_URL = process.env['DB_CONNECTION_STRING']
const PORT = process.env['PORT'] || 8000
console.log('db-url', DB_URL)
console.log('port', PORT)
const app = express()
const db = pgPromise(DB_URL)
app.get('/invite/<code>', async (req, res) => await invites.code(req, res))
app.get('/channels/list', async (req, res) => await channels.list(req, res, db))
app.post('/channels/create', async (req, res) => await channels.create(req, res))
app.listen(PORT)

1
dev.py
View File

@ -40,6 +40,7 @@ if __name__ == '__main__':
if args.check_container: if args.check_container:
run(f'docker exec -it {args.check_container} bash'.split()) run(f'docker exec -it {args.check_container} bash'.split())
if args.server: if args.server:
run('npm run build', env=os.environ, cwd='api', shell=True)
run( run(
f'npm run debug', f'npm run debug',
env=os.environ, env=os.environ,