+ async getLocalVideoViews (videoId: number) {
+ const { videoKey } = this.generateLocalVideoViewsKeys(videoId)
+
+ const valueString = await this.getValue(videoKey)
+ const valueInt = parseInt(valueString, 10)
+
+ if (isNaN(valueInt)) {
+ logger.error('Cannot get videos views of video %d: views number is NaN (%s).', videoId, valueString)
+ return undefined
+ }
+
+ return valueInt
+ }
+
+ async listLocalVideosViewed () {
+ const { setKey } = this.generateLocalVideoViewsKeys()
+
+ const stringIds = await this.getSet(setKey)
+ return stringIds.map(s => parseInt(s, 10))
+ }
+
+ deleteLocalVideoViews (videoId: number) {
+ const { setKey, videoKey } = this.generateLocalVideoViewsKeys(videoId)
+
+ return Promise.all([
+ this.deleteFromSet(setKey, videoId.toString()),
+ this.deleteKey(videoKey)
+ ])
+ }
+
+ /* ************ Resumable uploads final responses ************ */
+
+ setUploadSession (uploadId: string, response?: { video: { id: number, shortUUID: string, uuid: string } }) {
+ return this.setValue(
+ 'resumable-upload-' + uploadId,
+ response
+ ? JSON.stringify(response)
+ : '',
+ RESUMABLE_UPLOAD_SESSION_LIFETIME
+ )
+ }
+
+ doesUploadSessionExist (uploadId: string) {
+ return this.exists('resumable-upload-' + uploadId)
+ }
+
+ async getUploadSession (uploadId: string) {
+ const value = await this.getValue('resumable-upload-' + uploadId)
+
+ return value
+ ? JSON.parse(value)
+ : ''
+ }
+
+ deleteUploadSession (uploadId: string) {
+ return this.deleteKey('resumable-upload-' + uploadId)
+ }
+