From 93e1258c7cbc0d1235ca6d2a1f7c1875985328b8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 25 Aug 2017 11:36:23 +0200 Subject: Move video file metadata in their own table Will be used for user video quotas and multiple video resolutions --- server/controllers/api/remote/videos.ts | 42 +++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'server/controllers/api/remote/videos.ts') diff --git a/server/controllers/api/remote/videos.ts b/server/controllers/api/remote/videos.ts index 30771d8c4..e7edff606 100644 --- a/server/controllers/api/remote/videos.ts +++ b/server/controllers/api/remote/videos.ts @@ -258,8 +258,6 @@ function addRemoteVideo (videoToCreateData: RemoteVideoCreateData, fromPod: PodI const videoData = { name: videoToCreateData.name, uuid: videoToCreateData.uuid, - extname: videoToCreateData.extname, - infoHash: videoToCreateData.infoHash, category: videoToCreateData.category, licence: videoToCreateData.licence, language: videoToCreateData.language, @@ -289,6 +287,26 @@ function addRemoteVideo (videoToCreateData: RemoteVideoCreateData, fromPod: PodI return video.save(options).then(videoCreated => ({ tagInstances, videoCreated })) }) + .then(({ tagInstances, videoCreated }) => { + const tasks = [] + const options = { + transaction: t + } + + videoToCreateData.files.forEach(fileData => { + const videoFileInstance = db.VideoFile.build({ + extname: fileData.extname, + infoHash: fileData.infoHash, + resolution: fileData.resolution, + size: fileData.size, + videoId: videoCreated.id + }) + + tasks.push(videoFileInstance.save(options)) + }) + + return Promise.all(tasks).then(() => ({ tagInstances, videoCreated })) + }) .then(({ tagInstances, videoCreated }) => { const options = { transaction: t @@ -344,6 +362,26 @@ function updateRemoteVideo (videoAttributesToUpdate: RemoteVideoUpdateData, from return videoInstance.save(options).then(() => ({ videoInstance, tagInstances })) }) + .then(({ tagInstances, videoInstance }) => { + const tasks = [] + const options = { + transaction: t + } + + videoAttributesToUpdate.files.forEach(fileData => { + const videoFileInstance = db.VideoFile.build({ + extname: fileData.extname, + infoHash: fileData.infoHash, + resolution: fileData.resolution, + size: fileData.size, + videoId: videoInstance.id + }) + + tasks.push(videoFileInstance.save(options)) + }) + + return Promise.all(tasks).then(() => ({ tagInstances, videoInstance })) + }) .then(({ videoInstance, tagInstances }) => { const options = { transaction: t } -- cgit v1.2.3