]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/redis.ts
Add validator channelName for create-user api
[github/Chocobozzz/PeerTube.git] / server / lib / redis.ts
index b4cd6f8e7e0afe75189f775d7433519ee931a242..5313c46857a95254df77cc2d4717e763a803db3d 100644 (file)
@@ -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'
 
@@ -121,6 +122,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 +224,10 @@ class Redis {
     return `views-${videoUUID}-${ip}`
   }
 
+  private generateTrackerBlockIPKey (ip: string) {
+    return `tracker-block-ip-${ip}`
+  }
+
   private generateContactFormKey (ip: string) {
     return 'contact-form-' + ip
   }