perf(bulk-api-tester): optimize draft saving, share link creation, and combining with parallel multipart streaming and instant hard links
This commit is contained in:
+240
-191
@@ -3022,6 +3022,37 @@ const App = {
|
||||
}
|
||||
},
|
||||
|
||||
// ── High-Speed Blob Resolution Helper ────────────────────────────────────
|
||||
async _getBlobFromUrlOrBinary(url, binaryData, contentType = 'image/png') {
|
||||
if (url) {
|
||||
try {
|
||||
const res = await fetch(url);
|
||||
if (res.ok) return await res.blob();
|
||||
} catch (_) {}
|
||||
}
|
||||
if (binaryData) {
|
||||
try {
|
||||
let b64 = binaryData;
|
||||
let mime = contentType || 'image/png';
|
||||
if (b64.startsWith('data:')) {
|
||||
const idx = b64.indexOf(';base64,');
|
||||
if (idx !== -1) {
|
||||
mime = b64.substring(5, idx);
|
||||
b64 = b64.substring(idx + 8);
|
||||
}
|
||||
}
|
||||
const binStr = atob(b64);
|
||||
const len = binStr.length;
|
||||
const bytes = new Uint8Array(len);
|
||||
for (let i = 0; i < len; i++) {
|
||||
bytes[i] = binStr.charCodeAt(i);
|
||||
}
|
||||
return new Blob([bytes], { type: mime });
|
||||
} catch (_) {}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
// ── Shareable Visual Comparison Studio ─────────────────────────────────────
|
||||
async createShareableComparison() {
|
||||
const results = this.state.bulk.results;
|
||||
@@ -3039,88 +3070,84 @@ const App = {
|
||||
<i class="fa-solid fa-spinner fa-spin"></i>
|
||||
</div>
|
||||
<h3 style="font-family:var(--font-display); font-size:16px; margin:0 0 6px 0; color:var(--text-1);">Packaging Comparison Snapshot</h3>
|
||||
<p id="share-progress-text" style="font-size:12px; color:var(--text-3); margin:0 0 16px 0;">Processing result assets (0/${results.length})...</p>
|
||||
<p id="share-progress-text" style="font-size:12px; color:var(--text-3); margin:0 0 16px 0;">Uploading streaming assets (${results.length} items)...</p>
|
||||
<div class="progress-track" style="margin-bottom:0; height:6px;">
|
||||
<div id="share-progress-fill" class="progress-fill" style="width:0%; background:linear-gradient(90deg, #7257ff, #38bdf8);"></div>
|
||||
<div id="share-progress-fill" class="progress-fill" style="width:75%; background:linear-gradient(90deg, #7257ff, #38bdf8);"></div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
document.body.appendChild(progressModal);
|
||||
|
||||
const updateProgress = (done, total) => {
|
||||
const pText = document.getElementById('share-progress-text');
|
||||
const pFill = document.getElementById('share-progress-fill');
|
||||
if (pText) pText.textContent = `Processing result assets (${done}/${total})...`;
|
||||
if (pFill) pFill.style.width = `${Math.round((done / total) * 100)}%`;
|
||||
};
|
||||
|
||||
const blobToBase64 = (blob) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onloadend = () => resolve(reader.result);
|
||||
reader.onerror = reject;
|
||||
reader.readAsDataURL(blob);
|
||||
});
|
||||
};
|
||||
|
||||
try {
|
||||
const items = [];
|
||||
for (let i = 0; i < results.length; i++) {
|
||||
const r = results[i];
|
||||
updateProgress(i + 1, results.length);
|
||||
|
||||
let beforeData = '';
|
||||
let afterData = '';
|
||||
|
||||
// 1. Resolve Before Image
|
||||
// High-speed parallel blob resolution (zero base64 encoding overhead)
|
||||
const resolvedItems = await Promise.all(results.map(async (r, i) => {
|
||||
const itemIndex = r.index || (i + 1);
|
||||
const beforeObj = this.resolveOriginalImageForResult(r);
|
||||
if (beforeObj && beforeObj.url) {
|
||||
try {
|
||||
const bBlob = await fetch(beforeObj.url).then(res => res.blob());
|
||||
beforeData = await blobToBase64(bBlob);
|
||||
} catch(e) {
|
||||
console.warn("Failed to encode before image", e);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Resolve After Image
|
||||
if (r.blobUrl) {
|
||||
try {
|
||||
const aBlob = await fetch(r.blobUrl).then(res => res.blob());
|
||||
afterData = await blobToBase64(aBlob);
|
||||
} catch(e) {
|
||||
console.warn("Failed to encode after image", e);
|
||||
}
|
||||
} else if (r.binaryData) {
|
||||
afterData = r.binaryData.startsWith('data:') ? r.binaryData : `data:${r.contentType || 'image/png'};base64,${r.binaryData}`;
|
||||
}
|
||||
const [beforeBlob, afterBlob] = await Promise.all([
|
||||
beforeObj && beforeObj.url ? this._getBlobFromUrlOrBinary(beforeObj.url, null) : Promise.resolve(null),
|
||||
this._getBlobFromUrlOrBinary(r.blobUrl, r.binaryData, r.contentType || 'image/png')
|
||||
]);
|
||||
|
||||
items.push({
|
||||
index: r.index || (i + 1),
|
||||
return {
|
||||
index: itemIndex,
|
||||
status: r.status,
|
||||
latency: r.latency || 0,
|
||||
inputFilename: (beforeObj && beforeObj.name) || r.inputFilename || `input_${i+1}`,
|
||||
inputFilename: (beforeObj && beforeObj.name) || r.inputFilename || `input_${itemIndex}`,
|
||||
outputFilename: this.getFinalFilename(r),
|
||||
contentType: r.contentType || 'image/png',
|
||||
beforeData: beforeData,
|
||||
afterData: afterData,
|
||||
textContent: r.fullContent || (typeof r.data === 'string' ? r.data : '')
|
||||
textContent: r.fullContent || (typeof r.data === 'string' ? r.data : ''),
|
||||
beforeBlob,
|
||||
afterBlob
|
||||
};
|
||||
}));
|
||||
|
||||
const fd = new FormData();
|
||||
const metaItems = [];
|
||||
|
||||
const getExt = (blob, fallbackType) => {
|
||||
const type = (blob && blob.type) || fallbackType || '';
|
||||
if (type.includes('jpeg') || type.includes('jpg')) return '.jpg';
|
||||
if (type.includes('webp')) return '.webp';
|
||||
if (type.includes('gif')) return '.gif';
|
||||
if (type.includes('svg')) return '.svg';
|
||||
if (type.includes('avif')) return '.avif';
|
||||
return '.png';
|
||||
};
|
||||
|
||||
for (const it of resolvedItems) {
|
||||
if (it.beforeBlob) {
|
||||
const ext = getExt(it.beforeBlob, 'image/png');
|
||||
fd.append(`before_${it.index}`, it.beforeBlob, `before_${it.index}${ext}`);
|
||||
}
|
||||
if (it.afterBlob) {
|
||||
const ext = getExt(it.afterBlob, it.contentType);
|
||||
fd.append(`after_${it.index}`, it.afterBlob, `after_${it.index}${ext}`);
|
||||
}
|
||||
|
||||
metaItems.push({
|
||||
index: it.index,
|
||||
status: it.status,
|
||||
latency: it.latency,
|
||||
inputFilename: it.inputFilename,
|
||||
outputFilename: it.outputFilename,
|
||||
contentType: it.contentType,
|
||||
textContent: it.textContent
|
||||
});
|
||||
}
|
||||
|
||||
const activeSpace = this.state.spaces.find(s => s.id === this.state.activeSpaceId);
|
||||
const payload = {
|
||||
fd.append('meta', JSON.stringify({
|
||||
title: `Batch Comparison (${results.length} results)`,
|
||||
endpoint: this.state.url || '',
|
||||
spaceName: activeSpace ? activeSpace.name : 'Default Space',
|
||||
items: items
|
||||
};
|
||||
items: metaItems
|
||||
}));
|
||||
|
||||
const basePath = window.location.pathname.includes('/tool/bulk-api-tester') ? '/tool/bulk-api-tester' : '';
|
||||
const res = await fetch(`${basePath}/api/share-comparison`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload)
|
||||
body: fd
|
||||
});
|
||||
|
||||
progressModal.remove();
|
||||
@@ -3147,7 +3174,6 @@ const App = {
|
||||
copied = true;
|
||||
}
|
||||
} catch(_) {
|
||||
// Fallback for environments without direct clipboard focus
|
||||
try {
|
||||
const ta = document.createElement('textarea');
|
||||
ta.value = shareUrl;
|
||||
@@ -3373,66 +3399,77 @@ const App = {
|
||||
submitBtn.innerHTML = `<i class="fa-solid fa-spinner fa-spin"></i> Saving...`;
|
||||
}
|
||||
|
||||
const blobToBase64 = (blob) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onloadend = () => resolve(reader.result);
|
||||
reader.onerror = reject;
|
||||
reader.readAsDataURL(blob);
|
||||
});
|
||||
};
|
||||
|
||||
try {
|
||||
const items = [];
|
||||
for (let i = 0; i < results.length; i++) {
|
||||
const r = results[i];
|
||||
let beforeData = '';
|
||||
let afterData = '';
|
||||
|
||||
// High-speed parallel blob resolution (zero base64 encoding overhead)
|
||||
const resolvedItems = await Promise.all(results.map(async (r, i) => {
|
||||
const itemIndex = r.index || (i + 1);
|
||||
const beforeObj = this.resolveOriginalImageForResult(r);
|
||||
if (beforeObj && beforeObj.url) {
|
||||
try {
|
||||
const bBlob = await fetch(beforeObj.url).then(res => res.blob());
|
||||
beforeData = await blobToBase64(bBlob);
|
||||
} catch(_) {}
|
||||
}
|
||||
|
||||
if (r.blobUrl) {
|
||||
try {
|
||||
const aBlob = await fetch(r.blobUrl).then(res => res.blob());
|
||||
afterData = await blobToBase64(aBlob);
|
||||
} catch(_) {}
|
||||
} else if (r.binaryData) {
|
||||
afterData = r.binaryData.startsWith('data:') ? r.binaryData : `data:${r.contentType || 'image/png'};base64,${r.binaryData}`;
|
||||
}
|
||||
const [beforeBlob, afterBlob] = await Promise.all([
|
||||
beforeObj && beforeObj.url ? this._getBlobFromUrlOrBinary(beforeObj.url, null) : Promise.resolve(null),
|
||||
this._getBlobFromUrlOrBinary(r.blobUrl, r.binaryData, r.contentType || 'image/png')
|
||||
]);
|
||||
|
||||
items.push({
|
||||
index: r.index || (i + 1),
|
||||
return {
|
||||
index: itemIndex,
|
||||
status: r.status,
|
||||
latency: r.latency || 0,
|
||||
inputFilename: (beforeObj && beforeObj.name) || r.inputFilename || `input_${i+1}`,
|
||||
inputFilename: (beforeObj && beforeObj.name) || r.inputFilename || `input_${itemIndex}`,
|
||||
outputFilename: this.getFinalFilename(r),
|
||||
contentType: r.contentType || 'image/png',
|
||||
beforeData: beforeData,
|
||||
afterData: afterData,
|
||||
textContent: r.fullContent || (typeof r.data === 'string' ? r.data : '')
|
||||
textContent: r.fullContent || (typeof r.data === 'string' ? r.data : ''),
|
||||
beforeBlob,
|
||||
afterBlob
|
||||
};
|
||||
}));
|
||||
|
||||
const fd = new FormData();
|
||||
const metaItems = [];
|
||||
|
||||
const getExt = (blob, fallbackType) => {
|
||||
const type = (blob && blob.type) || fallbackType || '';
|
||||
if (type.includes('jpeg') || type.includes('jpg')) return '.jpg';
|
||||
if (type.includes('webp')) return '.webp';
|
||||
if (type.includes('gif')) return '.gif';
|
||||
if (type.includes('svg')) return '.svg';
|
||||
if (type.includes('avif')) return '.avif';
|
||||
return '.png';
|
||||
};
|
||||
|
||||
for (const it of resolvedItems) {
|
||||
if (it.beforeBlob) {
|
||||
const ext = getExt(it.beforeBlob, 'image/png');
|
||||
fd.append(`before_${it.index}`, it.beforeBlob, `before_${it.index}${ext}`);
|
||||
}
|
||||
if (it.afterBlob) {
|
||||
const ext = getExt(it.afterBlob, it.contentType);
|
||||
fd.append(`after_${it.index}`, it.afterBlob, `after_${it.index}${ext}`);
|
||||
}
|
||||
|
||||
metaItems.push({
|
||||
index: it.index,
|
||||
status: it.status,
|
||||
latency: it.latency,
|
||||
inputFilename: it.inputFilename,
|
||||
outputFilename: it.outputFilename,
|
||||
contentType: it.contentType,
|
||||
textContent: it.textContent
|
||||
});
|
||||
}
|
||||
|
||||
const activeSpace = this.state.spaces.find(s => s.id === this.state.activeSpaceId);
|
||||
const payload = {
|
||||
fd.append('meta', JSON.stringify({
|
||||
title: title || `Comparison Draft (${results.length} items)`,
|
||||
notes: notes,
|
||||
endpoint: this.state.url || '',
|
||||
spaceName: activeSpace ? activeSpace.name : 'Workspace',
|
||||
items: items
|
||||
};
|
||||
items: metaItems
|
||||
}));
|
||||
|
||||
const basePath = window.location.pathname.includes('/tool/bulk-api-tester') ? '/tool/bulk-api-tester' : '';
|
||||
const res = await fetch(`${basePath}/api/comparison-drafts`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload)
|
||||
body: fd
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
@@ -3440,6 +3477,9 @@ const App = {
|
||||
throw new Error(err.error || `HTTP ${res.status}`);
|
||||
}
|
||||
|
||||
// Invalidate cache so drafts manager immediately loads latest
|
||||
this._draftsCache = null;
|
||||
|
||||
document.querySelector('.save-draft-modal-overlay')?.remove();
|
||||
this.toast(`Comparison draft saved!`, 'success');
|
||||
this.updateDraftsBadge();
|
||||
@@ -3520,10 +3560,102 @@ const App = {
|
||||
modal.onclick = () => modal.remove();
|
||||
|
||||
this._selectedDraftItemKeys = new Set();
|
||||
this._draftsCache = [];
|
||||
if (this._draftsCache && this._draftsCache.length > 0) {
|
||||
this._renderDraftsList(this._draftsCache);
|
||||
}
|
||||
await this.loadDraftsIntoManager();
|
||||
},
|
||||
|
||||
_renderDraftsList(drafts) {
|
||||
const container = document.getElementById('drafts-list-container');
|
||||
if (!container) return;
|
||||
|
||||
if (!drafts || drafts.length === 0) {
|
||||
container.innerHTML = `
|
||||
<div style="padding:50px 20px; text-align:center; display:flex; flex-direction:column; align-items:center; gap:12px;">
|
||||
<i class="fa-solid fa-folder-open" style="font-size:42px; color:var(--text-3); opacity:0.6;"></i>
|
||||
<h4 style="font-family:var(--font-display); font-size:15px; color:var(--text-2); margin:0;">No Comparison Drafts Saved</h4>
|
||||
<p style="font-size:12px; color:var(--text-3); max-width:400px; margin:0; line-height:1.5;">
|
||||
When you execute single or batch API tests, click <b>"Save Draft"</b> to store the results here. Later, you can select and merge multiple drafts into a single shareable comparison link under one custom heading.
|
||||
</p>
|
||||
${this.state.bulk.results.length > 0 ? `
|
||||
<button class="btn btn-primary btn-sm" style="margin-top:6px;" onclick="App.openSaveDraftModal()">
|
||||
<i class="fa-solid fa-floppy-disk"></i> Save Current Results as First Draft
|
||||
</button>
|
||||
` : ''}
|
||||
</div>
|
||||
`;
|
||||
return;
|
||||
}
|
||||
|
||||
container.innerHTML = drafts.map(draft => {
|
||||
const dateStr = new Date(draft.createdAt).toLocaleString([], { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' });
|
||||
return `
|
||||
<div class="draft-card" id="draft-card-${draft.id}">
|
||||
<div class="draft-card-head">
|
||||
<div class="draft-title-wrap">
|
||||
<input type="checkbox" class="draft-checkbox" id="draft-cb-${draft.id}" onchange="App.onDraftCardCheckboxChange('${draft.id}', this.checked)" />
|
||||
<div>
|
||||
<div class="draft-title-text">${this.escapeHTML(draft.title)}</div>
|
||||
<div style="display:flex; align-items:center; gap:8px; font-size:11px; color:var(--text-3); margin-top:3px; font-family:var(--font-mono);">
|
||||
<span><i class="fa-regular fa-clock"></i> ${dateStr}</span>
|
||||
${draft.spaceName ? `<span>· ${this.escapeHTML(draft.spaceName)}</span>` : ''}
|
||||
${draft.endpoint ? `<span title="${this.escapeHTML(draft.endpoint)}">· ${this.escapeHTML(draft.endpoint.substring(0, 36))}...</span>` : ''}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div style="display:flex; align-items:center; gap:8px;">
|
||||
<span class="stat-capsule">${draft.total} Items</span>
|
||||
${draft.avgLatency > 0 ? `<span class="stat-capsule"><i class="fa-solid fa-gauge-high"></i> ${draft.avgLatency}ms</span>` : ''}
|
||||
<span class="stat-capsule ${draft.errorCount === 0 ? 'success' : 'error'}">${draft.successCount} OK</span>
|
||||
<button class="btn btn-ghost btn-xs" onclick="App.shareSingleDraft('${draft.id}')" title="Generate shareable comparison link for this draft">
|
||||
<i class="fa-solid fa-share-nodes"></i> Share
|
||||
</button>
|
||||
<button class="btn btn-ghost btn-xs" style="color:var(--danger);" onclick="App.deleteDraft('${draft.id}')" title="Delete draft">
|
||||
<i class="fa-solid fa-trash"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
${draft.notes ? `
|
||||
<div style="font-size:11.5px; color:var(--text-2); background:rgba(0,0,0,0.22); padding:6px 10px; border-radius:var(--r-sm); border:1px solid var(--border-1);">
|
||||
<i class="fa-solid fa-note-sticky" style="color:var(--accent); margin-right:4px;"></i> ${this.escapeHTML(draft.notes)}
|
||||
</div>
|
||||
` : ''}
|
||||
|
||||
<!-- Items Strip -->
|
||||
<div class="draft-items-strip">
|
||||
${(draft.items || []).map(it => {
|
||||
const key = `${draft.id}:${it.index}`;
|
||||
const isChecked = this._selectedDraftItemKeys && this._selectedDraftItemKeys.has(key);
|
||||
const afterUrl = it.afterImage ? (window.location.pathname.includes('/tool/bulk-api-tester') ? '/tool/bulk-api-tester' + it.afterImage : it.afterImage) : '';
|
||||
return `
|
||||
<div class="draft-item-card ${isChecked ? 'selected' : ''}" id="item-card-${draft.id}-${it.index}" onclick="App.toggleDraftItemDirectly('${draft.id}', ${it.index})">
|
||||
<div class="draft-item-thumb">
|
||||
<input type="checkbox" class="draft-item-checkbox" id="item-cb-${draft.id}-${it.index}"
|
||||
${isChecked ? 'checked' : ''}
|
||||
onclick="event.stopPropagation(); App.onDraftItemCbChange('${draft.id}', ${it.index}, this.checked)" />
|
||||
${afterUrl ? `<img src="${afterUrl}" loading="lazy" decoding="async" />` : `<i class="fa-solid fa-file-code" style="color:var(--text-3); font-size:20px;"></i>`}
|
||||
</div>
|
||||
<div style="font-size:10.5px; font-weight:600; color:var(--text-1); overflow:hidden; text-overflow:ellipsis; white-space:nowrap;" title="${this.escapeHTML(it.outputFilename || it.inputFilename || '')}">
|
||||
${this.escapeHTML(it.outputFilename || it.inputFilename || `#${it.index}`)}
|
||||
</div>
|
||||
<div style="display:flex; justify-content:space-between; align-items:center; font-size:10px; color:var(--text-3); font-family:var(--font-mono);">
|
||||
<span>#${it.index}</span>
|
||||
<span style="color:${String(it.status).startsWith('2') ? 'var(--success)' : 'var(--danger)'}; font-weight:700;">${it.status}</span>
|
||||
<span>${it.latency}ms</span>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}).join('')}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}).join('');
|
||||
|
||||
this.updateDraftCounters();
|
||||
},
|
||||
|
||||
async loadDraftsIntoManager() {
|
||||
const container = document.getElementById('drafts-list-container');
|
||||
if (!container) return;
|
||||
@@ -3534,99 +3666,16 @@ const App = {
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||
const drafts = await res.json();
|
||||
this._draftsCache = drafts || [];
|
||||
|
||||
if (this._draftsCache.length === 0) {
|
||||
container.innerHTML = `
|
||||
<div style="padding:50px 20px; text-align:center; display:flex; flex-direction:column; align-items:center; gap:12px;">
|
||||
<i class="fa-solid fa-folder-open" style="font-size:42px; color:var(--text-3); opacity:0.6;"></i>
|
||||
<h4 style="font-family:var(--font-display); font-size:15px; color:var(--text-2); margin:0;">No Comparison Drafts Saved</h4>
|
||||
<p style="font-size:12px; color:var(--text-3); max-width:400px; margin:0; line-height:1.5;">
|
||||
When you execute single or batch API tests, click <b>"Save Draft"</b> to store the results here. Later, you can select and merge multiple drafts into a single shareable comparison link under one custom heading.
|
||||
</p>
|
||||
${this.state.bulk.results.length > 0 ? `
|
||||
<button class="btn btn-primary btn-sm" style="margin-top:6px;" onclick="App.openSaveDraftModal()">
|
||||
<i class="fa-solid fa-floppy-disk"></i> Save Current Results as First Draft
|
||||
</button>
|
||||
` : ''}
|
||||
</div>
|
||||
`;
|
||||
return;
|
||||
}
|
||||
|
||||
container.innerHTML = this._draftsCache.map(draft => {
|
||||
const dateStr = new Date(draft.createdAt).toLocaleString([], { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' });
|
||||
return `
|
||||
<div class="draft-card" id="draft-card-${draft.id}">
|
||||
<div class="draft-card-head">
|
||||
<div class="draft-title-wrap">
|
||||
<input type="checkbox" class="draft-checkbox" id="draft-cb-${draft.id}" onchange="App.onDraftCardCheckboxChange('${draft.id}', this.checked)" />
|
||||
<div>
|
||||
<div class="draft-title-text">${this.escapeHTML(draft.title)}</div>
|
||||
<div style="display:flex; align-items:center; gap:8px; font-size:11px; color:var(--text-3); margin-top:3px; font-family:var(--font-mono);">
|
||||
<span><i class="fa-regular fa-clock"></i> ${dateStr}</span>
|
||||
${draft.spaceName ? `<span>· ${this.escapeHTML(draft.spaceName)}</span>` : ''}
|
||||
${draft.endpoint ? `<span title="${this.escapeHTML(draft.endpoint)}">· ${this.escapeHTML(draft.endpoint.substring(0, 36))}...</span>` : ''}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div style="display:flex; align-items:center; gap:8px;">
|
||||
<span class="stat-capsule">${draft.total} Items</span>
|
||||
${draft.avgLatency > 0 ? `<span class="stat-capsule"><i class="fa-solid fa-gauge-high"></i> ${draft.avgLatency}ms</span>` : ''}
|
||||
<span class="stat-capsule ${draft.errorCount === 0 ? 'success' : 'error'}">${draft.successCount} OK</span>
|
||||
<button class="btn btn-ghost btn-xs" onclick="App.shareSingleDraft('${draft.id}')" title="Generate shareable comparison link for this draft">
|
||||
<i class="fa-solid fa-share-nodes"></i> Share
|
||||
</button>
|
||||
<button class="btn btn-ghost btn-xs" style="color:var(--danger);" onclick="App.deleteDraft('${draft.id}')" title="Delete draft">
|
||||
<i class="fa-solid fa-trash"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
${draft.notes ? `
|
||||
<div style="font-size:11.5px; color:var(--text-2); background:rgba(0,0,0,0.22); padding:6px 10px; border-radius:var(--r-sm); border:1px solid var(--border-1);">
|
||||
<i class="fa-solid fa-note-sticky" style="color:var(--accent); margin-right:4px;"></i> ${this.escapeHTML(draft.notes)}
|
||||
</div>
|
||||
` : ''}
|
||||
|
||||
<!-- Items Strip -->
|
||||
<div class="draft-items-strip">
|
||||
${(draft.items || []).map(it => {
|
||||
const key = `${draft.id}:${it.index}`;
|
||||
const isChecked = this._selectedDraftItemKeys.has(key);
|
||||
const afterUrl = it.afterImage ? (window.location.pathname.includes('/tool/bulk-api-tester') ? '/tool/bulk-api-tester' + it.afterImage : it.afterImage) : '';
|
||||
return `
|
||||
<div class="draft-item-card ${isChecked ? 'selected' : ''}" id="item-card-${draft.id}-${it.index}" onclick="App.toggleDraftItemDirectly('${draft.id}', ${it.index})">
|
||||
<div class="draft-item-thumb">
|
||||
<input type="checkbox" class="draft-item-checkbox" id="item-cb-${draft.id}-${it.index}"
|
||||
${isChecked ? 'checked' : ''}
|
||||
onclick="event.stopPropagation(); App.onDraftItemCbChange('${draft.id}', ${it.index}, this.checked)" />
|
||||
${afterUrl ? `<img src="${afterUrl}" loading="lazy" />` : `<i class="fa-solid fa-file-code" style="color:var(--text-3); font-size:20px;"></i>`}
|
||||
</div>
|
||||
<div style="font-size:10.5px; font-weight:600; color:var(--text-1); overflow:hidden; text-overflow:ellipsis; white-space:nowrap;" title="${this.escapeHTML(it.outputFilename || it.inputFilename || '')}">
|
||||
${this.escapeHTML(it.outputFilename || it.inputFilename || `#${it.index}`)}
|
||||
</div>
|
||||
<div style="display:flex; justify-content:space-between; align-items:center; font-size:10px; color:var(--text-3); font-family:var(--font-mono);">
|
||||
<span>#${it.index}</span>
|
||||
<span style="color:${String(it.status).startsWith('2') ? 'var(--success)' : 'var(--danger)'}; font-weight:700;">${it.status}</span>
|
||||
<span>${it.latency}ms</span>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}).join('')}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}).join('');
|
||||
|
||||
this.updateDraftCounters();
|
||||
|
||||
this._renderDraftsList(this._draftsCache);
|
||||
} catch(e) {
|
||||
container.innerHTML = `
|
||||
<div style="padding:40px; text-align:center; color:var(--danger);">
|
||||
<i class="fa-solid fa-triangle-exclamation" style="font-size:28px; margin-bottom:8px;"></i>
|
||||
<div>Failed to load drafts: ${this.escapeHTML(e.message)}</div>
|
||||
</div>
|
||||
`;
|
||||
if (!this._draftsCache || this._draftsCache.length === 0) {
|
||||
container.innerHTML = `
|
||||
<div style="padding:40px; text-align:center; color:var(--danger);">
|
||||
<i class="fa-solid fa-triangle-exclamation" style="font-size:28px; margin-bottom:8px;"></i>
|
||||
<div>Failed to load drafts: ${this.escapeHTML(e.message)}</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user