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,
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) {
}
private generateViewKey (ip: string, videoUUID: string) {
- return videoUUID + '-' + ip
+ return `views-${videoUUID}-${ip}`
+ }
+
+ private generateContactFormKey (ip: string) {
+ return 'contact-form-' + ip
}
/************* Redis helpers *************/