From 07d767a4ae9ff560a3c1c4bb2413916c4dba1d6c Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Sat, 26 Mar 2022 15:35:47 +0200 Subject: [PATCH] compression middleware --- server/package.json | 1 + server/src/client/ClipIndex.js | 2 +- server/src/client/ServerClient.js | 5 ++++ server/src/client/endpoints/api/Upload.js | 2 +- server/yarn.lock | 34 +++++++++++++++++++++-- 5 files changed, 40 insertions(+), 4 deletions(-) diff --git a/server/package.json b/server/package.json index caa9568..2478d28 100644 --- a/server/package.json +++ b/server/package.json @@ -13,6 +13,7 @@ "dependencies": { "@navy.gif/passport-discord": "^0.2.2-b", "chalk": "^4.0.0", + "compression": "^1.7.4", "connect-mongo": "^4.6.0", "cookie-parser": "^1.4.6", "cors": "^2.8.5", diff --git a/server/src/client/ClipIndex.js b/server/src/client/ClipIndex.js index 25ebf4d..955b255 100644 --- a/server/src/client/ClipIndex.js +++ b/server/src/client/ClipIndex.js @@ -59,7 +59,7 @@ class ClipIndex extends EventEmitter { duration, uploader: { id: uploader.id, - tag: `${uploader.username}#${uploader.discriminator}` + tag: uploader.tag } }; diff --git a/server/src/client/ServerClient.js b/server/src/client/ServerClient.js index d4c49e8..459b97c 100644 --- a/server/src/client/ServerClient.js +++ b/server/src/client/ServerClient.js @@ -12,6 +12,7 @@ const { Strategy: DiscordStrategy } = require('@navy.gif/passport-discord'); const helmet = require('helmet'); const cors = require('cors'); const cookieParser = require('cookie-parser'); +const compression = require('compression'); const { Logger } = require('../util'); const Intercom = require('./Intercom'); @@ -77,6 +78,10 @@ class Client extends EventEmitter { next(); }); + this.app.use(compression({ + + })); + // Shouldn't be necessary, everything should come from the same domain: galactic.corgi.wtf this.app.use(cors({ origin: (origin, cb) => { diff --git a/server/src/client/endpoints/api/Upload.js b/server/src/client/endpoints/api/Upload.js index bd8b813..86f09e4 100644 --- a/server/src/client/endpoints/api/Upload.js +++ b/server/src/client/endpoints/api/Upload.js @@ -35,7 +35,7 @@ class Login extends APIEndpoint { return res.status(400).send('Invalid format'); } - this.logger.info(`${req.user.username}#${req.user.discriminator} is uploading ${name}`); + this.logger.info(`${req.user.tag} is uploading ${name}`); try { const result = await this.client.clipIndex.add(file, name, req.user); res.status(200).json({ diff --git a/server/yarn.lock b/server/yarn.lock index dcd821d..a0144ce 100644 --- a/server/yarn.lock +++ b/server/yarn.lock @@ -209,7 +209,7 @@ dependencies: "@types/node" "*" -accepts@~1.3.8: +accepts@~1.3.5, accepts@~1.3.8: version "1.3.8" resolved "https://registry.yarnpkg.com/accepts/-/accepts-1.3.8.tgz#0bf0be125b67014adcb0b0921e62db7bffe16b2e" integrity sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw== @@ -386,6 +386,11 @@ busboy@^0.3.1: dependencies: dicer "0.3.0" +bytes@3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.0.0.tgz#d32815404d689699f85a4ea4fa8755dd13a96048" + integrity sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg= + bytes@3.1.2: version "3.1.2" resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.2.tgz#8b0beeb98605adf1b128fa4386403c009e0221a5" @@ -444,6 +449,26 @@ combined-stream@^1.0.8: dependencies: delayed-stream "~1.0.0" +compressible@~2.0.16: + version "2.0.18" + resolved "https://registry.yarnpkg.com/compressible/-/compressible-2.0.18.tgz#af53cca6b070d4c3c0750fbd77286a6d7cc46fba" + integrity sha512-AF3r7P5dWxL8MxyITRMlORQNaOA2IkAFaTr4k7BUumjPtRpGDTZpl0Pb1XCO6JeDCBdp126Cgs9sMxqSjgYyRg== + dependencies: + mime-db ">= 1.43.0 < 2" + +compression@^1.7.4: + version "1.7.4" + resolved "https://registry.yarnpkg.com/compression/-/compression-1.7.4.tgz#95523eff170ca57c29a0ca41e6fe131f41e5bb8f" + integrity sha512-jaSIDzP9pZVS4ZfQ+TzvtiWhdpFhE2RDHz8QJkpX9SIpLq88VueF5jJw6t+6CUQcAoA6t+x89MLrWAqpfDE8iQ== + dependencies: + accepts "~1.3.5" + bytes "3.0.0" + compressible "~2.0.16" + debug "2.6.9" + on-headers "~1.0.2" + safe-buffer "5.1.2" + vary "~1.1.2" + concat-map@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" @@ -1140,7 +1165,7 @@ methods@~1.1.2: resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee" integrity sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4= -mime-db@1.52.0: +mime-db@1.52.0, "mime-db@>= 1.43.0 < 2": version "1.52.0" resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70" integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg== @@ -1407,6 +1432,11 @@ rimraf@^3.0.2: dependencies: glob "^7.1.3" +safe-buffer@5.1.2: + version "5.1.2" + resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d" + integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g== + safe-buffer@5.2.1: version "5.2.1" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6"