mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2024-12-02 05:19:17 -06:00
Fix issues with truncated description and utf characters
This commit is contained in:
parent
a3cffab42d
commit
bffbebbe6b
@ -16,7 +16,6 @@ function retryTransactionWrapper <T> (
|
||||
.catch(err => callback(err))
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
logger.error(options.errorMessage, err)
|
||||
throw err
|
||||
})
|
||||
|
@ -40,8 +40,7 @@ async function processActivities (activities: Activity[], signatureActor?: Actor
|
||||
try {
|
||||
await activityProcessor(activity, inboxActor)
|
||||
} catch (err) {
|
||||
logger.warn(err.stack)
|
||||
logger.warn('Cannot process activity %s.', activity.type, err)
|
||||
logger.warn('Cannot process activity %s.', activity.type, { error: err.stack })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ async function getOrCreateAccountAndVideoAndChannel (videoObject: VideoTorrentOb
|
||||
}
|
||||
|
||||
videoObject = await fetchRemoteVideo(videoObject)
|
||||
if (!videoObject) throw new Error('Cannot fetch remote video')
|
||||
if (!videoObject) throw new Error('Cannot fetch remote video (maybe invalid...)')
|
||||
}
|
||||
|
||||
if (!actor) {
|
||||
|
@ -1166,10 +1166,19 @@ export class VideoModel extends Model<VideoModel> {
|
||||
getTruncatedDescription () {
|
||||
if (!this.description) return null
|
||||
|
||||
const options = {
|
||||
length: CONSTRAINTS_FIELDS.VIDEOS.TRUNCATED_DESCRIPTION.max
|
||||
}
|
||||
const maxLength = CONSTRAINTS_FIELDS.VIDEOS.TRUNCATED_DESCRIPTION.max
|
||||
|
||||
const options = {
|
||||
length: maxLength
|
||||
}
|
||||
const truncatedDescription = truncate(this.description, options)
|
||||
|
||||
// The truncated string is okay, we can return it
|
||||
if (truncatedDescription.length <= maxLength) return truncatedDescription
|
||||
|
||||
// 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 -= maxLength - truncatedDescription.length
|
||||
return truncate(this.description, options)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user