USER_EMAIL_VERIFY_LIFETIME,
USER_PASSWORD_RESET_LIFETIME,
USER_PASSWORD_CREATE_LIFETIME,
- VIDEO_VIEW_LIFETIME,
+ VIEW_LIFETIME,
WEBSERVER,
TRACKER_RATE_LIMITS
} from '../initializers/constants'
/* ************ 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) {
}
private generateVideoViewKey (videoId: number, hour?: number) {
- if (!hour) hour = new Date().getHours()
+ if (hour === undefined || hour === null) hour = new Date().getHours()
return `video-view-${videoId}-h${hour}`
}
}
private addToSet (key: string, value: string) {
- return new Promise<string[]>((res, rej) => {
+ return new Promise<void>((res, rej) => {
this.client.sadd(this.prefix + key, value, err => err ? rej(err) : res())
})
}