ActivityPub-federated video streaming platform using P2P directly in your web browser
Add publishedAt field for video model.
Julien Le Bras2922e048de95
diff --git a/client/src/app/shared/video/video-miniature.component.html b/client/src/app/shared/video/video-miniature.component.htmlindex 7ac017235c..f28e9b8d9a 100644--- a/client/src/app/shared/video/video-miniature.component.html+++ b/client/src/app/shared/video/video-miniature.component.html@@ -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>diff --git a/client/src/app/shared/video/video.model.ts b/client/src/app/shared/video/video.model.tsindex 7b68933a1c..0c02cbcb9e 100644--- a/client/src/app/shared/video/video.model.ts+++ b/client/src/app/shared/video/video.model.ts@@ -9,6 +9,7 @@ export class Video implements VideoServerModel {by: stringcreatedAt: DateupdatedAt: Date+ publishedAt: Datecategory: 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.categorythis.licence = hash.licencethis.language = hash.languagediff --git a/client/src/app/videos/+video-watch/video-watch.component.html b/client/src/app/videos/+video-watch/video-watch.component.htmlindex 6c7fc08e11..ec5bd30dcb 100644--- a/client/src/app/videos/+video-watch/video-watch.component.html+++ b/client/src/app/videos/+video-watch/video-watch.component.html@@ -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">diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.tsindex 552e5edac7..244099015e 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)diff --git a/server/initializers/constants.ts b/server/initializers/constants.tsindex 5152095b3c..2622b2c71a 100644--- a/server/initializers/constants.ts+++ b/server/initializers/constants.ts@@ -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.tsnew file mode 100644index 0000000000..edaf4a145c--- /dev/null+++ b/server/initializers/migrations/0200-video-published-at.ts@@ -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+}diff --git a/server/models/video/video.ts b/server/models/video/video.tsindex 7c56c65a6e..2a1226f6dc 100644--- a/server/models/video/video.ts+++ b/server/models/video/video.ts@@ -376,6 +376,11 @@ export class VideoModel extends Model<VideoModel> {@UpdatedAtupdatedAt: Date+ @AllowNull(false)+ @Default(Sequelize.NOW)+ @Column+ publishedAt: Date+@ForeignKey(() => VideoChannelModel)@ColumnchannelId: 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(),diff --git a/shared/models/videos/video.model.ts b/shared/models/videos/video.model.tsindex ebd2813ca5..1b5f1a09c6 100644--- a/shared/models/videos/video.model.ts+++ b/shared/models/videos/video.model.ts@@ -22,6 +22,7 @@ export interface Video {uuid: stringcreatedAt: Date | stringupdatedAt: Date | string+ publishedAt: Date | stringcategory: VideoConstant<number>licence: VideoConstant<number>language: VideoConstant<number>