aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorJulien Le Bras <julien.lb.pro@gmail.com>2018-03-28 23:38:52 +0200
committerChocobozzz <me@florianbigard.com>2018-03-30 08:52:58 +0200
commit2922e048de95738b3319054ce0778f873a34a0ee (patch)
treeee35b2e8bf9e1967b7d08974d6680697b2965472 /server
parent2920281946cffd62ce5046b661d63f9867ab0654 (diff)
downloadPeerTube-2922e048de95738b3319054ce0778f873a34a0ee.tar.gz
PeerTube-2922e048de95738b3319054ce0778f873a34a0ee.tar.zst
PeerTube-2922e048de95738b3319054ce0778f873a34a0ee.zip
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
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/videos/index.ts9
-rw-r--r--server/initializers/constants.ts2
-rw-r--r--server/initializers/migrations/0200-video-published-at.ts32
-rw-r--r--server/models/video/video.ts8
4 files changed, 48 insertions, 3 deletions
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) {
307 if (videoInfoToUpdate.licence !== undefined) videoInstance.set('licence', videoInfoToUpdate.licence) 307 if (videoInfoToUpdate.licence !== undefined) videoInstance.set('licence', videoInfoToUpdate.licence)
308 if (videoInfoToUpdate.language !== undefined) videoInstance.set('language', videoInfoToUpdate.language) 308 if (videoInfoToUpdate.language !== undefined) videoInstance.set('language', videoInfoToUpdate.language)
309 if (videoInfoToUpdate.nsfw !== undefined) videoInstance.set('nsfw', videoInfoToUpdate.nsfw) 309 if (videoInfoToUpdate.nsfw !== undefined) videoInstance.set('nsfw', videoInfoToUpdate.nsfw)
310 if (videoInfoToUpdate.privacy !== undefined) videoInstance.set('privacy', parseInt(videoInfoToUpdate.privacy.toString(), 10))
311 if (videoInfoToUpdate.support !== undefined) videoInstance.set('support', videoInfoToUpdate.support) 310 if (videoInfoToUpdate.support !== undefined) videoInstance.set('support', videoInfoToUpdate.support)
312 if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description) 311 if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description)
313 if (videoInfoToUpdate.commentsEnabled !== undefined) videoInstance.set('commentsEnabled', videoInfoToUpdate.commentsEnabled) 312 if (videoInfoToUpdate.commentsEnabled !== undefined) videoInstance.set('commentsEnabled', videoInfoToUpdate.commentsEnabled)
313 if (videoInfoToUpdate.privacy !== undefined) {
314 const newPrivacy = parseInt(videoInfoToUpdate.privacy.toString(), 10)
315 videoInstance.set('privacy', newPrivacy)
316
317 if (wasPrivateVideo === true && newPrivacy !== VideoPrivacy.PRIVATE) {
318 videoInstance.set('publishedAt', new Date())
319 }
320 }
314 321
315 const videoInstanceUpdated = await videoInstance.save(sequelizeOptions) 322 const videoInstanceUpdated = await videoInstance.save(sequelizeOptions)
316 323
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index 5152095b3..2622b2c71 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -12,7 +12,7 @@ let config: IConfig = require('config')
12 12
13// --------------------------------------------------------------------------- 13// ---------------------------------------------------------------------------
14 14
15const LAST_MIGRATION_VERSION = 195 15const LAST_MIGRATION_VERSION = 200
16 16
17// --------------------------------------------------------------------------- 17// ---------------------------------------------------------------------------
18 18
diff --git a/server/initializers/migrations/0200-video-published-at.ts b/server/initializers/migrations/0200-video-published-at.ts
new file mode 100644
index 000000000..edaf4a145
--- /dev/null
+++ b/server/initializers/migrations/0200-video-published-at.ts
@@ -0,0 +1,32 @@
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: false,
13 defaultValue: Sequelize.NOW
14 }
15 await utils.queryInterface.addColumn('video', 'publishedAt', data)
16 }
17
18 {
19 const query = 'UPDATE video SET "publishedAt" = video."createdAt"'
20 await utils.sequelize.query(query)
21 }
22
23}
24
25function down (options) {
26 throw new Error('Not implemented.')
27}
28
29export {
30 up,
31 down
32}
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 7c56c65a6..2a1226f6d 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -376,6 +376,11 @@ export class VideoModel extends Model<VideoModel> {
376 @UpdatedAt 376 @UpdatedAt
377 updatedAt: Date 377 updatedAt: Date
378 378
379 @AllowNull(false)
380 @Default(Sequelize.NOW)
381 @Column
382 publishedAt: Date
383
379 @ForeignKey(() => VideoChannelModel) 384 @ForeignKey(() => VideoChannelModel)
380 @Column 385 @Column
381 channelId: number 386 channelId: number
@@ -968,6 +973,7 @@ export class VideoModel extends Model<VideoModel> {
968 embedPath: this.getEmbedPath(), 973 embedPath: this.getEmbedPath(),
969 createdAt: this.createdAt, 974 createdAt: this.createdAt,
970 updatedAt: this.updatedAt, 975 updatedAt: this.updatedAt,
976 publishedAt: this.publishedAt,
971 account: { 977 account: {
972 name: formattedAccount.name, 978 name: formattedAccount.name,
973 displayName: formattedAccount.displayName, 979 displayName: formattedAccount.displayName,
@@ -1122,7 +1128,7 @@ export class VideoModel extends Model<VideoModel> {
1122 views: this.views, 1128 views: this.views,
1123 sensitive: this.nsfw, 1129 sensitive: this.nsfw,
1124 commentsEnabled: this.commentsEnabled, 1130 commentsEnabled: this.commentsEnabled,
1125 published: this.createdAt.toISOString(), 1131 published: this.publishedAt.toISOString(),
1126 updated: this.updatedAt.toISOString(), 1132 updated: this.updatedAt.toISOString(),
1127 mediaType: 'text/markdown', 1133 mediaType: 'text/markdown',
1128 content: this.getTruncatedDescription(), 1134 content: this.getTruncatedDescription(),