Skip to content

Commit 88c84dd

Browse files
committed
Update server.ts
1 parent 942f702 commit 88c84dd

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/http/server.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,17 @@ export class Server extends EventEmitter {
2828
res.writeHead(200, { 'Content-Type': 'application/json' });
2929
if(!req.params.type) return res.end('{ status: 400, response: \'Missing param \"type"\' }');
3030
if(req.params.type !== 'ships' && req.params.type !== 'equipments' && req.params.type !== 'chapters' && req.params.type !== 'voicelines' && req.params.type !== 'barrages') return res.end('{ status: 400, response: \'Invalid value for param \"type"\' }');
31+
// eslint-disable-next-line brace-style, @typescript-eslint/brace-style
32+
if (req.params.method === 'raw') return res.end(`{ status: 200, response: ${JSON.stringify(this.client[`${req.params.type}`].raw).replace(/[\u007F-\uFFFF]/g, (chr) => { return `\\u${('0000' + chr.charCodeAt(0).toString(16)).substr(-4)}`; })}`);
3133
if(!req.params.method) return res.end('{ status: 400, response: \'Missing param \"method\"\' }');
3234
const q = req.params.q ? req.params.q : '';
33-
const fn = this.client[`${req.params.type}`][`${req.params.method}`](`${q}`);
34-
// eslint-disable-next-line brace-style, @typescript-eslint/brace-style
35-
if(fn) return res.end(`{ status: 200, response: ${JSON.stringify(fn).replace(/[\u007F-\uFFFF]/g, (chr) => { return `\\u${('0000' + chr.charCodeAt(0).toString(16)).substr(-4)}`; })}`);
36-
res.end('{ status: 400, response: \'Not a function or missing param \"q\"\' }');
35+
try {
36+
const fn = this.client[`${req.params.type}`][`${req.params.method}`](`${q}`);
37+
// eslint-disable-next-line brace-style, @typescript-eslint/brace-style
38+
return res.end(`{ status: 200, response: ${JSON.stringify(fn).replace(/[\u007F-\uFFFF]/g, (chr) => { return `\\u${('0000' + chr.charCodeAt(0).toString(16)).substr(-4)}`; })}`);
39+
} catch {
40+
res.end('{ status: 400, response: \'Not a function or missing param \"q\"\' }');
41+
}
3742
});
3843

3944
dispatcher.onError((req, res) => {

0 commit comments

Comments
 (0)