diff --git a/d.ts/src/helpers/socket.d.ts b/d.ts/src/helpers/socket.d.ts index e89e84be053..129a74f4072 100644 --- a/d.ts/src/helpers/socket.d.ts +++ b/d.ts/src/helpers/socket.d.ts @@ -148,11 +148,6 @@ export type ClientToServerEventsWithNamespace = { 'alert': (data: any) => void, 'cache': (cacheLimit: number, cb: (err: Error | string | null | unknown, data: any) => void) => void, }, - '/overlays/chat': GenericEvents & { - 'test': (data: { message: string; username: string }) => void, - 'timeout': (userName: string) => void, - 'message': (data: { id: string, show: boolean; message: string; username: string, timestamp: number, badges: any }) => void, - }, '/overlays/texttospeech': GenericEvents & { 'speak': (data: { text: string; highlight: boolean, key: string }) => void, }, diff --git a/src/overlays/chat.ts b/src/overlays/chat.ts index 001536daabd..8eafdd57d99 100644 --- a/src/overlays/chat.ts +++ b/src/overlays/chat.ts @@ -1,5 +1,3 @@ -import { randomUUID } from 'node:crypto'; - import Overlay from './_interface.js'; import { badgesCache } from '../services/twitch/calls/getChannelChatBadges.js'; @@ -7,7 +5,6 @@ import { onMessage } from '~/decorators/on.js'; import { timer } from '~/decorators.js'; import { ioServer } from '~/helpers/panel.js'; import { parseTextWithEmotes } from '~/helpers/parseTextWithEmotes.js'; -import { adminEndpoint } from '~/helpers/socket.js'; export const getBadgeImagesFromBadgeSet = (badgesMap: Map) => { const badgeImages: {url: string }[] = []; @@ -50,22 +47,6 @@ class Chat extends Overlay { }); }); } - - sockets() { - adminEndpoint('/overlays/chat', 'test', (data) => { - this.withEmotes(data.message).then(message => { - ioServer?.of('/overlays/chat').emit('message', { - id: randomUUID(), - timestamp: Date.now(), - displayName: data.username, - userName: data.username, - message, - show: false, - badges: [], - }); - }); - }); - } } export default new Chat(); diff --git a/src/registries/randomizer.ts b/src/registries/randomizer.ts index 88a31662249..64c0a0b2377 100644 --- a/src/registries/randomizer.ts +++ b/src/registries/randomizer.ts @@ -1,13 +1,13 @@ import { Randomizer as RandomizerEntity } from '@entity/randomizer.js'; +import { Request } from 'express'; import Registry from './_interface.js'; import { parser } from '../decorators.js'; import { AppDataSource } from '~/database.js'; +import { Delete, Get, Post } from '~/decorators/endpoint.js'; import { LOW } from '~/helpers/constants.js'; -import { app } from '~/helpers/panel.js'; import { check } from '~/helpers/permissions/check.js'; -import { withScope } from '~/helpers/socket.js'; class Randomizer extends Registry { constructor() { @@ -17,56 +17,50 @@ class Randomizer extends Registry { }); } - sockets () { - if (!app) { - setTimeout(() => this.sockets(), 100); - return; - } + @Get('/') + async getAll () { + return RandomizerEntity.find(); + } - app.get('/api/registries/randomizer', withScope(['randomizer:read']), async (req, res) => { - res.send({ - data: await RandomizerEntity.find(), - }); - }); - app.get('/api/registries/randomizer/visible', async (req, res) => { - res.send({ - data: await RandomizerEntity.findOneBy({ isShown: true }), - }); - }); - app.get('/api/registries/randomizer/:id', withScope(['randomizer:read']), async (req, res) => { - res.send({ - data: await RandomizerEntity.findOneBy({ id: req.params.id }), - }); - }); - app.post('/api/registries/randomizer/hide', withScope(['randomizer:manage']), async (req, res) => { - await AppDataSource.getRepository(RandomizerEntity).update({}, { isShown: false }); - res.status(204).send(); - }); - app.post('/api/registries/randomizer/:id/show', withScope(['randomizer:manage']), async (req, res) => { - await AppDataSource.getRepository(RandomizerEntity).update({}, { isShown: false }); - await AppDataSource.getRepository(RandomizerEntity).update({ id: String(req.params.id) }, { isShown: true }); - res.status(204).send(); - }); - app.post('/api/registries/randomizer/:id/spin', withScope(['randomizer:manage']), async (req, res) => { - const { generateAndAddSecureKey } = await import ('../tts.js'); - this.socket?.emit('spin', { - key: generateAndAddSecureKey(), - }); - res.status(204).send(); - }); - app.delete('/api/registries/randomizer/:id', withScope(['randomizer:manage']), async (req, res) => { - await RandomizerEntity.delete({ id: req.params.id }); - res.status(404).send(); - }); - app.post('/api/registries/randomizer', withScope(['randomizer:manage']), async (req, res) => { - try { - res.send({ data: await RandomizerEntity.create(req.body).save() }); - } catch (e) { - res.status(400).send({ errors: e }); - } + @Get('/visible') + async getVisible () { + return RandomizerEntity.findOneBy({ isShown: true }); + } + + @Get('/:id') + async getOne (req: Request) { + return RandomizerEntity.findOneBy({ id: req.params.id }); + } + + @Post('/hide') + async hide () { + await AppDataSource.getRepository(RandomizerEntity).update({}, { isShown: false }); + } + + @Post('/:id/show') + async show (req: Request) { + await AppDataSource.getRepository(RandomizerEntity).update({}, { isShown: false }); + await AppDataSource.getRepository(RandomizerEntity).update({ id: String(req.params.id) }, { isShown: true }); + } + + @Post('/:id/spin') + async spin (req: Request) { + const { generateAndAddSecureKey } = await import ('../tts.js'); + this.socket?.emit('spin', { + key: generateAndAddSecureKey(), }); } + @Delete('/:id') + async delete (req: Request) { + await RandomizerEntity.delete({ id: req.params.id }); + } + + @Post('/') + async create (req: Request) { + return RandomizerEntity.create(req.body).save(); + } + /** * Check if command is in randomizer (priority: low, fireAndForget) *