Фикс предпросмотра файлов с абсолютными self-URL
- extractFileKey понимает абсолютные URL (по pathname) — превью работает для уже записанных файлов - normalizeFileUrl: абсолютные self-URL нормализуются в относительные при записи file-полей (REST field-values, MCP update_task_fields/upload-инструменты, bot-api, create task)
This commit is contained in:
@@ -19,13 +19,22 @@ export function stripFileTokensFromHtml(html: string): string {
|
||||
}
|
||||
|
||||
// Extracts the file key from a local file URL.
|
||||
// Supports /api/files/:key and /uploads/:key patterns.
|
||||
// Supports /api/files/:key and /uploads/:key patterns, including absolute
|
||||
// self-URLs (https://iistwin.ru/api/files/<key>) written by external agents via REST/MCP.
|
||||
export function extractFileKey(url: string): string | null {
|
||||
if (url.startsWith('/api/files/')) {
|
||||
return url.slice('/api/files/'.length).split('?')[0];
|
||||
let path = url;
|
||||
if (url.startsWith('http://') || url.startsWith('https://')) {
|
||||
try {
|
||||
path = new URL(url).pathname;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (url.startsWith('/uploads/')) {
|
||||
return url.slice('/uploads/'.length).split('?')[0];
|
||||
if (path.startsWith('/api/files/')) {
|
||||
return path.slice('/api/files/'.length).split('?')[0];
|
||||
}
|
||||
if (path.startsWith('/uploads/')) {
|
||||
return path.slice('/uploads/'.length).split('?')[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user