chore: exclude local resource artifacts from main sync
This commit is contained in:
@@ -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 [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user