mirror of
https://github.com/koreanbots/core.git
synced 2025-12-16 06:20:24 +00:00
feat: added auth function
This commit is contained in:
parent
728b0fc30b
commit
2a98be6bbb
@ -222,6 +222,13 @@ async function assignToken(info: TokenRegister):Promise<string> {
|
|||||||
return t
|
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<unknown, number>) {
|
async function addRequest(ip: string, map: TLRU<unknown, number>) {
|
||||||
if(!map.has(ip)) map.set(ip, 0)
|
if(!map.has(ip)) map.set(ip, 0)
|
||||||
map.set(ip, map.get(ip) + 1)
|
map.set(ip, map.get(ip) + 1)
|
||||||
@ -269,7 +276,8 @@ export const get = {
|
|||||||
async (urls: string[]) =>
|
async (urls: string[]) =>
|
||||||
(await Promise.all(urls.map(async (url: string) => await getImage(url))))
|
(await Promise.all(urls.map(async (url: string) => await getImage(url))))
|
||||||
, { cacheMap: new TLRU({ maxStoreSize: 500, maxAgeMs: 3600000 }) }),
|
, { cacheMap: new TLRU({ maxStoreSize: 500, maxAgeMs: 3600000 }) }),
|
||||||
}
|
},
|
||||||
|
Authorization
|
||||||
}
|
}
|
||||||
|
|
||||||
export const update = {
|
export const update = {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user