From 9fdd1ab9d5c6938c894e9df060172361c3782aad Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Thu, 24 Mar 2022 22:38:13 +0200 Subject: [PATCH] hmmm --- server/src/client/endpoints/api/Clips.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/server/src/client/endpoints/api/Clips.js b/server/src/client/endpoints/api/Clips.js index beaf35c..4a11afa 100644 --- a/server/src/client/endpoints/api/Clips.js +++ b/server/src/client/endpoints/api/Clips.js @@ -1,6 +1,7 @@ const { APIEndpoint } = require('../../interfaces'); const fs = require('fs'); const path = require('path'); +const { CheckAuth, Permissions } = require('../../middleware'); class Clips extends APIEndpoint { @@ -17,7 +18,8 @@ class Clips extends APIEndpoint { ]; this.subpaths = [ - ['/:clip', 'get', this.clip.bind(this)] + ['/:clip', 'get', this.clip.bind(this)], + ['/:clip', 'delete', this.clipDelete.bind(this), [CheckAuth, Permissions('admin')]] ]; this.mediaDir = path.join(this.client.baseDirectory, 'media'); @@ -29,14 +31,14 @@ class Clips extends APIEndpoint { async get(req, res) { const index = this.client.clipIndex.clips; - console.log(index); - res.send(index); + res.json(index); } async clip(req, res) { - const { params: { clip }, headers: { range } } = req; + const { params: { clip }, headers: { range, ...rest } } = req; + console.log(rest); const files = fs.readdirSync(path.join(this.client.baseDirectory, 'media')); if (!files.some((file) => file === clip)) return res.status(404).send('Not found'); @@ -64,6 +66,13 @@ class Clips extends APIEndpoint { } + async clipDelete(req, res) { + const { params: { clip }, user } = req; + this.logger.info(`${user.tag} is deleting clip ${clip}`); + if (this.client.clipIndex.delete(clip)) res.status(200).end(); + else res.status(404).end(); + } + } module.exports = Clips; \ No newline at end of file