ActivityPub-federated video streaming platform using P2P directly in your web browser
Fix federation issue with some actor descriptions
Chocobozzz687c6180bc5f
diff --git a/server/helpers/core-utils.ts b/server/helpers/core-utils.tsindex 9ff67c43af..7e8252aa40 100644--- a/server/helpers/core-utils.ts+++ b/server/helpers/core-utils.ts@@ -179,18 +179,15 @@ function buildPath (path: string) {}// Consistent with .length, lodash truncate function is not-function peertubeTruncate (str: string, maxLength: number) {- const options = {- length: maxLength- }+function peertubeTruncate (str: string, options: { length: number, separator?: RegExp, omission?: string }) {const truncatedStr = truncate(str, options)// 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// We always use the .length so we need to truncate more if needed- options.length -= truncatedStr.length - maxLength+ options.length -= truncatedStr.length - options.lengthreturn truncate(str, options)}diff --git a/server/helpers/custom-validators/activitypub/actor.ts b/server/helpers/custom-validators/activitypub/actor.tsindex 55bc8cc96c..4e9aabf0ed 100644--- a/server/helpers/custom-validators/activitypub/actor.ts+++ b/server/helpers/custom-validators/activitypub/actor.ts@@ -1,9 +1,9 @@import * as validator from 'validator'import { CONSTRAINTS_FIELDS } from '../../../initializers/constants'import { exists, isArray } from '../misc'-import { truncate } from 'lodash'import { isActivityPubUrlValid, isBaseActivityValid, setValidAttributedTo } from './misc'import { isHostValid } from '../servers'+import { peertubeTruncate } from '@server/helpers/core-utils'function isActorEndpointsObjectValid (endpointObject: any) {return isActivityPubUrlValid(endpointObject.sharedInbox)@@ -88,7 +88,7 @@ function normalizeActor (actor: any) {}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) {actor.summary = nulldiff --git a/server/helpers/custom-validators/activitypub/videos.ts b/server/helpers/custom-validators/activitypub/videos.tsindex 3ba6b07440..02f9143269 100644--- a/server/helpers/custom-validators/activitypub/videos.ts+++ b/server/helpers/custom-validators/activitypub/videos.ts@@ -155,7 +155,7 @@ function setValidRemoteVideoUrls (video: any) {function setRemoteVideoTruncatedContent (video: any) {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 truediff --git a/server/helpers/youtube-dl.ts b/server/helpers/youtube-dl.tsindex b3079370f0..87a0d0584e 100644--- a/server/helpers/youtube-dl.ts+++ b/server/helpers/youtube-dl.ts@@ -1,10 +1,9 @@-import { truncate } from 'lodash'import { CONSTRAINTS_FIELDS, VIDEO_CATEGORIES } from '../initializers/constants'import { logger } from './logger'import { generateVideoImportTmpPath } from './utils'import { join } from 'path'-import { root } from './core-utils'-import { ensureDir, writeFile, remove } from 'fs-extra'+import { peertubeTruncate, root } from './core-utils'+import { ensureDir, remove, writeFile } from 'fs-extra'import * as request from 'request'import { createWriteStream } from 'fs'@@ -212,20 +211,20 @@ function buildVideoInfo (obj: any) {}function titleTruncation (title: string) {- return truncate(title, {- 'length': CONSTRAINTS_FIELDS.VIDEOS.NAME.max,- 'separator': /,? +/,- 'omission': ' […]'+ return peertubeTruncate(title, {+ length: CONSTRAINTS_FIELDS.VIDEOS.NAME.max,+ separator: /,? +/,+ omission: ' […]'})}function descriptionTruncation (description: string) {if (!description || description.length < CONSTRAINTS_FIELDS.VIDEOS.DESCRIPTION.min) return undefined- return truncate(description, {- 'length': CONSTRAINTS_FIELDS.VIDEOS.DESCRIPTION.max,- 'separator': /,? +/,- 'omission': ' […]'+ return peertubeTruncate(description, {+ length: CONSTRAINTS_FIELDS.VIDEOS.DESCRIPTION.max,+ separator: /,? +/,+ omission: ' […]'})}diff --git a/server/models/video/video.ts b/server/models/video/video.tsindex 6856dcd9f0..0ee3feaf3d 100644--- a/server/models/video/video.ts+++ b/server/models/video/video.ts@@ -1920,7 +1920,7 @@ export class VideoModel extends Model<VideoModel> {if (!this.description) return nullconst maxLength = CONSTRAINTS_FIELDS.VIDEOS.TRUNCATED_DESCRIPTION.max- return peertubeTruncate(this.description, maxLength)+ return peertubeTruncate(this.description, { length: maxLength })}getOriginalFileResolution () {