feat(web): connect quick share flow
Signed-off-by: JustMe <mr.toing@outlook.com>
This commit is contained in:
1 parent
53768a195d
commit
e02e024605
138 files changed
+10614
No files matched your search
@@ -0,0 +1,30 @@
|
||||
import { isLongText } from './fileKind';
|
||||
|
||||
/** 不大的视频才直接放进列表播放 */
|
||||
export const VIDEO_INLINE_MAX = 25 * 1024 * 1024;
|
||||
|
||||
const JSON_MAX_LINES = 14;
|
||||
const JSON_MAX_CHARS = 1200;
|
||||
const JSON_PARSE_MAX_CHARS = 100_000;
|
||||
|
||||
export interface TextView {
|
||||
json: boolean;
|
||||
/** 要显示的内容:JSON 已格式化 */
|
||||
body: string;
|
||||
/** 太长,列表里只显示前几行 */
|
||||
long: boolean;
|
||||
}
|
||||
|
||||
/** 文本与 JSON 的内联显示:能解析成对象或数组的当作 JSON 格式化,否则原样显示 */
|
||||
export function textView(text: string): TextView {
|
||||
const t = text.trim();
|
||||
if ((t.startsWith('{') || t.startsWith('[')) && t.length <= JSON_PARSE_MAX_CHARS) {
|
||||
try {
|
||||
const body = JSON.stringify(JSON.parse(t) as unknown, null, 2);
|
||||
return { json: true, body, long: body.split('\n').length > JSON_MAX_LINES || body.length > JSON_MAX_CHARS };
|
||||
} catch {
|
||||
/* 不是合法 JSON,按普通文本显示 */
|
||||
}
|
||||
}
|
||||
return { json: false, body: text, long: isLongText(text) };
|
||||
}
|
||||
Reference in new issue
Block a user