Fix issues with truncated description and utf characters

This commit is contained in:
Chocobozzz 2018-03-21 15:00:58 +01:00
parent a3cffab42d
commit bffbebbe6b
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 14 additions and 7 deletions

View File

@ -16,7 +16,6 @@ function retryTransactionWrapper <T> (
.catch(err => callback(err))
})
.catch(err => {
console.error(err)
logger.error(options.errorMessage, err)
throw err
})

View File

@ -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 })
}
}
}

View File

@ -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) {

View File

@ -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)
}