From 42a7b4758fa8a6a2c7e6f4d23e385430840176ba Mon Sep 17 00:00:00 2001 From: tycrek Date: Wed, 30 Nov 2022 14:15:23 -0700 Subject: [PATCH] chore: rename this to improve understanding --- src/auth.ts | 2 +- src/routers/upload.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/auth.ts b/src/auth.ts index 80560e3..10b9d62 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -142,7 +142,7 @@ export const findFromToken = (token: string) => { /** * Verifies that the upload token in the request exists in the user map */ -export const verify = (req: Request) => { +export const verifyValidToken = (req: Request) => { return req.headers.authorization && findFromToken(req.headers.authorization); }; diff --git a/src/routers/upload.ts b/src/routers/upload.ts index 904d90e..01632d6 100644 --- a/src/routers/upload.ts +++ b/src/routers/upload.ts @@ -9,7 +9,7 @@ import { Webhook, MessageBuilder } from 'discord-webhook-node'; import { processUploaded } from '../storage'; import { path, log, getTrueHttp, getTrueDomain, generateId, formatBytes } from '../utils'; import { data } from '../data'; -import { findFromToken, verify } from '../auth'; +import { findFromToken, verifyValidToken } from '../auth'; const { maxUploadSize, resourceIdSize, gfyIdSize, resourceIdType, spaceReplace, adminWebhookEnabled, adminWebhookUrl, adminWebhookUsername, adminWebhookAvatar }: Config = fs.readJsonSync(path('config.json')); const { CODE_UNAUTHORIZED, CODE_PAYLOAD_TOO_LARGE }: MagicNumbers = fs.readJsonSync(path('MagicNumbers.json')); @@ -35,7 +35,7 @@ bb.extend(router, { router.post('/', (req: Request, res: Response, next: Function) => { req.headers.authorization = req.headers.authorization || ''; req.token = req.headers.authorization.replace(/[^\da-z]/gi, ''); // Strip anything that isn't a digit or ASCII letter - !verify(req) ? log.warn('Upload blocked', 'Unauthorized').callback(() => res.sendStatus(CODE_UNAUTHORIZED)) : next(); // skipcq: JS-0093 + !verifyValidToken(req) ? log.warn('Upload blocked', 'Unauthorized').callback(() => res.sendStatus(CODE_UNAUTHORIZED)) : next(); // skipcq: JS-0093 }); // Upload file