From 2922e048de95738b3319054ce0778f873a34a0ee Mon Sep 17 00:00:00 2001 From: Julien Le Bras Date: Wed, 28 Mar 2018 23:38:52 +0200 Subject: Add publishedAt field for video model. * New field added in the `video` table + migration script * `publishedAt` updated to NOW when privacy changes from private to public/unlisted (default = NOW) * Models updated to handle the new attribute * Client interface updated to use `publishedAt` instead of `createdAt` except in My Account > My Videos view --- server/controllers/api/videos/index.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'server/controllers/api/videos') diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 552e5edac..244099015 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -307,10 +307,17 @@ async function updateVideo (req: express.Request, res: express.Response) { if (videoInfoToUpdate.licence !== undefined) videoInstance.set('licence', videoInfoToUpdate.licence) if (videoInfoToUpdate.language !== undefined) videoInstance.set('language', videoInfoToUpdate.language) if (videoInfoToUpdate.nsfw !== undefined) videoInstance.set('nsfw', videoInfoToUpdate.nsfw) - if (videoInfoToUpdate.privacy !== undefined) videoInstance.set('privacy', parseInt(videoInfoToUpdate.privacy.toString(), 10)) if (videoInfoToUpdate.support !== undefined) videoInstance.set('support', videoInfoToUpdate.support) if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description) if (videoInfoToUpdate.commentsEnabled !== undefined) videoInstance.set('commentsEnabled', videoInfoToUpdate.commentsEnabled) + if (videoInfoToUpdate.privacy !== undefined) { + const newPrivacy = parseInt(videoInfoToUpdate.privacy.toString(), 10) + videoInstance.set('privacy', newPrivacy) + + if (wasPrivateVideo === true && newPrivacy !== VideoPrivacy.PRIVATE) { + videoInstance.set('publishedAt', new Date()) + } + } const videoInstanceUpdated = await videoInstance.save(sequelizeOptions) -- cgit v1.2.3