ActivityPub-federated video streaming platform using P2P directly in your web browser
Federate entire description
Chocobozzzf713f36bdf6f
diff --git a/client/src/app/+videos/+video-watch/shared/metadata/video-description.component.html b/client/src/app/+videos/+video-watch/shared/metadata/video-description.component.htmlindex fa4dbb3ca8..d847daff7d 100644--- a/client/src/app/+videos/+video-watch/shared/metadata/video-description.component.html+++ b/client/src/app/+videos/+video-watch/shared/metadata/video-description.component.html@@ -1,7 +1,7 @@<div class="video-info-description"><divclass="video-info-description-html"- [innerHTML]="videoHTMLDescription"+ [innerHTML]="getHTMLDescription()"(timestampClicked)="onTimestampClicked($event)"myTimestampRouteTransformer></div>diff --git a/client/src/app/+videos/+video-watch/shared/metadata/video-description.component.ts b/client/src/app/+videos/+video-watch/shared/metadata/video-description.component.tsindex 72b09a274b..d010806110 100644--- a/client/src/app/+videos/+video-watch/shared/metadata/video-description.component.ts+++ b/client/src/app/+videos/+video-watch/shared/metadata/video-description.component.ts@@ -15,8 +15,10 @@ export class VideoDescriptionComponent implements OnChanges {descriptionLoading = falsecompleteDescriptionShown = false- completeVideoDescription: string- shortVideoDescription: string++ completeVideoDescriptionLoaded = false++ videoHTMLTruncatedDescription = ''videoHTMLDescription = ''constructor (@@ -28,22 +30,19 @@ export class VideoDescriptionComponent implements OnChanges {ngOnChanges () {this.descriptionLoading = falsethis.completeDescriptionShown = false- this.completeVideoDescription = undefinedthis.setVideoDescriptionHTML()}showMoreDescription () {- if (this.completeVideoDescription === undefined) {+ if (!this.completeVideoDescriptionLoaded) {return this.loadCompleteDescription()}- this.updateVideoDescription(this.completeVideoDescription)this.completeDescriptionShown = true}showLessDescription () {- this.updateVideoDescription(this.shortVideoDescription)this.completeDescriptionShown = false}@@ -56,10 +55,10 @@ export class VideoDescriptionComponent implements OnChanges {this.completeDescriptionShown = truethis.descriptionLoading = false- this.shortVideoDescription = this.video.description- this.completeVideoDescription = description+ this.video.description = description- this.updateVideoDescription(this.completeVideoDescription)+ this.setVideoDescriptionHTML()+ .catch(err => logger.error(err))},error: err => {@@ -73,15 +72,25 @@ export class VideoDescriptionComponent implements OnChanges {this.timestampClicked.emit(timestamp)}- private updateVideoDescription (description: string) {- this.video.description = description- this.setVideoDescriptionHTML()- .catch(err => logger.error(err))+ getHTMLDescription () {+ if (this.completeDescriptionShown) {+ return this.videoHTMLDescription+ }++ return this.videoHTMLTruncatedDescription}private async setVideoDescriptionHTML () {- const html = await this.markdownService.textMarkdownToHTML({ markdown: this.video.description })+ {+ const html = await this.markdownService.textMarkdownToHTML({ markdown: this.video.description })- this.videoHTMLDescription = this.markdownService.processVideoTimestamps(this.video.shortUUID, html)+ this.videoHTMLDescription = this.markdownService.processVideoTimestamps(this.video.shortUUID, html)+ }++ {+ const html = await this.markdownService.textMarkdownToHTML({ markdown: this.video.truncatedDescription })++ this.videoHTMLTruncatedDescription = this.markdownService.processVideoTimestamps(this.video.shortUUID, html)+ }}}diff --git a/client/src/app/shared/shared-main/video/video.model.ts b/client/src/app/shared/shared-main/video/video.model.tsindex c9c6b979c2..6fdffb3942 100644--- a/client/src/app/shared/shared-main/video/video.model.ts+++ b/client/src/app/shared/shared-main/video/video.model.ts@@ -34,6 +34,7 @@ export class Video implements VideoServerModel {language: VideoConstant<string>privacy: VideoConstant<VideoPrivacy>+ truncatedDescription: stringdescription: stringduration: number@@ -134,6 +135,8 @@ export class Video implements VideoServerModel {this.privacy = hash.privacythis.waitTranscoding = hash.waitTranscodingthis.state = hash.state++ this.truncatedDescription = hash.truncatedDescriptionthis.description = hash.descriptionthis.isLive = hash.isLivediff --git a/server/helpers/custom-validators/activitypub/videos.ts b/server/helpers/custom-validators/activitypub/videos.tsindex 2a2f008b90..97b3577af3 100644--- a/server/helpers/custom-validators/activitypub/videos.ts+++ b/server/helpers/custom-validators/activitypub/videos.ts@@ -7,11 +7,11 @@ import { peertubeTruncate } from '../../core-utils'import { isArray, isBooleanValid, isDateValid, isUUIDValid } from '../misc'import { isLiveLatencyModeValid } from '../video-lives'import {+ isVideoDescriptionValid,isVideoDurationValid,isVideoNameValid,isVideoStateValid,isVideoTagValid,- isVideoTruncatedDescriptionValid,isVideoViewsValid} from '../videos'import { isActivityPubUrlValid, isActivityPubVideoDurationValid, isBaseActivityValid, setValidAttributedTo } from './misc'@@ -32,7 +32,7 @@ function sanitizeAndCheckVideoTorrentObject (video: any) {logger.debug('Video has invalid urls', { video })return false}- if (!setRemoteVideoTruncatedContent(video)) {+ if (!setRemoteVideoContent(video)) {logger.debug('Video has invalid content', { video })return false}@@ -168,7 +168,7 @@ function isRemoteStringIdentifierValid (data: any) {}function isRemoteVideoContentValid (mediaType: string, content: string) {- return mediaType === 'text/markdown' && isVideoTruncatedDescriptionValid(content)+ return mediaType === 'text/markdown' && isVideoDescriptionValid(content)}function setValidRemoteIcon (video: any) {@@ -194,9 +194,9 @@ function setValidRemoteVideoUrls (video: any) {return true}-function setRemoteVideoTruncatedContent (video: any) {+function setRemoteVideoContent (video: any) {if (video.content) {- video.content = peertubeTruncate(video.content, { length: CONSTRAINTS_FIELDS.VIDEOS.TRUNCATED_DESCRIPTION.max })+ video.content = peertubeTruncate(video.content, { length: CONSTRAINTS_FIELDS.VIDEOS.DESCRIPTION.max })}return truediff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.tsindex 3ebfe29370..9e8177f77a 100644--- a/server/helpers/custom-validators/videos.ts+++ b/server/helpers/custom-validators/videos.ts@@ -45,10 +45,6 @@ function isVideoDurationValid (value: string) {return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.DURATION)}-function isVideoTruncatedDescriptionValid (value: string) {- return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.TRUNCATED_DESCRIPTION)-}-function isVideoDescriptionValid (value: string) {return value === null || (exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.DESCRIPTION))}@@ -151,7 +147,6 @@ export {isVideoCategoryValid,isVideoLicenceValid,isVideoLanguageValid,- isVideoTruncatedDescriptionValid,isVideoDescriptionValid,isVideoFileInfoHashValid,isVideoNameValid,diff --git a/server/models/video/formatter/video-format-utils.ts b/server/models/video/formatter/video-format-utils.tsindex 76745f4b5e..240619f695 100644--- a/server/models/video/formatter/video-format-utils.ts+++ b/server/models/video/formatter/video-format-utils.ts@@ -103,6 +103,7 @@ function videoModelToFormattedJSON (video: MVideoFormattable, options: VideoForm},nsfw: video.nsfw,+ truncatedDescription: video.getTruncatedDescription(),description: options && options.completeDescription === true? video.description: video.getTruncatedDescription(),@@ -181,6 +182,7 @@ function videoModelToFormattedDetailsJSON (video: MVideoFormattableDetails): Vidconst span = tracer.startSpan('peertube.VideoModel.toFormattedDetailsJSON')const videoJSON = video.toFormattedJSON({+ completeDescription: true,additionalAttributes: {scheduledUpdate: true,blacklistInfo: true,diff --git a/server/tests/api/videos/video-description.ts b/server/tests/api/videos/video-description.tsindex a4b3ff6e73..c4185882a3 100644--- a/server/tests/api/videos/video-description.ts+++ b/server/tests/api/videos/video-description.ts@@ -14,8 +14,12 @@ describe('Test video description', function () {let servers: PeerTubeServer[] = []let videoUUID = ''let videoId: number+const longDescription = 'my super description for server 1'.repeat(50)+ // 30 characters * 6 -> 240 characters+ const truncatedDescription = 'my super description for server 1'.repeat(7) + 'my super descrip...'+before(async function () {this.timeout(40000)@@ -45,15 +49,22 @@ describe('Test video description', function () {videoUUID = data[0].uuid})- it('Should have a truncated description on each server', async function () {+ it('Should have a truncated description on each server when listing videos', async function () {for (const server of servers) {- const video = await server.videos.get({ id: videoUUID })-- // 30 characters * 6 -> 240 characters- const truncatedDescription = 'my super description for server 1'.repeat(7) +- 'my super descrip...'+ const { data } = await server.videos.list()+ const video = data.find(v => v.uuid === videoUUID)expect(video.description).to.equal(truncatedDescription)+ expect(video.truncatedDescription).to.equal(truncatedDescription)+ }+ })++ it('Should not have a truncated description on each server when getting videos', async function () {+ for (const server of servers) {+ const video = await server.videos.get({ id: videoUUID })++ expect(video.description).to.equal(longDescription)+ expect(video.truncatedDescription).to.equal(truncatedDescription)}})diff --git a/shared/models/videos/video.model.ts b/shared/models/videos/video.model.tsindex d9765dbd64..06ffb327c7 100644--- a/shared/models/videos/video.model.ts+++ b/shared/models/videos/video.model.ts@@ -20,7 +20,11 @@ export interface Video {licence: VideoConstant<number>language: VideoConstant<string>privacy: VideoConstant<VideoPrivacy>++ // Deprecated in 5.0 in favour of truncatedDescriptiondescription: string+ truncatedDescription: string+duration: numberisLocal: booleanname: string@@ -70,7 +74,9 @@ export interface Video {}export interface VideoDetails extends Video {+ // Deprecated in 5.0descriptionPath: string+support: stringchannel: VideoChannelaccount: Account