From 2a98be6bbb7439c6a332dba42f6c5941d6ca8516 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9B=90=EB=8D=94?= Date: Sat, 30 Jan 2021 20:40:42 +0900 Subject: [PATCH] feat: added auth function --- utils/Query.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/utils/Query.ts b/utils/Query.ts index 027f35d..ef7bb5e 100644 --- a/utils/Query.ts +++ b/utils/Query.ts @@ -222,6 +222,13 @@ async function assignToken(info: TokenRegister):Promise { return t } +async function Authorization(token: string) { + const tokenInfo = verify(token) + const user = await knex('users').select(['id']).where({ id: tokenInfo?.id, token }) + if(user.length === 0) return false + else return user[0].id +} + async function addRequest(ip: string, map: TLRU) { if(!map.has(ip)) map.set(ip, 0) map.set(ip, map.get(ip) + 1) @@ -269,7 +276,8 @@ export const get = { async (urls: string[]) => (await Promise.all(urls.map(async (url: string) => await getImage(url)))) , { cacheMap: new TLRU({ maxStoreSize: 500, maxAgeMs: 3600000 }) }), - } + }, + Authorization } export const update = {