X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fredis.ts;h=a075eee2d900e9765f96d04578e2a167ecb90db4;hb=284ef529113ad61de30ff30a28c699b97d9ca02f;hp=b4cd6f8e7e0afe75189f775d7433519ee931a242;hpb=2ad9dcda240ee843c5e4a5b98cc94f7b2aab2c89;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/redis.ts b/server/lib/redis.ts index b4cd6f8e7..a075eee2d 100644 --- a/server/lib/redis.ts +++ b/server/lib/redis.ts @@ -8,7 +8,8 @@ import { USER_PASSWORD_RESET_LIFETIME, USER_PASSWORD_CREATE_LIFETIME, VIDEO_VIEW_LIFETIME, - WEBSERVER + WEBSERVER, + TRACKER_RATE_LIMITS } from '../initializers/constants' import { CONFIG } from '../initializers/config' @@ -83,6 +84,10 @@ class Redis { return generatedString } + async removePasswordVerificationString (userId: number) { + return this.removeValue(this.generateResetPasswordKey(userId)) + } + async getResetPasswordLink (userId: number) { return this.getValue(this.generateResetPasswordKey(userId)) } @@ -121,6 +126,16 @@ class Redis { return this.exists(this.generateViewKey(ip, videoUUID)) } + /* ************ Tracker IP block ************ */ + + setTrackerBlockIP (ip: string) { + return this.setValue(this.generateTrackerBlockIPKey(ip), '1', TRACKER_RATE_LIMITS.BLOCK_IP_LIFETIME) + } + + async doesTrackerBlockIPExist (ip: string) { + return this.exists(this.generateTrackerBlockIPKey(ip)) + } + /* ************ API cache ************ */ async getCachedRoute (req: express.Request) { @@ -213,6 +228,10 @@ class Redis { return `views-${videoUUID}-${ip}` } + private generateTrackerBlockIPKey (ip: string) { + return `tracker-block-ip-${ip}` + } + private generateContactFormKey (ip: string) { return 'contact-form-' + ip } @@ -275,6 +294,16 @@ class Redis { }) } + private removeValue (key: string) { + return new Promise((res, rej) => { + this.client.del(this.prefix + key, err => { + if (err) return rej(err) + + return res() + }) + }) + } + private setObject (key: string, obj: { [id: string]: string }, expirationMilliseconds: number) { return new Promise((res, rej) => { this.client.hmset(this.prefix + key, obj, (err, ok) => {