From 2d435c685e66b6739f58fb444497883796bfa248 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Fri, 26 May 2023 09:37:04 +0400 Subject: [PATCH] Add video attribute "importedFrom" --- .../metadata/video-attributes.component.html | 12 +++++++++++ .../shared/shared-main/video/video.model.ts | 2 ++ server/initializers/constants.ts | 2 +- .../migrations/0756-imported-from.ts | 21 +++++++++++++++++++ .../video/formatter/video-format-utils.ts | 1 + .../video/shared/video-table-attributes.ts | 1 + server/models/video/video.ts | 5 +++++ shared/models/videos/video.model.ts | 1 + support/doc/api/openapi.yaml | 3 +++ 9 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 server/initializers/migrations/0756-imported-from.ts diff --git a/client/src/app/+videos/+video-watch/shared/metadata/video-attributes.component.html b/client/src/app/+videos/+video-watch/shared/metadata/video-attributes.component.html index 0aa707666..cc77891e7 100644 --- a/client/src/app/+videos/+video-watch/shared/metadata/video-attributes.component.html +++ b/client/src/app/+videos/+video-watch/shared/metadata/video-attributes.component.html @@ -18,6 +18,18 @@ +
+ Imported from + + {{ video.importedFrom }} + +
+
Originally published {{ video.originallyPublishedAt | date: 'dd MMMM yyyy' }} diff --git a/client/src/app/shared/shared-main/video/video.model.ts b/client/src/app/shared/shared-main/video/video.model.ts index 6fdffb394..fff8bba78 100644 --- a/client/src/app/shared/shared-main/video/video.model.ts +++ b/client/src/app/shared/shared-main/video/video.model.ts @@ -28,6 +28,7 @@ export class Video implements VideoServerModel { createdAt: Date updatedAt: Date publishedAt: Date + importedFrom: string originallyPublishedAt: Date | string category: VideoConstant licence: VideoConstant @@ -185,6 +186,7 @@ export class Video implements VideoServerModel { this.privacy.label = peertubeTranslate(this.privacy.label, translations) this.scheduledUpdate = hash.scheduledUpdate + this.importedFrom = hash.importedFrom this.originallyPublishedAt = hash.originallyPublishedAt ? new Date(hash.originallyPublishedAt.toString()) : null if (this.state) this.state.label = peertubeTranslate(this.state.label, translations) diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 4703e20f2..7ce7f73b2 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -26,7 +26,7 @@ import { CONFIG, registerConfigChangedHandler } from './config' // --------------------------------------------------------------------------- -const LAST_MIGRATION_VERSION = 755 +const LAST_MIGRATION_VERSION = 756 // --------------------------------------------------------------------------- diff --git a/server/initializers/migrations/0756-imported-from.ts b/server/initializers/migrations/0756-imported-from.ts new file mode 100644 index 000000000..90d9ac8a2 --- /dev/null +++ b/server/initializers/migrations/0756-imported-from.ts @@ -0,0 +1,21 @@ +import * as Sequelize from 'sequelize' + +async function up (utils: { + transaction: Sequelize.Transaction + queryInterface: Sequelize.QueryInterface + sequelize: Sequelize.Sequelize +}): Promise { + await utils.sequelize.query(` + ALTER TABLE "video" + ADD COLUMN "importedFrom" + varchar(2000) + `) +} + +async function down (utils: {}) { +} + +export { + up, + down +} diff --git a/server/models/video/formatter/video-format-utils.ts b/server/models/video/formatter/video-format-utils.ts index 6f05dbdc8..457b38b83 100644 --- a/server/models/video/formatter/video-format-utils.ts +++ b/server/models/video/formatter/video-format-utils.ts @@ -122,6 +122,7 @@ function videoModelToFormattedJSON (video: MVideoFormattable, options: VideoForm createdAt: video.createdAt, updatedAt: video.updatedAt, publishedAt: video.publishedAt, + importedFrom: video.importedFrom, originallyPublishedAt: video.originallyPublishedAt, isLive: video.isLive, diff --git a/server/models/video/sql/video/shared/video-table-attributes.ts b/server/models/video/sql/video/shared/video-table-attributes.ts index e2c1c0f6d..d24f45d4d 100644 --- a/server/models/video/sql/video/shared/video-table-attributes.ts +++ b/server/models/video/sql/video/shared/video-table-attributes.ts @@ -260,6 +260,7 @@ export class VideoTableAttributes { 'waitTranscoding', 'state', 'publishedAt', + 'importedFrom', 'originallyPublishedAt', 'channelId', 'createdAt', diff --git a/server/models/video/video.ts b/server/models/video/video.ts index aa9c62e36..a866ba6db 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -549,6 +549,11 @@ export class VideoModel extends Model>> { @Column publishedAt: Date + @AllowNull(true) + @Default(null) + @Column + importedFrom: string + @AllowNull(true) @Default(null) @Column diff --git a/shared/models/videos/video.model.ts b/shared/models/videos/video.model.ts index 06ffb327c..081072f2f 100644 --- a/shared/models/videos/video.model.ts +++ b/shared/models/videos/video.model.ts @@ -15,6 +15,7 @@ export interface Video { createdAt: Date | string updatedAt: Date | string publishedAt: Date | string + importedFrom: string originallyPublishedAt: Date | string category: VideoConstant licence: VideoConstant diff --git a/support/doc/api/openapi.yaml b/support/doc/api/openapi.yaml index a63694211..9000e4fd2 100644 --- a/support/doc/api/openapi.yaml +++ b/support/doc/api/openapi.yaml @@ -2530,6 +2530,9 @@ paths: downloadEnabled: description: Enable or disable downloading for this video type: boolean + importedFrom: + description: The URL where this video is imported from + type: string originallyPublishedAt: description: Date when the content was originally published type: string