diff options
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/video/video.ts | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index a28b5209b..7c56c65a6 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
2 | import { map, maxBy, truncate } from 'lodash' | 2 | import { map, maxBy } from 'lodash' |
3 | import * as magnetUtil from 'magnet-uri' | 3 | import * as magnetUtil from 'magnet-uri' |
4 | import * as parseTorrent from 'parse-torrent' | 4 | import * as parseTorrent from 'parse-torrent' |
5 | import { join } from 'path' | 5 | import { join } from 'path' |
@@ -31,7 +31,10 @@ import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' | |||
31 | import { Video, VideoDetails } from '../../../shared/models/videos' | 31 | import { Video, VideoDetails } from '../../../shared/models/videos' |
32 | import { VideoFilter } from '../../../shared/models/videos/video-query.type' | 32 | import { VideoFilter } from '../../../shared/models/videos/video-query.type' |
33 | import { activityPubCollection } from '../../helpers/activitypub' | 33 | import { activityPubCollection } from '../../helpers/activitypub' |
34 | import { createTorrentPromise, renamePromise, statPromise, unlinkPromise, writeFilePromise } from '../../helpers/core-utils' | 34 | import { |
35 | createTorrentPromise, peertubeTruncate, renamePromise, statPromise, unlinkPromise, | ||
36 | writeFilePromise | ||
37 | } from '../../helpers/core-utils' | ||
35 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 38 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
36 | import { isBooleanValid } from '../../helpers/custom-validators/misc' | 39 | import { isBooleanValid } from '../../helpers/custom-validators/misc' |
37 | import { | 40 | import { |
@@ -1191,19 +1194,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1191 | if (!this.description) return null | 1194 | if (!this.description) return null |
1192 | 1195 | ||
1193 | const maxLength = CONSTRAINTS_FIELDS.VIDEOS.TRUNCATED_DESCRIPTION.max | 1196 | const maxLength = CONSTRAINTS_FIELDS.VIDEOS.TRUNCATED_DESCRIPTION.max |
1194 | 1197 | return peertubeTruncate(this.description, maxLength) | |
1195 | const options = { | ||
1196 | length: maxLength | ||
1197 | } | ||
1198 | const truncatedDescription = truncate(this.description, options) | ||
1199 | |||
1200 | // The truncated string is okay, we can return it | ||
1201 | if (truncatedDescription.length <= maxLength) return truncatedDescription | ||
1202 | |||
1203 | // Lodash takes into account all UTF characters, whereas String.prototype.length does not: some characters have a length of 2 | ||
1204 | // We always use the .length so we need to truncate more if needed | ||
1205 | options.length -= maxLength - truncatedDescription.length | ||
1206 | return truncate(this.description, options) | ||
1207 | } | 1198 | } |
1208 | 1199 | ||
1209 | optimizeOriginalVideofile = async function () { | 1200 | optimizeOriginalVideofile = async function () { |