Browse Source

Federate entire description

Introduce an explicit field truncatedDescription
description in video list is deprecated
description in video get will contain the entire description
develop
Chocobozzz 1 week ago
parent
commit
f713f36bdf
No known key found for this signature in database GPG Key ID: 583A612D890159BE
8 changed files with 58 additions and 32 deletions
  1. +1
    -1
      client/src/app/+videos/+video-watch/shared/metadata/video-description.component.html
  2. +24
    -15
      client/src/app/+videos/+video-watch/shared/metadata/video-description.component.ts
  3. +3
    -0
      client/src/app/shared/shared-main/video/video.model.ts
  4. +5
    -5
      server/helpers/custom-validators/activitypub/videos.ts
  5. +0
    -5
      server/helpers/custom-validators/videos.ts
  6. +2
    -0
      server/models/video/formatter/video-format-utils.ts
  7. +17
    -6
      server/tests/api/videos/video-description.ts
  8. +6
    -0
      shared/models/videos/video.model.ts

+ 1
- 1
client/src/app/+videos/+video-watch/shared/metadata/video-description.component.html View File

@@ -1,7 +1,7 @@
<div class="video-info-description">
<div
class="video-info-description-html"
[innerHTML]="videoHTMLDescription"
[innerHTML]="getHTMLDescription()"
(timestampClicked)="onTimestampClicked($event)"
myTimestampRouteTransformer
></div>


+ 24
- 15
client/src/app/+videos/+video-watch/shared/metadata/video-description.component.ts View File

@@ -15,8 +15,10 @@ export class VideoDescriptionComponent implements OnChanges {

descriptionLoading = false
completeDescriptionShown = false
completeVideoDescription: string
shortVideoDescription: string

completeVideoDescriptionLoaded = false

videoHTMLTruncatedDescription = ''
videoHTMLDescription = ''

constructor (
@@ -28,22 +30,19 @@ export class VideoDescriptionComponent implements OnChanges {
ngOnChanges () {
this.descriptionLoading = false
this.completeDescriptionShown = false
this.completeVideoDescription = undefined

this.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 = true
this.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)
}
}
}

+ 3
- 0
client/src/app/shared/shared-main/video/video.model.ts View File

@@ -34,6 +34,7 @@ export class Video implements VideoServerModel {
language: VideoConstant<string>
privacy: VideoConstant<VideoPrivacy>

truncatedDescription: string
description: string

duration: number
@@ -134,6 +135,8 @@ export class Video implements VideoServerModel {
this.privacy = hash.privacy
this.waitTranscoding = hash.waitTranscoding
this.state = hash.state

this.truncatedDescription = hash.truncatedDescription
this.description = hash.description

this.isLive = hash.isLive


+ 5
- 5
server/helpers/custom-validators/activitypub/videos.ts View File

@@ -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 true


+ 0
- 5
server/helpers/custom-validators/videos.ts View File

@@ -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,


+ 2
- 0
server/models/video/formatter/video-format-utils.ts View File

@@ -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): Vid
const span = tracer.startSpan('peertube.VideoModel.toFormattedDetailsJSON')

const videoJSON = video.toFormattedJSON({
completeDescription: true,
additionalAttributes: {
scheduledUpdate: true,
blacklistInfo: true,


+ 17
- 6
server/tests/api/videos/video-description.ts View File

@@ -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)
}
})



+ 6
- 0
shared/models/videos/video.model.ts View File

@@ -20,7 +20,11 @@ export interface Video {
licence: VideoConstant<number>
language: VideoConstant<string>
privacy: VideoConstant<VideoPrivacy>

// Deprecated in 5.0 in favour of truncatedDescription
description: string
truncatedDescription: string

duration: number
isLocal: boolean
name: string
@@ -70,7 +74,9 @@ export interface Video {
}

export interface VideoDetails extends Video {
// Deprecated in 5.0
descriptionPath: string

support: string
channel: VideoChannel
account: Account


Loading…
Cancel
Save