]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix issues with truncated description and utf characters
authorChocobozzz <me@florianbigard.com>
Wed, 21 Mar 2018 14:00:58 +0000 (15:00 +0100)
committerChocobozzz <me@florianbigard.com>
Wed, 21 Mar 2018 14:00:58 +0000 (15:00 +0100)
server/helpers/database-utils.ts
server/lib/activitypub/process/process.ts
server/lib/activitypub/videos.ts
server/models/video/video.ts

index 31808f9e4b11dcfc3108437210f0e9f8ded3fe04..d09b4b245b60bb81ab3181933d8a52363e76335a 100644 (file)
@@ -16,7 +16,6 @@ function retryTransactionWrapper <T> (
         .catch(err => callback(err))
   })
   .catch(err => {
-    console.error(err)
     logger.error(options.errorMessage, err)
     throw err
   })
index 7edf3bba00b9212e8f88c113a7a693b53489e390..094219489fe2d77b7dcba2ef4be04fc8b5ad4737 100644 (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 })
     }
   }
 }
index e7b516129aa4a87b4d14db81acb155fe5aa1ad6f..907fe458d57ffa179e1d2de9ae133a1597629b6d 100644 (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) {
index 4e175c410ee2d9ab0633da2a8dda088e7ec30e47..f43b73e49c7d978151c87a645ef8cfa36dd3f366 100644 (file)
@@ -1166,10 +1166,19 @@ export class VideoModel extends Model<VideoModel> {
   getTruncatedDescription () {
     if (!this.description) return null
 
+    const maxLength = CONSTRAINTS_FIELDS.VIDEOS.TRUNCATED_DESCRIPTION.max
+
     const options = {
-      length: CONSTRAINTS_FIELDS.VIDEOS.TRUNCATED_DESCRIPTION.max
+      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)
   }