aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/helpers/core-utils.ts9
-rw-r--r--server/helpers/custom-validators/activitypub/actor.ts4
-rw-r--r--server/helpers/custom-validators/activitypub/videos.ts2
-rw-r--r--server/helpers/youtube-dl.ts21
-rw-r--r--server/models/video/video.ts2
5 files changed, 17 insertions, 21 deletions
diff --git a/server/helpers/core-utils.ts b/server/helpers/core-utils.ts
index 9ff67c43a..7e8252aa4 100644
--- a/server/helpers/core-utils.ts
+++ b/server/helpers/core-utils.ts
@@ -179,18 +179,15 @@ function buildPath (path: string) {
179} 179}
180 180
181// Consistent with .length, lodash truncate function is not 181// Consistent with .length, lodash truncate function is not
182function peertubeTruncate (str: string, maxLength: number) { 182function peertubeTruncate (str: string, options: { length: number, separator?: RegExp, omission?: string }) {
183 const options = {
184 length: maxLength
185 }
186 const truncatedStr = truncate(str, options) 183 const truncatedStr = truncate(str, options)
187 184
188 // The truncated string is okay, we can return it 185 // The truncated string is okay, we can return it
189 if (truncatedStr.length <= maxLength) return truncatedStr 186 if (truncatedStr.length <= options.length) return truncatedStr
190 187
191 // Lodash takes into account all UTF characters, whereas String.prototype.length does not: some characters have a length of 2 188 // Lodash takes into account all UTF characters, whereas String.prototype.length does not: some characters have a length of 2
192 // We always use the .length so we need to truncate more if needed 189 // We always use the .length so we need to truncate more if needed
193 options.length -= truncatedStr.length - maxLength 190 options.length -= truncatedStr.length - options.length
194 return truncate(str, options) 191 return truncate(str, options)
195} 192}
196 193
diff --git a/server/helpers/custom-validators/activitypub/actor.ts b/server/helpers/custom-validators/activitypub/actor.ts
index 55bc8cc96..4e9aabf0e 100644
--- a/server/helpers/custom-validators/activitypub/actor.ts
+++ b/server/helpers/custom-validators/activitypub/actor.ts
@@ -1,9 +1,9 @@
1import * as validator from 'validator' 1import * as validator from 'validator'
2import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' 2import { CONSTRAINTS_FIELDS } from '../../../initializers/constants'
3import { exists, isArray } from '../misc' 3import { exists, isArray } from '../misc'
4import { truncate } from 'lodash'
5import { isActivityPubUrlValid, isBaseActivityValid, setValidAttributedTo } from './misc' 4import { isActivityPubUrlValid, isBaseActivityValid, setValidAttributedTo } from './misc'
6import { isHostValid } from '../servers' 5import { isHostValid } from '../servers'
6import { peertubeTruncate } from '@server/helpers/core-utils'
7 7
8function isActorEndpointsObjectValid (endpointObject: any) { 8function isActorEndpointsObjectValid (endpointObject: any) {
9 return isActivityPubUrlValid(endpointObject.sharedInbox) 9 return isActivityPubUrlValid(endpointObject.sharedInbox)
@@ -88,7 +88,7 @@ function normalizeActor (actor: any) {
88 } 88 }
89 89
90 if (actor.summary && typeof actor.summary === 'string') { 90 if (actor.summary && typeof actor.summary === 'string') {
91 actor.summary = truncate(actor.summary, { length: CONSTRAINTS_FIELDS.USERS.DESCRIPTION.max }) 91 actor.summary = peertubeTruncate(actor.summary, { length: CONSTRAINTS_FIELDS.USERS.DESCRIPTION.max })
92 92
93 if (actor.summary.length < CONSTRAINTS_FIELDS.USERS.DESCRIPTION.min) { 93 if (actor.summary.length < CONSTRAINTS_FIELDS.USERS.DESCRIPTION.min) {
94 actor.summary = null 94 actor.summary = null
diff --git a/server/helpers/custom-validators/activitypub/videos.ts b/server/helpers/custom-validators/activitypub/videos.ts
index 3ba6b0744..02f914326 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) {
155 155
156function setRemoteVideoTruncatedContent (video: any) { 156function setRemoteVideoTruncatedContent (video: any) {
157 if (video.content) { 157 if (video.content) {
158 video.content = peertubeTruncate(video.content, CONSTRAINTS_FIELDS.VIDEOS.TRUNCATED_DESCRIPTION.max) 158 video.content = peertubeTruncate(video.content, { length: CONSTRAINTS_FIELDS.VIDEOS.TRUNCATED_DESCRIPTION.max })
159 } 159 }
160 160
161 return true 161 return true
diff --git a/server/helpers/youtube-dl.ts b/server/helpers/youtube-dl.ts
index b3079370f..87a0d0584 100644
--- a/server/helpers/youtube-dl.ts
+++ b/server/helpers/youtube-dl.ts
@@ -1,10 +1,9 @@
1import { truncate } from 'lodash'
2import { CONSTRAINTS_FIELDS, VIDEO_CATEGORIES } from '../initializers/constants' 1import { CONSTRAINTS_FIELDS, VIDEO_CATEGORIES } from '../initializers/constants'
3import { logger } from './logger' 2import { logger } from './logger'
4import { generateVideoImportTmpPath } from './utils' 3import { generateVideoImportTmpPath } from './utils'
5import { join } from 'path' 4import { join } from 'path'
6import { root } from './core-utils' 5import { peertubeTruncate, root } from './core-utils'
7import { ensureDir, writeFile, remove } from 'fs-extra' 6import { ensureDir, remove, writeFile } from 'fs-extra'
8import * as request from 'request' 7import * as request from 'request'
9import { createWriteStream } from 'fs' 8import { createWriteStream } from 'fs'
10 9
@@ -212,20 +211,20 @@ function buildVideoInfo (obj: any) {
212} 211}
213 212
214function titleTruncation (title: string) { 213function titleTruncation (title: string) {
215 return truncate(title, { 214 return peertubeTruncate(title, {
216 'length': CONSTRAINTS_FIELDS.VIDEOS.NAME.max, 215 length: CONSTRAINTS_FIELDS.VIDEOS.NAME.max,
217 'separator': /,? +/, 216 separator: /,? +/,
218 'omission': ' […]' 217 omission: ' […]'
219 }) 218 })
220} 219}
221 220
222function descriptionTruncation (description: string) { 221function descriptionTruncation (description: string) {
223 if (!description || description.length < CONSTRAINTS_FIELDS.VIDEOS.DESCRIPTION.min) return undefined 222 if (!description || description.length < CONSTRAINTS_FIELDS.VIDEOS.DESCRIPTION.min) return undefined
224 223
225 return truncate(description, { 224 return peertubeTruncate(description, {
226 'length': CONSTRAINTS_FIELDS.VIDEOS.DESCRIPTION.max, 225 length: CONSTRAINTS_FIELDS.VIDEOS.DESCRIPTION.max,
227 'separator': /,? +/, 226 separator: /,? +/,
228 'omission': ' […]' 227 omission: ' […]'
229 }) 228 })
230} 229}
231 230
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 6856dcd9f..0ee3feaf3 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -1920,7 +1920,7 @@ export class VideoModel extends Model<VideoModel> {
1920 if (!this.description) return null 1920 if (!this.description) return null
1921 1921
1922 const maxLength = CONSTRAINTS_FIELDS.VIDEOS.TRUNCATED_DESCRIPTION.max 1922 const maxLength = CONSTRAINTS_FIELDS.VIDEOS.TRUNCATED_DESCRIPTION.max
1923 return peertubeTruncate(this.description, maxLength) 1923 return peertubeTruncate(this.description, { length: maxLength })
1924 } 1924 }
1925 1925
1926 getOriginalFileResolution () { 1926 getOriginalFileResolution () {