const fs = require('fs');
let code = fs.readFileSync('public/index.html', 'utf8');
const searchAction = ` let actionHtml = '';
if (embedUrl) {
actionHtml = \`
\`;
} else {
actionHtml = \`Pending\`;
}`;
const replacementAction = ` let actionHtml = '';
if (embedUrl) {
if (currentState.processingMode === 'drive_secure') {
actionHtml = \`
\`;
} else {
actionHtml = \`
\`;
}
} else {
actionHtml = \`Pending\`;
}`;
code = code.replace(searchAction, replacementAction);
const searchFileType = `
\${formatBytes(file.size || file.totalBytes)} (\${ext})
`;
const replaceFileType = `
\${formatBytes(file.size || file.totalBytes)} (\${ext})
\${currentState.processingMode === 'drive_secure'
? 'DRIVE PLAYER
'
: 'YOUTUBE UPLOAD
'
}`;
code = code.replace(searchFileType, replaceFileType);
const searchFuncs = ` window.copyToClipboard = function(text, label = 'Embed Link') {`;
const replaceFuncs = ` window.currentThumbnailVideoId = null;
window.triggerThumbnailUpload = function(videoId) {
window.currentThumbnailVideoId = videoId;
document.getElementById('hiddenThumbInput').click();
};
window.handleThumbnailSelect = function(event) {
const file = event.target.files[0];
if (!file || !window.currentThumbnailVideoId) return;
if (file.size > 10 * 1024 * 1024) {
showToast('Thumbnail must be less than 10MB', 'error');
return;
}
const reader = new FileReader();
reader.onload = async (e) => {
const base64 = e.target.result;
showToast('Uploading thumbnail...', 'info');
try {
const res = await fetch('/api/thumbnail', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + window.getAccessToken()
},
body: JSON.stringify({
videoId: window.currentThumbnailVideoId,
imageBase64: base64
})
});
const data = await res.json();
if (data.success) {
showToast('Thumbnail updated successfully!', 'success');
// Refresh table or wait for SSE
loadJobStatus();
} else {
showToast('Failed to update thumbnail: ' + data.error, 'error');
}
} catch (err) {
showToast('Error uploading thumbnail: ' + err.message, 'error');
}
};
reader.readAsDataURL(file);
};
window.copyToClipboard = function(text, label = 'Embed Link') {`;
code = code.replace(searchFuncs, replaceFuncs);
const bodyEnd = `