-function updateCacheFile (cacheFileObject: CacheFileObject, redundancyModel: VideoRedundancyModel, byActor: ActorModel) {
- const attributes = cacheFileActivityObjectToDBAttributes(cacheFileObject, redundancyModel.VideoFile.Video, byActor)
+function createCacheFile (cacheFileObject: CacheFileObject, video: VideoModel, byActor: { id?: number }, 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 },
+ t: Transaction
+) {
+ if (redundancyModel.actorId !== byActor.id) {
+ throw new Error('Cannot update redundancy ' + redundancyModel.url + ' of another actor.')
+ }
+
+ const attributes = cacheFileActivityObjectToDBAttributes(cacheFileObject, video, byActor)