-
-async function createOrUpdateCacheFile (cacheFileObject: CacheFileObject, video: VideoModel, byActor: { id?: number }, t: Transaction) {
- const redundancyModel = await VideoRedundancyModel.loadByUrl(cacheFileObject.id, t)
-
- if (!redundancyModel) {
- await createCacheFile(cacheFileObject, video, byActor, t)
- } else {
- await updateCacheFile(cacheFileObject, redundancyModel, video, byActor, t)
- }
-}
-
-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)
-
- redundancyModel.set('expires', attributes.expiresOn)
- redundancyModel.set('fileUrl', attributes.fileUrl)
-
- return redundancyModel.save({ transaction: t })
-}
-
-export {
- createOrUpdateCacheFile,
- createCacheFile,
- updateCacheFile,
- cacheFileActivityObjectToDBAttributes
-}