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/remote/activitypub | |
| parent | :art: (diff) | |
| download | misskey-414f1d11582510f77ea3a927053fe68fa160278b.tar.gz misskey-414f1d11582510f77ea3a927053fe68fa160278b.tar.bz2 misskey-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/remote/activitypub')
| -rw-r--r-- | src/remote/activitypub/models/image.ts | 4 | ||||
| -rw-r--r-- | src/remote/activitypub/models/person.ts | 11 |
2 files changed, 4 insertions, 11 deletions
diff --git a/src/remote/activitypub/models/image.ts b/src/remote/activitypub/models/image.ts index cd28d59a16..89259d30fb 100644 --- a/src/remote/activitypub/models/image.ts +++ b/src/remote/activitypub/models/image.ts @@ -5,6 +5,8 @@ import { fetchMeta } from '@/misc/fetch-meta'; import { apLogger } from '../logger'; import { DriveFile } from '@/models/entities/drive-file'; import { DriveFiles } from '@/models/index'; +import { truncate } from '@/misc/truncate'; +import { DM_MAX_IMAGE_COMMENT_LENGTH } from '@/misc/hard-limits'; const logger = apLogger; @@ -28,7 +30,7 @@ export async function createImage(actor: IRemoteUser, value: any): Promise<Drive const instance = await fetchMeta(); const cache = instance.cacheRemoteFiles; - let file = await uploadFromUrl(image.url, actor, null, image.url, image.sensitive, false, !cache, image.name); + let file = await uploadFromUrl(image.url, actor, null, image.url, image.sensitive, false, !cache, truncate(image.name, DB_MAX_IMAGE_COMMENT_LENGTH)); if (file.isLink) { // URLが異なっている場合、同じ画像が以前に異なるURLで登録されていたということなので、 diff --git a/src/remote/activitypub/models/person.ts b/src/remote/activitypub/models/person.ts index 4823def7cb..84b2f0c51c 100644 --- a/src/remote/activitypub/models/person.ts +++ b/src/remote/activitypub/models/person.ts @@ -28,22 +28,13 @@ import { getConnection } from 'typeorm'; import { toArray } from '@/prelude/array'; import { fetchInstanceMetadata } from '@/services/fetch-instance-metadata'; import { normalizeForSearch } from '@/misc/normalize-for-search'; +import { truncate } from '@/misc/truncate'; const logger = apLogger; const nameLength = 128; const summaryLength = 2048; -function truncate(input: string, size: number): string; -function truncate(input: string | undefined, size: number): string | undefined; -function truncate(input: string | undefined, size: number): string | undefined { - if (!input || input.length <= size) { - return input; - } else { - return input.substring(0, size); - } -} - /** * Validate and convert to actor object * @param x Fetched object |