]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Add publishedAt field for video model.
authorJulien Le Bras <julien.lb.pro@gmail.com>
Wed, 28 Mar 2018 21:38:52 +0000 (23:38 +0200)
committerChocobozzz <me@florianbigard.com>
Fri, 30 Mar 2018 06:52:58 +0000 (08:52 +0200)
* 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

client/src/app/shared/video/video-miniature.component.html
client/src/app/shared/video/video.model.ts
client/src/app/videos/+video-watch/video-watch.component.html
server/controllers/api/videos/index.ts
server/initializers/constants.ts
server/initializers/migrations/0200-video-published-at.ts [new file with mode: 0644]
server/models/video/video.ts
shared/models/videos/video.model.ts

index 7ac017235c7852c2002548b446a4210dbd74f84c..f28e9b8d9a35cba38069213bac241a2007f37b41 100644 (file)
@@ -11,7 +11,7 @@
       </a>
     </span>
 
-    <span class="video-miniature-created-at-views">{{ video.createdAt | myFromNow }} - {{ video.views | myNumberFormatter }} views</span>
+    <span class="video-miniature-created-at-views">{{ video.publishedAt | myFromNow }} - {{ video.views | myNumberFormatter }} views</span>
     <span class="video-miniature-account">{{ video.by }}</span>
   </div>
 </div>
index 7b68933a1c88a51ae4f2d84122c9a28d8366bbe9..0c02cbcb9eac3675a2e70ecf1c666e418a9f5b3a 100644 (file)
@@ -9,6 +9,7 @@ export class Video implements VideoServerModel {
   by: string
   createdAt: Date
   updatedAt: Date
+  publishedAt: Date
   category: VideoConstant<number>
   licence: VideoConstant<number>
   language: VideoConstant<number>
@@ -56,6 +57,7 @@ export class Video implements VideoServerModel {
     const absoluteAPIUrl = getAbsoluteAPIUrl()
 
     this.createdAt = new Date(hash.createdAt.toString())
+    this.publishedAt = new Date(hash.publishedAt.toString())
     this.category = hash.category
     this.licence = hash.licence
     this.language = hash.language
index 6c7fc08e112bed0f8073532244e049c428b73917..ec5bd30dcba86f7cc711e0a8c2faad67707e67d6 100644 (file)
@@ -14,7 +14,7 @@
           <div class="video-info-name">{{ video.name }}</div>
 
           <div class="video-info-date-views">
-            {{ video.createdAt | myFromNow }} - {{ video.views | myNumberFormatter }} views
+            {{ video.publishedAt | myFromNow }} - {{ video.views | myNumberFormatter }} views
           </div>
 
           <div class="video-info-channel">
index 552e5edac74c08223a07feb3a3394f5ff4af6713..244099015e3a9c1b58e5559368ea02991d90ad7e 100644 (file)
@@ -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)
 
index 5152095b3c198abaef3ac831d57acc753354cf97..2622b2c71a2561b735a31dbbcc25f4914f85cba2 100644 (file)
@@ -12,7 +12,7 @@ let config: IConfig = require('config')
 
 // ---------------------------------------------------------------------------
 
-const LAST_MIGRATION_VERSION = 195
+const LAST_MIGRATION_VERSION = 200
 
 // ---------------------------------------------------------------------------
 
diff --git a/server/initializers/migrations/0200-video-published-at.ts b/server/initializers/migrations/0200-video-published-at.ts
new file mode 100644 (file)
index 0000000..edaf4a1
--- /dev/null
@@ -0,0 +1,32 @@
+import * as Sequelize from 'sequelize'
+
+async function up (utils: {
+  transaction: Sequelize.Transaction,
+  queryInterface: Sequelize.QueryInterface,
+  sequelize: Sequelize.Sequelize
+}): Promise<void> {
+
+  {
+    const data = {
+      type: Sequelize.DATE,
+      allowNull: false,
+      defaultValue: Sequelize.NOW
+    }
+    await utils.queryInterface.addColumn('video', 'publishedAt', data)
+  }
+
+  {
+    const query = 'UPDATE video SET "publishedAt" = video."createdAt"'
+    await utils.sequelize.query(query)
+  }
+
+}
+
+function down (options) {
+  throw new Error('Not implemented.')
+}
+
+export {
+  up,
+  down
+}
index 7c56c65a6ea4a21e32c032e99b1d3b819e684e11..2a1226f6dcf8576921da4ce22af1999ecf8a266d 100644 (file)
@@ -376,6 +376,11 @@ export class VideoModel extends Model<VideoModel> {
   @UpdatedAt
   updatedAt: Date
 
+  @AllowNull(false)
+  @Default(Sequelize.NOW)
+  @Column
+  publishedAt: Date
+
   @ForeignKey(() => VideoChannelModel)
   @Column
   channelId: number
@@ -968,6 +973,7 @@ export class VideoModel extends Model<VideoModel> {
       embedPath: this.getEmbedPath(),
       createdAt: this.createdAt,
       updatedAt: this.updatedAt,
+      publishedAt: this.publishedAt,
       account: {
         name: formattedAccount.name,
         displayName: formattedAccount.displayName,
@@ -1122,7 +1128,7 @@ export class VideoModel extends Model<VideoModel> {
       views: this.views,
       sensitive: this.nsfw,
       commentsEnabled: this.commentsEnabled,
-      published: this.createdAt.toISOString(),
+      published: this.publishedAt.toISOString(),
       updated: this.updatedAt.toISOString(),
       mediaType: 'text/markdown',
       content: this.getTruncatedDescription(),
index ebd2813ca5f4ac554a9aba511817ca01242b84c2..1b5f1a09c685e3ee2aa164a517f1b5843bbe76d1 100644 (file)
@@ -22,6 +22,7 @@ export interface Video {
   uuid: string
   createdAt: Date | string
   updatedAt: Date | string
+  publishedAt: Date | string
   category: VideoConstant<number>
   licence: VideoConstant<number>
   language: VideoConstant<number>