X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=server%2Flib%2Fredis.ts;h=3628c0583e3006dc91f30ba60fb076285cfe5fa1;hb=a4101923e699e49ceb9ff36e971c75417fafc9f0;hp=3e25e6a2c278987d9629cd3cee36bf5c36621d38;hpb=6040f87d143a5fa01db79867ece8197c3ce7be47;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/redis.ts b/server/lib/redis.ts index 3e25e6a2c..3628c0583 100644 --- a/server/lib/redis.ts +++ b/server/lib/redis.ts @@ -2,7 +2,13 @@ import * as express from 'express' import { createClient, RedisClient } from 'redis' import { logger } from '../helpers/logger' import { generateRandomString } from '../helpers/utils' -import { CONFIG, USER_PASSWORD_RESET_LIFETIME, USER_EMAIL_VERIFY_LIFETIME, VIDEO_VIEW_LIFETIME } from '../initializers' +import { + CONFIG, + CONTACT_FORM_LIFETIME, + USER_EMAIL_VERIFY_LIFETIME, + USER_PASSWORD_RESET_LIFETIME, + VIDEO_VIEW_LIFETIME +} from '../initializers' type CachedRoute = { body: string, @@ -76,6 +82,16 @@ class Redis { return this.getValue(this.generateVerifyEmailKey(userId)) } + /************* Contact form per IP *************/ + + async setContactFormIp (ip: string) { + return this.setValue(this.generateContactFormKey(ip), '1', CONTACT_FORM_LIFETIME) + } + + async isContactFormIpExists (ip: string) { + return this.exists(this.generateContactFormKey(ip)) + } + /************* Views per IP *************/ setIPVideoView (ip: string, videoUUID: string) { @@ -175,7 +191,11 @@ class Redis { } private generateViewKey (ip: string, videoUUID: string) { - return videoUUID + '-' + ip + return `views-${videoUUID}-${ip}` + } + + private generateContactFormKey (ip: string) { + return 'contact-form-' + ip } /************* Redis helpers *************/