]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/redis.ts
Remove notifications of muted accounts/servers
[github/Chocobozzz/PeerTube.git] / server / lib / redis.ts
index 5313c46857a95254df77cc2d4717e763a803db3d..4325598b2f3df6c2cf35adfcfb1ff3447c08ab9a 100644 (file)
@@ -7,7 +7,7 @@ import {
   USER_EMAIL_VERIFY_LIFETIME,
   USER_PASSWORD_RESET_LIFETIME,
   USER_PASSWORD_CREATE_LIFETIME,
-  VIDEO_VIEW_LIFETIME,
+  VIEW_LIFETIME,
   WEBSERVER,
   TRACKER_RATE_LIMITS
 } from '../initializers/constants'
@@ -84,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))
   }
@@ -114,8 +118,12 @@ class Redis {
 
   /* ************ Views per IP ************ */
 
-  setIPVideoView (ip: string, videoUUID: string) {
-    return this.setValue(this.generateViewKey(ip, videoUUID), '1', VIDEO_VIEW_LIFETIME)
+  setIPVideoView (ip: string, videoUUID: string, isLive: boolean) {
+    const lifetime = isLive
+      ? VIEW_LIFETIME.LIVE
+      : VIEW_LIFETIME.VIDEO
+
+    return this.setValue(this.generateViewKey(ip, videoUUID), '1', lifetime)
   }
 
   async doesVideoIPViewExist (ip: string, videoUUID: string) {
@@ -290,6 +298,16 @@ class Redis {
     })
   }
 
+  private removeValue (key: string) {
+    return new Promise<void>((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<void>((res, rej) => {
       this.client.hmset(this.prefix + key, obj, (err, ok) => {