chore: exclude local resource artifacts from main sync

This commit is contained in:
2026-05-15 10:16:45 +09:00
parent 442879313f
commit d38d022872
504 changed files with 17074 additions and 3642 deletions

View File

@@ -1,51 +1,4 @@
const AUTO_DETECTED_PREVIEW_URL_PATTERN =
/(https?:\/\/[^\s<>)\]]+|\/(?:[A-Za-z0-9._~%-][A-Za-z0-9._~:/?#[\]@!$&'*+,;=%-]*))/g;
const LOCAL_RESOURCE_PREFIXES = ['/api/chat/resources/', '/public/.codex_chat/', '/.codex_chat/'] as const;
const PREVIEWABLE_FILE_EXTENSION_PATTERN =
/\.(png|jpe?g|gif|webp|svg|bmp|ico|mp4|webm|mov|m4v|ogg|md|markdown|diff|patch|ts|tsx|js|jsx|json|css|scss|html|xml|java|kt|sql|sh|py|go|rs|c|cpp|h|hpp|yml|yaml|txt|log|csv|pdf)$/i;
function stripCodeFenceBlocks(text: string) {
return String(text ?? '').replace(/```[\s\S]*?```/g, '');
}
function trimAutoDetectedUrl(value: string) {
return String(value ?? '').trim().replace(/[`\])}>.,;!?]+$/g, '');
}
function isLikelyLocalPreviewUrl(value: string) {
if (LOCAL_RESOURCE_PREFIXES.some((prefix) => value.startsWith(prefix))) {
return true;
}
const pathname = value.split(/[?#]/, 1)[0] ?? '';
return PREVIEWABLE_FILE_EXTENSION_PATTERN.test(pathname);
}
export function extractAutoDetectedPreviewUrls(text: string) {
const normalized = stripCodeFenceBlocks(text);
const urls: string[] = [];
for (const match of normalized.matchAll(AUTO_DETECTED_PREVIEW_URL_PATTERN)) {
const value = trimAutoDetectedUrl(match[0] ?? '');
if (!value) {
continue;
}
const startIndex = match.index ?? -1;
const previousChar = startIndex > 0 ? normalized[startIndex - 1] : '';
// Ignore HTML closing tags like </div> that were being misread as same-origin routes.
if (previousChar === '<') {
continue;
}
if (value.startsWith('/') && !isLikelyLocalPreviewUrl(value)) {
continue;
}
urls.push(value);
}
return urls;
void text;
return [];
}