0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-05-08 05:54:09 +02:00

Compress code and add error handling for fetchBlobExcerpt

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
silverwind 2026-02-18 07:39:00 +01:00
parent 0fc9c4e6a4
commit c8b2dcde09
No known key found for this signature in database
GPG Key ID: 2E62B41C93869443

View File

@ -258,9 +258,7 @@ async function onLocationHashChange() {
const attrAutoLoadClicked = 'data-auto-load-clicked'; const attrAutoLoadClicked = 'data-auto-load-clicked';
if (expandButton.hasAttribute(attrAutoLoadClicked)) return; if (expandButton.hasAttribute(attrAutoLoadClicked)) return;
expandButton.setAttribute(attrAutoLoadClicked, 'true'); expandButton.setAttribute(attrAutoLoadClicked, 'true');
const tr = expandButton.closest('tr')!; await fetchBlobExcerpt(expandButton.closest('tr')!, expandButton.getAttribute('data-url')!);
const url = expandButton.getAttribute('data-url')!;
await fetchBlobExcerpt(tr, url);
continue; // Try again to find the element continue; // Try again to find the element
} }
} }
@ -285,13 +283,13 @@ function initRepoDiffHashChangeListener() {
const expandAllSavedState = new Map<string, HTMLElement>(); const expandAllSavedState = new Map<string, HTMLElement>();
async function fetchBlobExcerpt(tr: Element, url: string): Promise<void> { async function fetchBlobExcerpt(tr: Element, url: string): Promise<void> {
const resp = await GET(url); try {
const text = await resp.text(); const tempTbody = document.createElement('tbody');
// Parse <tr> elements in proper table context tempTbody.innerHTML = await (await GET(url)).text();
const tempTbody = document.createElement('tbody'); tr.replaceWith(...tempTbody.children);
tempTbody.innerHTML = text; } catch (error) {
const nodes = Array.from(tempTbody.children); console.error('Error:', error);
tr.replaceWith(...nodes); }
} }
async function expandAllLines(btn: HTMLElement, fileBox: HTMLElement) { async function expandAllLines(btn: HTMLElement, fileBox: HTMLElement) {
@ -377,9 +375,7 @@ function initDiffExpandAllLines() {
}); });
registerGlobalEventFunc('click', 'onExpanderButtonClick', (btn: HTMLElement) => { registerGlobalEventFunc('click', 'onExpanderButtonClick', (btn: HTMLElement) => {
const tr = btn.closest('tr')!; fetchBlobExcerpt(btn.closest('tr')!, btn.getAttribute('data-url')!);
const url = btn.getAttribute('data-url')!;
fetchBlobExcerpt(tr, url);
}); });
} }