diff options
Diffstat (limited to 'server/lib/redis.ts')
-rw-r--r-- | server/lib/redis.ts | 24 |
1 files changed, 22 insertions, 2 deletions
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' | |||
2 | import { createClient, RedisClient } from 'redis' | 2 | import { createClient, RedisClient } from 'redis' |
3 | import { logger } from '../helpers/logger' | 3 | import { logger } from '../helpers/logger' |
4 | import { generateRandomString } from '../helpers/utils' | 4 | import { generateRandomString } from '../helpers/utils' |
5 | import { CONFIG, USER_PASSWORD_RESET_LIFETIME, USER_EMAIL_VERIFY_LIFETIME, VIDEO_VIEW_LIFETIME } from '../initializers' | 5 | import { |
6 | CONFIG, | ||
7 | CONTACT_FORM_LIFETIME, | ||
8 | USER_EMAIL_VERIFY_LIFETIME, | ||
9 | USER_PASSWORD_RESET_LIFETIME, | ||
10 | VIDEO_VIEW_LIFETIME | ||
11 | } from '../initializers' | ||
6 | 12 | ||
7 | type CachedRoute = { | 13 | type CachedRoute = { |
8 | body: string, | 14 | body: string, |
@@ -76,6 +82,16 @@ class Redis { | |||
76 | return this.getValue(this.generateVerifyEmailKey(userId)) | 82 | return this.getValue(this.generateVerifyEmailKey(userId)) |
77 | } | 83 | } |
78 | 84 | ||
85 | /************* Contact form per IP *************/ | ||
86 | |||
87 | async setContactFormIp (ip: string) { | ||
88 | return this.setValue(this.generateContactFormKey(ip), '1', CONTACT_FORM_LIFETIME) | ||
89 | } | ||
90 | |||
91 | async isContactFormIpExists (ip: string) { | ||
92 | return this.exists(this.generateContactFormKey(ip)) | ||
93 | } | ||
94 | |||
79 | /************* Views per IP *************/ | 95 | /************* Views per IP *************/ |
80 | 96 | ||
81 | setIPVideoView (ip: string, videoUUID: string) { | 97 | setIPVideoView (ip: string, videoUUID: string) { |
@@ -175,7 +191,11 @@ class Redis { | |||
175 | } | 191 | } |
176 | 192 | ||
177 | private generateViewKey (ip: string, videoUUID: string) { | 193 | private generateViewKey (ip: string, videoUUID: string) { |
178 | return videoUUID + '-' + ip | 194 | return `views-${videoUUID}-${ip}` |
195 | } | ||
196 | |||
197 | private generateContactFormKey (ip: string) { | ||
198 | return 'contact-form-' + ip | ||
179 | } | 199 | } |
180 | 200 | ||
181 | /************* Redis helpers *************/ | 201 | /************* Redis helpers *************/ |