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>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user