fix: add file size cap and error i18n keys for diff viewer (#1234)
- Add 512 KB cap for inline diff rendering to prevent DOM bloat on large patch files - Add diff_error and diff_too_large i18n keys in all 7 locales for clear error messages - Improve error state to show explanatory message instead of just filename - Addresses reviewer feedback on file size cap and missing diff_error i18n key
This commit is contained in:
1 parent
9a371f06f5
commit
1f602b47ec
2 files changed
+20
-1
No files matched your search
@@ -27,6 +27,8 @@ const LOCALES = {
|
||||
copy_failed: 'Copy failed',
|
||||
|
||||
diff_loading: 'Loading diff',
|
||||
diff_error: 'Could not load patch file',
|
||||
diff_too_large: 'Patch file too large to display inline',
|
||||
you: 'You',
|
||||
thinking: 'Thinking',
|
||||
expand_all: 'Expand all',
|
||||
@@ -719,6 +721,8 @@ const LOCALES = {
|
||||
copy_failed: '\u041e\u0448\u0438\u0431\u043a\u0430 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f',
|
||||
|
||||
diff_loading: 'Загрузка diff',
|
||||
diff_error: 'Не удалось загрузить файл патча',
|
||||
diff_too_large: 'Файл патча слишком большой для отображения',
|
||||
you: 'Вы',
|
||||
thinking: 'Думаю',
|
||||
expand_all: 'Развернуть всё',
|
||||
@@ -1360,6 +1364,8 @@ const LOCALES = {
|
||||
copy_failed: 'Error al copiar',
|
||||
|
||||
diff_loading: 'Cargando diff',
|
||||
diff_error: 'No se pudo cargar el archivo de parche',
|
||||
diff_too_large: 'Archivo de parche demasiado grande para mostrar',
|
||||
you: 'Tú',
|
||||
thinking: 'Pensando',
|
||||
expand_all: 'Expandir todo',
|
||||
@@ -1993,6 +1999,8 @@ const LOCALES = {
|
||||
copy_failed: 'Kopieren fehlgeschlagen',
|
||||
|
||||
diff_loading: 'Lade Diff',
|
||||
diff_error: 'Patch-Datei konnte nicht geladen werden',
|
||||
diff_too_large: 'Patch-Datei zu groß für Inline-Anzeige',
|
||||
you: 'Du',
|
||||
thinking: 'Nachdenken',
|
||||
expand_all: 'Alle ausklappen',
|
||||
@@ -2401,6 +2409,8 @@ const LOCALES = {
|
||||
copy_failed: '\u590d\u5236\u5931\u8d25',
|
||||
|
||||
diff_loading: '加载 diff',
|
||||
diff_error: '无法加载 patch 文件',
|
||||
diff_too_large: 'Patch 文件过大,无法内联显示',
|
||||
you: '\u4f60',
|
||||
thinking: '\u601d\u8003\u8fc7\u7a0b',
|
||||
expand_all: '\u5168\u90e8\u5c55\u5f00',
|
||||
@@ -3032,6 +3042,8 @@ const LOCALES = {
|
||||
copy_failed: '\u8907\u88fd\u5931\u6557',
|
||||
|
||||
diff_loading: '載入 diff',
|
||||
diff_error: '無法載入 patch 檔案',
|
||||
diff_too_large: 'Patch 檔案過大,無法內聯顯示',
|
||||
you: '\u4f60',
|
||||
thinking: '\u601d\u8003\u904e\u7a0b',
|
||||
expand_all: '\u5168\u90e8\u5c55\u958b',
|
||||
@@ -3712,6 +3724,8 @@ const LOCALES = {
|
||||
copy_failed: '복사 실패',
|
||||
|
||||
diff_loading: 'diff 불러오는 중',
|
||||
diff_error: '패치 파일을 로드할 수 없습니다',
|
||||
diff_too_large: '패치 파일이 너무 커서 인라인으로 표시할 수 없습니다',
|
||||
you: '나',
|
||||
thinking: '생각 중',
|
||||
expand_all: '모두 펼치기',
|
||||
|
||||
+6
-1
@@ -3151,12 +3151,17 @@ let _mermaidLoading=false;
|
||||
let _mermaidReady=false;
|
||||
|
||||
function loadDiffInline(){
|
||||
const DIFF_MAX_SIZE=512*1024; // 512 KB cap for inline diff rendering
|
||||
document.querySelectorAll('.diff-inline-load:not([data-loaded])').forEach(el=>{
|
||||
el.setAttribute('data-loaded','1');
|
||||
const path=el.dataset.path;
|
||||
fetch('api/media?path='+encodeURIComponent(path))
|
||||
.then(r=>{if(!r.ok) throw new Error(r.status);return r.text();})
|
||||
.then(text=>{
|
||||
if(text.length>DIFF_MAX_SIZE){
|
||||
el.outerHTML=`<div class="diff-inline-error">${esc(path.split('/').pop())}<br><span style="color:var(--muted);font-size:12px">${t('diff_too_large')}</span></div>`;
|
||||
return;
|
||||
}
|
||||
const lines=text.split('\n').map(line=>{
|
||||
const e=esc(line);
|
||||
if(e.startsWith('@@')) return `<span class="diff-line diff-hunk">${e}</span>`;
|
||||
@@ -3167,7 +3172,7 @@ function loadDiffInline(){
|
||||
el.outerHTML=`<div class="diff-inline"><div class="pre-header">${esc(path.split('/').pop())}</div><pre class="diff-block"><code>${lines}</code></pre></div>`;
|
||||
})
|
||||
.catch(()=>{
|
||||
el.outerHTML=`<div class="diff-inline-error">${esc(path.split('/').pop())}</div>`;
|
||||
el.outerHTML=`<div class="diff-inline-error">${esc(path.split('/').pop())}<br><span style="color:var(--muted);font-size:12px">${t('diff_error')}</span></div>`;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user