Atualização automática: 2026-05-23 20:55:21

This commit is contained in:
Hermes
2026-05-23 20:55:21 +00:00
parent a81e273364
commit 7cfc1724d3
4 changed files with 73 additions and 33 deletions
+43 -23
View File
@@ -301,7 +301,7 @@ app.post('/api/wget-clone', async (req, res) => {
const { exec } = require('child_process');
const containerId = require('os').hostname();
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) => {
if (err) console.log('⚠️ Sync to host failed:', err.message);
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 containerId = require('os').hostname();
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) => {
if (err) console.log('⚠️ SmartClone sync to host failed:', err.message);
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)
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' });
const folderName = cloneDir.split('/').pop();
const folderPath = path.join(__dirname, '..', 'cloned-sites', folderName);
const originalFolderName = cloneDir.split('/').pop();
const folderPath = path.join(__dirname, '..', 'cloned-sites', originalFolderName);
if (!fs.existsSync(folderPath)) {
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');
fs.writeFileSync(cssPath, cssContent, 'utf8');
// 2. Injetar a tag <link> no index.html do clone
const indexPath = path.join(folderPath, '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');
const newFolderName = `${originalFolderName}_${agentName || 'designer'}`;
const newFolderPath = path.join(__dirname, '..', 'cloned-sites', newFolderName);
// Copy the original folder to the new folder
exec(`cp -r "${folderPath}" "${newFolderPath}"`, (copyErr) => {
if (copyErr) {
console.error('Error copying folder for agent redesign:', copyErr);
return res.status(500).json({ error: 'Failed to create new agent folder' });
}
}
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) {
console.error('Error injecting AI redesign:', err);
res.status(500).json({ error: err.message });