Atualização automática: 2026-05-23 20:55:21
This commit is contained in:
@@ -312,21 +312,33 @@ async function applyUltraModernRedesign(cloneDir) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Injetar o CSS de Redesign Ultra-Moderno gerado pela IA no site clonado
|
// Injetar o CSS de Redesign Ultra-Moderno gerado pela IA no site clonado
|
||||||
|
let newPreviewUrl = `/api/preview/${cloneDir.split('/').pop()}`;
|
||||||
try {
|
try {
|
||||||
await fetch('/api/ai/inject-redesign', {
|
const response = await fetch('/api/ai/inject-redesign', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ cloneDir, appliedStyles, elementsRedesigned })
|
body: JSON.stringify({
|
||||||
|
cloneDir,
|
||||||
|
appliedStyles,
|
||||||
|
elementsRedesigned,
|
||||||
|
outputDir: settings.outputDir,
|
||||||
|
agentName: 'designer'
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
const data = await response.json();
|
||||||
|
if (data.newFolderName) {
|
||||||
|
newPreviewUrl = `/api/preview/${data.newFolderName}`;
|
||||||
|
if (agentsState.designer.currentClone) {
|
||||||
|
agentsState.designer.currentClone.directory = 'cloned-sites/' + data.newFolderName;
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Erro ao injetar CSS de redesign:", e);
|
console.error("Erro ao injetar CSS de redesign:", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
const previewUrl = `/api/preview/${cloneDir.split('/').pop()}`;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
previewUrl,
|
previewUrl: newPreviewUrl,
|
||||||
appliedStyles,
|
appliedStyles,
|
||||||
elementsRedesigned
|
elementsRedesigned
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -304,7 +304,10 @@ async function startCloning(url, options) {
|
|||||||
response = await fetch('/api/smart-clone', {
|
response = await fetch('/api/smart-clone', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ url })
|
body: JSON.stringify({
|
||||||
|
url,
|
||||||
|
outputDir: settings.outputDir
|
||||||
|
})
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// WGET logic
|
// WGET logic
|
||||||
@@ -313,7 +316,8 @@ async function startCloning(url, options) {
|
|||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
url,
|
url,
|
||||||
depth: options.depth
|
depth: options.depth,
|
||||||
|
outputDir: settings.outputDir
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -584,9 +588,13 @@ function loadSettings() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Populate settings form (if needed)
|
// Populate settings form (if needed)
|
||||||
|
const outDirInput = document.getElementById('settingsOutputDir');
|
||||||
|
if (outDirInput) outDirInput.value = settings.outputDir || '/root/Desktop/Clonados';
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveSettings() {
|
function saveSettings() {
|
||||||
|
const outDirInput = document.getElementById('settingsOutputDir');
|
||||||
|
if (outDirInput) settings.outputDir = outDirInput.value;
|
||||||
localStorage.setItem('cloneSettings', JSON.stringify(settings));
|
localStorage.setItem('cloneSettings', JSON.stringify(settings));
|
||||||
showToast('Configurações salvas!', 'success');
|
showToast('Configurações salvas!', 'success');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -250,8 +250,8 @@
|
|||||||
<p>Local onde os sites clonados serão salvos</p>
|
<p>Local onde os sites clonados serão salvos</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="setting-control">
|
<div class="setting-control">
|
||||||
<input type="text" class="form-control" value="M:\CLONEWEB\cloned-sites" readonly>
|
<input type="text" id="settingsOutputDir" class="form-control" value="/root/Desktop/Clonados">
|
||||||
<button class="btn btn-secondary btn-sm">
|
<button class="btn btn-secondary btn-sm" onclick="openCloneFolder(document.getElementById('settingsOutputDir').value)">
|
||||||
<i class="fas fa-folder-open"></i> Abrir
|
<i class="fas fa-folder-open"></i> Abrir
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -293,7 +293,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="settings-actions">
|
<div class="settings-actions">
|
||||||
<button class="btn btn-primary">
|
<button class="btn btn-primary" onclick="saveSettings()">
|
||||||
<i class="fas fa-save"></i> Salvar Configurações
|
<i class="fas fa-save"></i> Salvar Configurações
|
||||||
</button>
|
</button>
|
||||||
<button class="btn btn-secondary">
|
<button class="btn btn-secondary">
|
||||||
|
|||||||
+42
-22
@@ -301,7 +301,7 @@ app.post('/api/wget-clone', async (req, res) => {
|
|||||||
const { exec } = require('child_process');
|
const { exec } = require('child_process');
|
||||||
const containerId = require('os').hostname();
|
const containerId = require('os').hostname();
|
||||||
const cloneDir = directory.split('/').pop();
|
const cloneDir = directory.split('/').pop();
|
||||||
const hostDir = '/root/Desktop/Clonados';
|
const hostDir = req.body.outputDir || '/root/Desktop/Clonados';
|
||||||
exec(`mkdir -p ${hostDir} && cp -r ${directory} ${hostDir}/ 2>/dev/null || docker cp ${containerId}:${directory} ${hostDir}/ 2>/dev/null`, (err) => {
|
exec(`mkdir -p ${hostDir} && cp -r ${directory} ${hostDir}/ 2>/dev/null || docker cp ${containerId}:${directory} ${hostDir}/ 2>/dev/null`, (err) => {
|
||||||
if (err) console.log('⚠️ Sync to host failed:', err.message);
|
if (err) console.log('⚠️ Sync to host failed:', err.message);
|
||||||
else console.log('✅ Clone synced to host Desktop:', cloneDir);
|
else console.log('✅ Clone synced to host Desktop:', cloneDir);
|
||||||
@@ -378,7 +378,7 @@ app.post('/api/smart-clone', (req, res) => {
|
|||||||
const { exec } = require('child_process');
|
const { exec } = require('child_process');
|
||||||
const containerId = require('os').hostname();
|
const containerId = require('os').hostname();
|
||||||
const cloneDir = directory.split('/').pop();
|
const cloneDir = directory.split('/').pop();
|
||||||
const hostDir = '/root/Desktop/Clonados';
|
const hostDir = req.body.outputDir || '/root/Desktop/Clonados';
|
||||||
exec(`mkdir -p ${hostDir} && cp -r ${directory} ${hostDir}/ 2>/dev/null || docker cp ${containerId}:${directory} ${hostDir}/ 2>/dev/null`, (err) => {
|
exec(`mkdir -p ${hostDir} && cp -r ${directory} ${hostDir}/ 2>/dev/null || docker cp ${containerId}:${directory} ${hostDir}/ 2>/dev/null`, (err) => {
|
||||||
if (err) console.log('⚠️ SmartClone sync to host failed:', err.message);
|
if (err) console.log('⚠️ SmartClone sync to host failed:', err.message);
|
||||||
else console.log('✅ SmartClone synced to host Desktop:', cloneDir);
|
else console.log('✅ SmartClone synced to host Desktop:', cloneDir);
|
||||||
@@ -634,11 +634,11 @@ app.post('/api/ai/agent', async (req, res) => {
|
|||||||
|
|
||||||
// AI Inject Redesign Route (Pilar 1 - Agente Designer Real)
|
// AI Inject Redesign Route (Pilar 1 - Agente Designer Real)
|
||||||
app.post('/api/ai/inject-redesign', (req, res) => {
|
app.post('/api/ai/inject-redesign', (req, res) => {
|
||||||
const { cloneDir, appliedStyles, elementsRedesigned } = req.body;
|
const { cloneDir, appliedStyles, elementsRedesigned, outputDir, agentName } = req.body;
|
||||||
if (!cloneDir) return res.status(400).json({ error: 'cloneDir is required' });
|
if (!cloneDir) return res.status(400).json({ error: 'cloneDir is required' });
|
||||||
|
|
||||||
const folderName = cloneDir.split('/').pop();
|
const originalFolderName = cloneDir.split('/').pop();
|
||||||
const folderPath = path.join(__dirname, '..', 'cloned-sites', folderName);
|
const folderPath = path.join(__dirname, '..', 'cloned-sites', originalFolderName);
|
||||||
|
|
||||||
if (!fs.existsSync(folderPath)) {
|
if (!fs.existsSync(folderPath)) {
|
||||||
return res.status(404).json({ error: 'Cloned site folder not found' });
|
return res.status(404).json({ error: 'Cloned site folder not found' });
|
||||||
@@ -753,26 +753,46 @@ p, span, li, label, td, th {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const cssPath = path.join(folderPath, '__ai_redesign.css');
|
const newFolderName = `${originalFolderName}_${agentName || 'designer'}`;
|
||||||
fs.writeFileSync(cssPath, cssContent, 'utf8');
|
const newFolderPath = path.join(__dirname, '..', 'cloned-sites', newFolderName);
|
||||||
|
|
||||||
// 2. Injetar a tag <link> no index.html do clone
|
// Copy the original folder to the new folder
|
||||||
const indexPath = path.join(folderPath, 'index.html');
|
exec(`cp -r "${folderPath}" "${newFolderPath}"`, (copyErr) => {
|
||||||
if (fs.existsSync(indexPath)) {
|
if (copyErr) {
|
||||||
let html = fs.readFileSync(indexPath, 'utf8');
|
console.error('Error copying folder for agent redesign:', copyErr);
|
||||||
const linkTag = `\n<link rel="stylesheet" href="/__ai_redesign.css" id="__AI_REDESIGN_LINK__">\n`;
|
return res.status(500).json({ error: 'Failed to create new agent folder' });
|
||||||
|
|
||||||
if (!html.includes('__ai_redesign.css')) {
|
|
||||||
if (html.includes('</head>')) {
|
|
||||||
html = html.replace('</head>', linkTag + '</head>');
|
|
||||||
} else {
|
|
||||||
html = linkTag + html;
|
|
||||||
}
|
|
||||||
fs.writeFileSync(indexPath, html, 'utf8');
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
res.json({ success: true, message: 'AI Redesign CSS injected successfully' });
|
// 1. Criar o arquivo CSS de Redesign Ultra-Moderno (__ai_redesign.css) no novo diretório
|
||||||
|
const cssPath = path.join(newFolderPath, '__ai_redesign.css');
|
||||||
|
fs.writeFileSync(cssPath, cssContent, 'utf8');
|
||||||
|
|
||||||
|
// 2. Injetar a tag <link> no index.html do novo clone
|
||||||
|
const indexPath = path.join(newFolderPath, 'index.html');
|
||||||
|
if (fs.existsSync(indexPath)) {
|
||||||
|
let html = fs.readFileSync(indexPath, 'utf8');
|
||||||
|
const linkTag = `\n<link rel="stylesheet" href="/__ai_redesign.css" id="__AI_REDESIGN_LINK__">\n`;
|
||||||
|
|
||||||
|
if (!html.includes('__ai_redesign.css')) {
|
||||||
|
if (html.includes('</head>')) {
|
||||||
|
html = html.replace('</head>', linkTag + '</head>');
|
||||||
|
} else {
|
||||||
|
html = linkTag + html;
|
||||||
|
}
|
||||||
|
fs.writeFileSync(indexPath, html, 'utf8');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Sincronizar o novo diretório com o host
|
||||||
|
const hostDir = outputDir || '/root/Desktop/Clonados';
|
||||||
|
const containerId = require('os').hostname();
|
||||||
|
exec(`mkdir -p "${hostDir}" && cp -r "${newFolderPath}" "${hostDir}/" 2>/dev/null || docker cp ${containerId}:"${newFolderPath}" "${hostDir}/" 2>/dev/null`, (syncErr) => {
|
||||||
|
if (syncErr) console.log('⚠️ Redesign sync to host failed:', syncErr.message);
|
||||||
|
else console.log('✅ Redesign synced to host output dir:', newFolderName);
|
||||||
|
});
|
||||||
|
|
||||||
|
res.json({ success: true, message: 'AI Redesign CSS injected successfully', newFolderName });
|
||||||
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error injecting AI redesign:', err);
|
console.error('Error injecting AI redesign:', err);
|
||||||
res.status(500).json({ error: err.message });
|
res.status(500).json({ error: err.message });
|
||||||
|
|||||||
Reference in New Issue
Block a user