diff options
| author | Johann150 <johann.galle@protonmail.com> | 2021-09-29 18:44:22 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-30 01:44:22 +0900 |
| commit | 414f1d11582510f77ea3a927053fe68fa160278b (patch) | |
| tree | 406a8299b6eff7a7c63175d1adce18e4ccb3dfad /src/server/api | |
| parent | :art: (diff) | |
| download | sharkey-414f1d11582510f77ea3a927053fe68fa160278b.tar.gz sharkey-414f1d11582510f77ea3a927053fe68fa160278b.tar.bz2 sharkey-414f1d11582510f77ea3a927053fe68fa160278b.zip | |
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 <me@nullob.si>
* 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 <me@nullob.si>
Diffstat (limited to 'src/server/api')
| -rw-r--r-- | src/server/api/endpoints/drive/files/update.ts | 3 | ||||
| -rw-r--r-- | src/server/api/endpoints/drive/files/upload-from-url.ts | 3 |
2 files changed, 4 insertions, 2 deletions
diff --git a/src/server/api/endpoints/drive/files/update.ts b/src/server/api/endpoints/drive/files/update.ts index 1ef445625c..f277a9c3dc 100644 --- a/src/server/api/endpoints/drive/files/update.ts +++ b/src/server/api/endpoints/drive/files/update.ts @@ -4,6 +4,7 @@ import { publishDriveStream } from '@/services/stream'; import define from '../../../define'; import { ApiError } from '../../../error'; import { DriveFiles, DriveFolders } from '@/models/index'; +import { DB_MAX_IMAGE_COMMENT_LENGTH } from '@/misc/hard-limits'; export const meta = { tags: ['drive'], @@ -33,7 +34,7 @@ export const meta = { }, comment: { - validator: $.optional.nullable.str, + validator: $.optional.nullable.str.max(DB_MAX_IMAGE_COMMENT_LENGTH), default: undefined as any, } }, diff --git a/src/server/api/endpoints/drive/files/upload-from-url.ts b/src/server/api/endpoints/drive/files/upload-from-url.ts index f37f316efb..9f10a42d24 100644 --- a/src/server/api/endpoints/drive/files/upload-from-url.ts +++ b/src/server/api/endpoints/drive/files/upload-from-url.ts @@ -5,6 +5,7 @@ import uploadFromUrl from '@/services/drive/upload-from-url'; import define from '../../../define'; import { DriveFiles } from '@/models/index'; import { publishMainStream } from '@/services/stream'; +import { DB_MAX_IMAGE_COMMENT_LENGTH } from '@/misc/hard-limits'; export const meta = { tags: ['drive'], @@ -35,7 +36,7 @@ export const meta = { }, comment: { - validator: $.optional.nullable.str, + validator: $.optional.nullable.str.max(DB_MAX_IMAGE_COMMENT_LENGTH), default: null, }, |