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 => callback(err))
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error(err)
|
|
||||||
logger.error(options.errorMessage, err)
|
logger.error(options.errorMessage, err)
|
||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
|
|
|
@ -40,8 +40,7 @@ async function processActivities (activities: Activity[], signatureActor?: Actor
|
||||||
try {
|
try {
|
||||||
await activityProcessor(activity, inboxActor)
|
await activityProcessor(activity, inboxActor)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.warn(err.stack)
|
logger.warn('Cannot process activity %s.', activity.type, { error: err.stack })
|
||||||
logger.warn('Cannot process activity %s.', activity.type, err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,7 +187,7 @@ async function getOrCreateAccountAndVideoAndChannel (videoObject: VideoTorrentOb
|
||||||
}
|
}
|
||||||
|
|
||||||
videoObject = await fetchRemoteVideo(videoObject)
|
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) {
|
if (!actor) {
|
||||||
|
|
|
@ -1166,10 +1166,19 @@ export class VideoModel extends Model<VideoModel> {
|
||||||
getTruncatedDescription () {
|
getTruncatedDescription () {
|
||||||
if (!this.description) return null
|
if (!this.description) return null
|
||||||
|
|
||||||
const options = {
|
const maxLength = CONSTRAINTS_FIELDS.VIDEOS.TRUNCATED_DESCRIPTION.max
|
||||||
length: 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)
|
return truncate(this.description, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue