-import { ActivityPlaylistUrlObject, ActivityVideoUrlObject, CacheFileObject } from '../../../shared/index'
-import { VideoModel } from '../../models/video/video'
+import { CacheFileObject } from '../../../shared/index'
import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy'
import { Transaction } from 'sequelize'
import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type'
+import { MActorId, MVideoRedundancy, MVideoWithAllFiles } from '@server/types/models'
-function cacheFileActivityObjectToDBAttributes (cacheFileObject: CacheFileObject, video: VideoModel, byActor: { id?: number }) {
+function cacheFileActivityObjectToDBAttributes (cacheFileObject: CacheFileObject, video: MVideoWithAllFiles, byActor: MActorId) {
if (cacheFileObject.url.mediaType === 'application/x-mpegURL') {
const url = cacheFileObject.url
if (!playlist) throw new Error('Cannot find HLS playlist of video ' + video.url)
return {
- expiresOn: new Date(cacheFileObject.expires),
+ expiresOn: cacheFileObject.expires ? new Date(cacheFileObject.expires) : null,
url: cacheFileObject.id,
fileUrl: url.href,
strategy: null,
if (!videoFile) throw new Error(`Cannot find video file ${url.height} ${url.fps} of video ${video.url}`)
return {
- expiresOn: new Date(cacheFileObject.expires),
+ expiresOn: cacheFileObject.expires ? new Date(cacheFileObject.expires) : null,
url: cacheFileObject.id,
fileUrl: url.href,
strategy: null,
}
}
-async function createOrUpdateCacheFile (cacheFileObject: CacheFileObject, video: VideoModel, byActor: { id?: number }, t: Transaction) {
+async function createOrUpdateCacheFile (cacheFileObject: CacheFileObject, video: MVideoWithAllFiles, byActor: MActorId, t: Transaction) {
const redundancyModel = await VideoRedundancyModel.loadByUrl(cacheFileObject.id, t)
if (!redundancyModel) {
}
}
-function createCacheFile (cacheFileObject: CacheFileObject, video: VideoModel, byActor: { id?: number }, t: Transaction) {
+function createCacheFile (cacheFileObject: CacheFileObject, video: MVideoWithAllFiles, byActor: MActorId, t: Transaction) {
const attributes = cacheFileActivityObjectToDBAttributes(cacheFileObject, video, byActor)
return VideoRedundancyModel.create(attributes, { transaction: t })
function updateCacheFile (
cacheFileObject: CacheFileObject,
- redundancyModel: VideoRedundancyModel,
- video: VideoModel,
- byActor: { id?: number },
+ redundancyModel: MVideoRedundancy,
+ video: MVideoWithAllFiles,
+ byActor: MActorId,
t: Transaction
) {
if (redundancyModel.actorId !== byActor.id) {
const attributes = cacheFileActivityObjectToDBAttributes(cacheFileObject, video, byActor)
- redundancyModel.set('expires', attributes.expiresOn)
- redundancyModel.set('fileUrl', attributes.fileUrl)
+ redundancyModel.expiresOn = attributes.expiresOn
+ redundancyModel.fileUrl = attributes.fileUrl
return redundancyModel.save({ transaction: t })
}