93 lines
4.8 KiB
Python
93 lines
4.8 KiB
Python
import re
|
|
|
|
with open('/home/creserver/Desktop/Vaishno_workspace/Unified_Dashboard_Suite_Go/web/bulk-api-tester/static/js/app.js', 'r') as f:
|
|
content = f.read()
|
|
|
|
# 1. Add async helper
|
|
if 'base64ToBlobUrlAsync' not in content:
|
|
content = content.replace('base64ToBlobUrl(base64Data, contentType) {', '''async base64ToBlobUrlAsync(base64Data, contentType) {
|
|
if (!base64Data) return '';
|
|
try {
|
|
const res = await fetch(`data:${contentType || 'application/octet-stream'};base64,${base64Data}`);
|
|
const blob = await res.blob();
|
|
return URL.createObjectURL(blob);
|
|
} catch (e) {
|
|
console.error("Async Base64 decode error", e);
|
|
return '';
|
|
}
|
|
},
|
|
|
|
base64ToBlobUrl(base64Data, contentType) {''')
|
|
|
|
# 2. Update executeRequest
|
|
old_exec = """ const data = await res.json();
|
|
data.latency = Date.now() - start;
|
|
return data;
|
|
},"""
|
|
|
|
new_exec = """ const data = await res.json();
|
|
if (data.binary_data) {
|
|
data.blobUrl = await this.base64ToBlobUrlAsync(data.binary_data, data.content_type);
|
|
}
|
|
data.latency = Date.now() - start;
|
|
return data;
|
|
},"""
|
|
content = content.replace(old_exec, new_exec)
|
|
|
|
# 3. Update result pushing in runBulkRequests
|
|
old_push = """ binaryData: res.binary_data,
|
|
contentType: res.content_type,"""
|
|
new_push = """ binaryData: res.binary_data,
|
|
blobUrl: res.blobUrl,
|
|
contentType: res.content_type,"""
|
|
content = content.replace(old_push, new_push)
|
|
|
|
# 4. Update result replacing in resendBulkRequest
|
|
old_replace = """ resultItem.fullContent = res.content;
|
|
resultItem.binaryData = res.binary_data;
|
|
resultItem.contentType = res.content_type;
|
|
resultItem.headers = res.headers;
|
|
|
|
// Clear cached image blob so it regenerates for the new response
|
|
if (resultItem.blobUrl) {
|
|
URL.revokeObjectURL(resultItem.blobUrl);
|
|
resultItem.blobUrl = null;
|
|
}"""
|
|
new_replace = """ resultItem.fullContent = res.content;
|
|
resultItem.binaryData = res.binary_data;
|
|
resultItem.contentType = res.content_type;
|
|
resultItem.headers = res.headers;
|
|
|
|
if (resultItem.blobUrl && resultItem.blobUrl !== res.blobUrl) {
|
|
URL.revokeObjectURL(resultItem.blobUrl);
|
|
}
|
|
resultItem.blobUrl = res.blobUrl;"""
|
|
content = content.replace(old_replace, new_replace)
|
|
|
|
# 5. Update single response logic
|
|
old_single = """ this.state.response = res;"""
|
|
new_single = """ this.state.response = res;
|
|
if (res.blobUrl) this.state.response.blobUrl = res.blobUrl;"""
|
|
content = content.replace(old_single, new_single)
|
|
|
|
# 6. Remove synchronous atob call from renderResultCard
|
|
old_render1 = """ previewHTML = `<img src="${!result.blobUrl ? (result.blobUrl = this.base64ToBlobUrl(result.binaryData, result.contentType)) : result.blobUrl}" class="card-thumb" alt="${filename}" loading="lazy" decoding="async" />`;"""
|
|
new_render1 = """ previewHTML = `<img src="${result.blobUrl || this.base64ToBlobUrl(result.binaryData, result.contentType)}" class="card-thumb" alt="${filename}" loading="lazy" decoding="async" />`;"""
|
|
content = content.replace(old_render1, new_render1)
|
|
|
|
old_render2 = """ <img src="${!resp.blobUrl ? (resp.blobUrl = this.base64ToBlobUrl(resp.binary_data, resp.content_type)) : resp.blobUrl}"
|
|
loading="lazy" decoding="async" style="max-width:100%; max-height:260px; border:1px solid var(--border); border-radius: 4px;" alt="Binary Content" />"""
|
|
new_render2 = """ <img src="${resp.blobUrl || this.base64ToBlobUrl(resp.binary_data, resp.content_type)}"
|
|
loading="lazy" decoding="async" style="max-width:100%; max-height:260px; border:1px solid var(--border); border-radius: 4px;" alt="Binary Content" />"""
|
|
content = content.replace(old_render2, new_render2)
|
|
|
|
old_render3 = """ contentHTML = `<img src="${!result.blobUrl ? (result.blobUrl = this.base64ToBlobUrl(result.binaryData, result.contentType)) : result.blobUrl}" class="modal-zoom-image" alt="${finalFilename}" loading="lazy" decoding="async" />`;"""
|
|
new_render3 = """ contentHTML = `<img src="${result.blobUrl || this.base64ToBlobUrl(result.binaryData, result.contentType)}" class="modal-zoom-image" alt="${finalFilename}" loading="lazy" decoding="async" />`;"""
|
|
content = content.replace(old_render3, new_render3)
|
|
|
|
|
|
with open('/home/creserver/Desktop/Vaishno_workspace/Unified_Dashboard_Suite_Go/web/bulk-api-tester/static/js/app.js', 'w') as f:
|
|
f.write(content)
|
|
|
|
print("Applied async blob patches")
|