From 6040f87d143a5fa01db79867ece8197c3ce7be47 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 4 Dec 2018 16:02:49 +0100 Subject: Add tmp and redundancy directories --- server/lib/redis.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'server/lib/redis.ts') diff --git a/server/lib/redis.ts b/server/lib/redis.ts index abd75d512..3e25e6a2c 100644 --- a/server/lib/redis.ts +++ b/server/lib/redis.ts @@ -121,7 +121,14 @@ class Redis { const key = this.generateVideoViewKey(videoId, hour) const valueString = await this.getValue(key) - return parseInt(valueString, 10) + const valueInt = parseInt(valueString, 10) + + if (isNaN(valueInt)) { + logger.error('Cannot get videos views of video %d in hour %d: views number is NaN (%s).', videoId, hour, valueString) + return undefined + } + + return valueInt } async getVideosIdViewed (hour: number) { -- cgit v1.2.3 From a4101923e699e49ceb9ff36e971c75417fafc9f0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 9 Jan 2019 15:14:29 +0100 Subject: Implement contact form on server side --- server/lib/redis.ts | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'server/lib/redis.ts') 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 *************/ -- cgit v1.2.3