Fix federation issue with some actor descriptions
This commit is contained in:
parent
4386e66e55
commit
687c6180bc
|
@ -179,18 +179,15 @@ function buildPath (path: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Consistent with .length, lodash truncate function is not
|
// Consistent with .length, lodash truncate function is not
|
||||||
function peertubeTruncate (str: string, maxLength: number) {
|
function peertubeTruncate (str: string, options: { length: number, separator?: RegExp, omission?: string }) {
|
||||||
const options = {
|
|
||||||
length: maxLength
|
|
||||||
}
|
|
||||||
const truncatedStr = truncate(str, options)
|
const truncatedStr = truncate(str, options)
|
||||||
|
|
||||||
// The truncated string is okay, we can return it
|
// The truncated string is okay, we can return it
|
||||||
if (truncatedStr.length <= maxLength) return truncatedStr
|
if (truncatedStr.length <= options.length) return truncatedStr
|
||||||
|
|
||||||
// Lodash takes into account all UTF characters, whereas String.prototype.length does not: some characters have a length of 2
|
// Lodash takes into account all UTF characters, whereas String.prototype.length does not: some characters have a length of 2
|
||||||
// We always use the .length so we need to truncate more if needed
|
// We always use the .length so we need to truncate more if needed
|
||||||
options.length -= truncatedStr.length - maxLength
|
options.length -= truncatedStr.length - options.length
|
||||||
return truncate(str, options)
|
return truncate(str, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import * as validator from 'validator'
|
import * as validator from 'validator'
|
||||||
import { CONSTRAINTS_FIELDS } from '../../../initializers/constants'
|
import { CONSTRAINTS_FIELDS } from '../../../initializers/constants'
|
||||||
import { exists, isArray } from '../misc'
|
import { exists, isArray } from '../misc'
|
||||||
import { truncate } from 'lodash'
|
|
||||||
import { isActivityPubUrlValid, isBaseActivityValid, setValidAttributedTo } from './misc'
|
import { isActivityPubUrlValid, isBaseActivityValid, setValidAttributedTo } from './misc'
|
||||||
import { isHostValid } from '../servers'
|
import { isHostValid } from '../servers'
|
||||||
|
import { peertubeTruncate } from '@server/helpers/core-utils'
|
||||||
|
|
||||||
function isActorEndpointsObjectValid (endpointObject: any) {
|
function isActorEndpointsObjectValid (endpointObject: any) {
|
||||||
return isActivityPubUrlValid(endpointObject.sharedInbox)
|
return isActivityPubUrlValid(endpointObject.sharedInbox)
|
||||||
|
@ -88,7 +88,7 @@ function normalizeActor (actor: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actor.summary && typeof actor.summary === 'string') {
|
if (actor.summary && typeof actor.summary === 'string') {
|
||||||
actor.summary = truncate(actor.summary, { length: CONSTRAINTS_FIELDS.USERS.DESCRIPTION.max })
|
actor.summary = peertubeTruncate(actor.summary, { length: CONSTRAINTS_FIELDS.USERS.DESCRIPTION.max })
|
||||||
|
|
||||||
if (actor.summary.length < CONSTRAINTS_FIELDS.USERS.DESCRIPTION.min) {
|
if (actor.summary.length < CONSTRAINTS_FIELDS.USERS.DESCRIPTION.min) {
|
||||||
actor.summary = null
|
actor.summary = null
|
||||||
|
|
|
@ -155,7 +155,7 @@ function setValidRemoteVideoUrls (video: any) {
|
||||||
|
|
||||||
function setRemoteVideoTruncatedContent (video: any) {
|
function setRemoteVideoTruncatedContent (video: any) {
|
||||||
if (video.content) {
|
if (video.content) {
|
||||||
video.content = peertubeTruncate(video.content, CONSTRAINTS_FIELDS.VIDEOS.TRUNCATED_DESCRIPTION.max)
|
video.content = peertubeTruncate(video.content, { length: CONSTRAINTS_FIELDS.VIDEOS.TRUNCATED_DESCRIPTION.max })
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
import { truncate } from 'lodash'
|
|
||||||
import { CONSTRAINTS_FIELDS, VIDEO_CATEGORIES } from '../initializers/constants'
|
import { CONSTRAINTS_FIELDS, VIDEO_CATEGORIES } from '../initializers/constants'
|
||||||
import { logger } from './logger'
|
import { logger } from './logger'
|
||||||
import { generateVideoImportTmpPath } from './utils'
|
import { generateVideoImportTmpPath } from './utils'
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
import { root } from './core-utils'
|
import { peertubeTruncate, root } from './core-utils'
|
||||||
import { ensureDir, writeFile, remove } from 'fs-extra'
|
import { ensureDir, remove, writeFile } from 'fs-extra'
|
||||||
import * as request from 'request'
|
import * as request from 'request'
|
||||||
import { createWriteStream } from 'fs'
|
import { createWriteStream } from 'fs'
|
||||||
|
|
||||||
|
@ -212,20 +211,20 @@ function buildVideoInfo (obj: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function titleTruncation (title: string) {
|
function titleTruncation (title: string) {
|
||||||
return truncate(title, {
|
return peertubeTruncate(title, {
|
||||||
'length': CONSTRAINTS_FIELDS.VIDEOS.NAME.max,
|
length: CONSTRAINTS_FIELDS.VIDEOS.NAME.max,
|
||||||
'separator': /,? +/,
|
separator: /,? +/,
|
||||||
'omission': ' […]'
|
omission: ' […]'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function descriptionTruncation (description: string) {
|
function descriptionTruncation (description: string) {
|
||||||
if (!description || description.length < CONSTRAINTS_FIELDS.VIDEOS.DESCRIPTION.min) return undefined
|
if (!description || description.length < CONSTRAINTS_FIELDS.VIDEOS.DESCRIPTION.min) return undefined
|
||||||
|
|
||||||
return truncate(description, {
|
return peertubeTruncate(description, {
|
||||||
'length': CONSTRAINTS_FIELDS.VIDEOS.DESCRIPTION.max,
|
length: CONSTRAINTS_FIELDS.VIDEOS.DESCRIPTION.max,
|
||||||
'separator': /,? +/,
|
separator: /,? +/,
|
||||||
'omission': ' […]'
|
omission: ' […]'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1920,7 +1920,7 @@ export class VideoModel extends Model<VideoModel> {
|
||||||
if (!this.description) return null
|
if (!this.description) return null
|
||||||
|
|
||||||
const maxLength = CONSTRAINTS_FIELDS.VIDEOS.TRUNCATED_DESCRIPTION.max
|
const maxLength = CONSTRAINTS_FIELDS.VIDEOS.TRUNCATED_DESCRIPTION.max
|
||||||
return peertubeTruncate(this.description, maxLength)
|
return peertubeTruncate(this.description, { length: maxLength })
|
||||||
}
|
}
|
||||||
|
|
||||||
getOriginalFileResolution () {
|
getOriginalFileResolution () {
|
||||||
|
|
Loading…
Reference in New Issue