aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/videos/index.ts8
-rw-r--r--server/helpers/custom-validators/videos.ts7
-rw-r--r--server/initializers/constants.ts2
-rw-r--r--server/initializers/migrations/0340-add-originally-published-at.ts31
-rw-r--r--server/middlewares/validators/videos/videos.ts6
-rw-r--r--server/models/video/video-format-utils.ts4
-rw-r--r--server/models/video/video.ts4
7 files changed, 58 insertions, 4 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 76a318d13..6ac13e6a4 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -190,7 +190,8 @@ async function addVideo (req: express.Request, res: express.Response) {
190 support: videoInfo.support, 190 support: videoInfo.support,
191 privacy: videoInfo.privacy, 191 privacy: videoInfo.privacy,
192 duration: videoPhysicalFile['duration'], // duration was added by a previous middleware 192 duration: videoPhysicalFile['duration'], // duration was added by a previous middleware
193 channelId: res.locals.videoChannel.id 193 channelId: res.locals.videoChannel.id,
194 originallyPublishedAt: videoInfo.originallyPublishedAt
194 } 195 }
195 const video = new VideoModel(videoData) 196 const video = new VideoModel(videoData)
196 video.url = getVideoActivityPubUrl(video) // We use the UUID, so set the URL after building the object 197 video.url = getVideoActivityPubUrl(video) // We use the UUID, so set the URL after building the object
@@ -328,6 +329,11 @@ async function updateVideo (req: express.Request, res: express.Response) {
328 if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description) 329 if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description)
329 if (videoInfoToUpdate.commentsEnabled !== undefined) videoInstance.set('commentsEnabled', videoInfoToUpdate.commentsEnabled) 330 if (videoInfoToUpdate.commentsEnabled !== undefined) videoInstance.set('commentsEnabled', videoInfoToUpdate.commentsEnabled)
330 if (videoInfoToUpdate.downloadEnabled !== undefined) videoInstance.set('downloadEnabled', videoInfoToUpdate.downloadEnabled) 331 if (videoInfoToUpdate.downloadEnabled !== undefined) videoInstance.set('downloadEnabled', videoInfoToUpdate.downloadEnabled)
332
333 if (videoInfoToUpdate.originallyPublishedAt !== undefined && videoInfoToUpdate.originallyPublishedAt !== null) {
334 videoInstance.set('originallyPublishedAt', videoInfoToUpdate.originallyPublishedAt)
335 }
336
331 if (videoInfoToUpdate.privacy !== undefined) { 337 if (videoInfoToUpdate.privacy !== undefined) {
332 const newPrivacy = parseInt(videoInfoToUpdate.privacy.toString(), 10) 338 const newPrivacy = parseInt(videoInfoToUpdate.privacy.toString(), 10)
333 videoInstance.set('privacy', newPrivacy) 339 videoInstance.set('privacy', newPrivacy)
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts
index 95e256b8f..dd04aa5f6 100644
--- a/server/helpers/custom-validators/videos.ts
+++ b/server/helpers/custom-validators/videos.ts
@@ -13,7 +13,7 @@ import {
13 VIDEO_STATES 13 VIDEO_STATES
14} from '../../initializers' 14} from '../../initializers'
15import { VideoModel } from '../../models/video/video' 15import { VideoModel } from '../../models/video/video'
16import { exists, isArray, isFileValid } from './misc' 16import { exists, isArray, isDateValid, isFileValid } from './misc'
17import { VideoChannelModel } from '../../models/video/video-channel' 17import { VideoChannelModel } from '../../models/video/video-channel'
18import { UserModel } from '../../models/account/user' 18import { UserModel } from '../../models/account/user'
19import * as magnetUtil from 'magnet-uri' 19import * as magnetUtil from 'magnet-uri'
@@ -115,6 +115,10 @@ function isScheduleVideoUpdatePrivacyValid (value: number) {
115 ) 115 )
116} 116}
117 117
118function isVideoOriginallyPublishedAtValid (value: string | null) {
119 return value === null || isDateValid(value)
120}
121
118function isVideoFileInfoHashValid (value: string | null | undefined) { 122function isVideoFileInfoHashValid (value: string | null | undefined) {
119 return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.INFO_HASH) 123 return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.INFO_HASH)
120} 124}
@@ -220,6 +224,7 @@ export {
220 isVideoTagsValid, 224 isVideoTagsValid,
221 isVideoFPSResolutionValid, 225 isVideoFPSResolutionValid,
222 isScheduleVideoUpdatePrivacyValid, 226 isScheduleVideoUpdatePrivacyValid,
227 isVideoOriginallyPublishedAtValid,
223 isVideoFile, 228 isVideoFile,
224 isVideoMagnetUriValid, 229 isVideoMagnetUriValid,
225 isVideoStateValid, 230 isVideoStateValid,
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index 639493d73..3656a23f9 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -16,7 +16,7 @@ let config: IConfig = require('config')
16 16
17// --------------------------------------------------------------------------- 17// ---------------------------------------------------------------------------
18 18
19const LAST_MIGRATION_VERSION = 335 19const LAST_MIGRATION_VERSION = 340
20 20
21// --------------------------------------------------------------------------- 21// ---------------------------------------------------------------------------
22 22
diff --git a/server/initializers/migrations/0340-add-originally-published-at.ts b/server/initializers/migrations/0340-add-originally-published-at.ts
new file mode 100644
index 000000000..ab8d66854
--- /dev/null
+++ b/server/initializers/migrations/0340-add-originally-published-at.ts
@@ -0,0 +1,31 @@
1import * as Sequelize from 'sequelize'
2
3async function up (utils: {
4 transaction: Sequelize.Transaction,
5 queryInterface: Sequelize.QueryInterface,
6 sequelize: Sequelize.Sequelize
7}): Promise<void> {
8
9 {
10 const data = {
11 type: Sequelize.DATE,
12 allowNull: true,
13 defaultValue: Sequelize.NOW
14 }
15 await utils.queryInterface.addColumn('video', 'originallyPublishedAt', data)
16 }
17
18 {
19 const query = 'UPDATE video SET "originallyPublishedAt" = video."publishedAt"'
20 await utils.sequelize.query(query)
21 }
22}
23
24function down (options) {
25 throw new Error('Not implemented.')
26}
27
28export {
29 up,
30 down
31}
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts
index d9626929c..159727e28 100644
--- a/server/middlewares/validators/videos/videos.ts
+++ b/server/middlewares/validators/videos/videos.ts
@@ -14,6 +14,7 @@ import {
14} from '../../../helpers/custom-validators/misc' 14} from '../../../helpers/custom-validators/misc'
15import { 15import {
16 checkUserCanManageVideo, 16 checkUserCanManageVideo,
17 isVideoOriginallyPublishedAtValid,
17 isScheduleVideoUpdatePrivacyValid, 18 isScheduleVideoUpdatePrivacyValid,
18 isVideoCategoryValid, 19 isVideoCategoryValid,
19 isVideoChannelOfAccountExist, 20 isVideoChannelOfAccountExist,
@@ -344,7 +345,10 @@ function getCommonVideoAttributes () {
344 .optional() 345 .optional()
345 .toBoolean() 346 .toBoolean()
346 .custom(isBooleanValid).withMessage('Should have downloading enabled boolean'), 347 .custom(isBooleanValid).withMessage('Should have downloading enabled boolean'),
347 348 body('originallyPublishedAt')
349 .optional()
350 .customSanitizer(toValueOrNull)
351 .custom(isVideoOriginallyPublishedAtValid).withMessage('Should have a valid original publication date'),
348 body('scheduleUpdate') 352 body('scheduleUpdate')
349 .optional() 353 .optional()
350 .customSanitizer(toValueOrNull), 354 .customSanitizer(toValueOrNull),
diff --git a/server/models/video/video-format-utils.ts b/server/models/video/video-format-utils.ts
index 76d0445d4..c63285e25 100644
--- a/server/models/video/video-format-utils.ts
+++ b/server/models/video/video-format-utils.ts
@@ -67,6 +67,7 @@ function videoModelToFormattedJSON (video: VideoModel, options?: VideoFormatting
67 createdAt: video.createdAt, 67 createdAt: video.createdAt,
68 updatedAt: video.updatedAt, 68 updatedAt: video.updatedAt,
69 publishedAt: video.publishedAt, 69 publishedAt: video.publishedAt,
70 originallyPublishedAt: video.originallyPublishedAt,
70 account: { 71 account: {
71 id: formattedAccount.id, 72 id: formattedAccount.id,
72 uuid: formattedAccount.uuid, 73 uuid: formattedAccount.uuid,
@@ -323,6 +324,9 @@ function videoModelToActivityPubObject (video: VideoModel): VideoTorrentObject {
323 commentsEnabled: video.commentsEnabled, 324 commentsEnabled: video.commentsEnabled,
324 downloadEnabled: video.downloadEnabled, 325 downloadEnabled: video.downloadEnabled,
325 published: video.publishedAt.toISOString(), 326 published: video.publishedAt.toISOString(),
327 originallyPublishedAt: video.originallyPublishedAt ?
328 video.originallyPublishedAt.toISOString() :
329 null,
326 updated: video.updatedAt.toISOString(), 330 updated: video.updatedAt.toISOString(),
327 mediaType: 'text/markdown', 331 mediaType: 'text/markdown',
328 content: video.getTruncatedDescription(), 332 content: video.getTruncatedDescription(),
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 0feeed4f8..73626b6a0 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -103,6 +103,7 @@ const indexes: Sequelize.DefineIndexesOptions[] = [
103 103
104 { fields: [ 'createdAt' ] }, 104 { fields: [ 'createdAt' ] },
105 { fields: [ 'publishedAt' ] }, 105 { fields: [ 'publishedAt' ] },
106 { fields: [ 'originallyPublishedAt' ] },
106 { fields: [ 'duration' ] }, 107 { fields: [ 'duration' ] },
107 { fields: [ 'views' ] }, 108 { fields: [ 'views' ] },
108 { fields: [ 'channelId' ] }, 109 { fields: [ 'channelId' ] },
@@ -740,6 +741,9 @@ export class VideoModel extends Model<VideoModel> {
740 @Column 741 @Column
741 publishedAt: Date 742 publishedAt: Date
742 743
744 @Column
745 originallyPublishedAt: Date
746
743 @ForeignKey(() => VideoChannelModel) 747 @ForeignKey(() => VideoChannelModel)
744 @Column 748 @Column
745 channelId: number 749 channelId: number