From 414f1d11582510f77ea3a927053fe68fa160278b Mon Sep 17 00:00:00 2001 From: Johann150 Date: Wed, 29 Sep 2021 18:44:22 +0200 Subject: [PATCH] fix: truncate image descriptions (#7699) * move truncate function to separate file to reuse it * truncate image descriptions * show image description limit in UI * correctly treat null Co-authored-by: nullobsi * make truncate Unicode-aware The strings that truncate returns should now be valid Unicode. PostgreSQL also counts Unicode Code Points instead of bytes so this should be correct. * move truncate to internal, validate in API Truncating could also be done in src/services/drive/add-file.ts or src/services/drive/upload-from-url.ts but those would also affect local images. But local images should result in a hard error if the image comment is too long. * avoid overwriting Co-authored-by: nullobsi --- src/client/components/media-caption.vue | 30 ++++++++++++++++--- src/misc/hard-limits.ts | 6 ++++ src/misc/truncate.ts | 11 +++++++ src/remote/activitypub/models/image.ts | 4 ++- src/remote/activitypub/models/person.ts | 11 +------ .../api/endpoints/drive/files/update.ts | 3 +- .../endpoints/drive/files/upload-from-url.ts | 3 +- 7 files changed, 51 insertions(+), 17 deletions(-) create mode 100644 src/misc/truncate.ts diff --git a/src/client/components/media-caption.vue b/src/client/components/media-caption.vue index 690927d4c..73eba2302 100644 --- a/src/client/components/media-caption.vue +++ b/src/client/components/media-caption.vue @@ -3,10 +3,13 @@
-
+
+ + {{ remainingLength }} +
- {{ $ts.ok }} + {{ $ts.ok }} {{ $ts.cancel }}
@@ -26,10 +29,12 @@