fix: header sizes, transform image crop, sidebar accordion dropdown

This commit is contained in:
VPS 4 Builder
2026-05-25 04:06:00 +02:00
parent fa351efae7
commit 6153ac0ed0
4 changed files with 136 additions and 19 deletions
+81 -5
View File
@@ -41,6 +41,8 @@ const io = socketIo(server, {
maxHttpBufferSize: 5e7 // 50MB para suportar raios-x grandes
});
const connectedClients = [];
const PORT = process.env.PORT || 3000;
const UPLOAD_DIR = process.env.UPLOAD_DIR || path.join(__dirname, 'uploads');
const PROCESSED_DIR = process.env.PROCESSED_DIR || path.join(__dirname, 'processed');
@@ -72,6 +74,43 @@ app.get('/status', (req, res) => {
});
});
// Verificar se o nome do computador/cliente já existe
app.get('/api/clients/check-name', async (req, res) => {
try {
const name = (req.query.name || '').trim();
const token = req.query.token || req.headers['x-api-key'] || req.headers['authorization']?.split(' ')[1];
const clientId = req.query.clientId || '';
const serverApiKey = process.env.CLIENT_API_KEY || 'rf-dental-secure-key-2026';
if (token !== serverApiKey) {
return res.status(401).json({ success: false, error: 'Chave de API inválida' });
}
if (!name) {
return res.status(400).json({ success: false, error: 'Nome não fornecido' });
}
// 1. Verificar se existe no banco de dados na tabela images (busca case-insensitive)
const row = await db.get('SELECT COUNT(*) as count FROM images WHERE LOWER(client_name) = LOWER(?)', [name]);
const existsInDb = row && row.count > 0;
// 2. Verificar se existe algum cliente atualmente conectado com esse nome (desconsiderando o próprio clientId)
const existsConnected = connectedClients.some(c =>
c.name.toLowerCase() === name.toLowerCase() &&
(!clientId || c.clientId !== clientId)
);
if (existsInDb || existsConnected) {
return res.json({ success: true, available: false, exists: true });
}
res.json({ success: true, available: true, exists: false });
} catch (error) {
console.error('Erro ao verificar nome do cliente:', error);
res.status(500).json({ success: false, error: error.message });
}
});
// Debug endpoint for browser logs
app.post('/api/debug-log', (req, res) => {
console.log('=== BROWSER HTML ===');
@@ -454,7 +493,8 @@ async function checkInstallationMiddleware(req, res, next) {
req.path.startsWith('/status') ||
req.path.startsWith('/socket.io') ||
req.path.startsWith('/api/auth') ||
req.path.startsWith('/api/install')) {
req.path.startsWith('/api/install') ||
req.path.startsWith('/api/clients/check-name')) {
return next();
}
@@ -551,8 +591,6 @@ io.use((socket, next) => {
}
});
const connectedClients = [];
io.on('connection', (socket) => {
console.log('📱 Cliente conectado:', socket.id);
console.log('📱 Socket transport:', socket.conn.transport.name);
@@ -587,18 +625,56 @@ io.on('connection', (socket) => {
console.log('👤 Cliente identificado:', data?.type || 'SEM TYPE', data?.name || 'SEM NAME');
console.log('👤 Dados completos:', JSON.stringify(data, null, 2));
if (!data || !data.type) {
if (!data || !data.type || !data.name) {
console.error('❌ [client-identify] Dados inválidos:', data);
socket.emit('error', { message: 'Dados de identificação inválidos' });
return;
}
const clientName = data.name.trim();
const clientId = data.clientId || '';
// 1. Validar unicidade em relação aos clientes já conectados
const duplicate = connectedClients.find(c =>
c.name.toLowerCase() === clientName.toLowerCase() &&
c.clientId !== clientId
);
if (duplicate) {
console.log(`❌ [client-identify] Conexão rejeitada: O nome "${clientName}" já está em uso por outro dispositivo.`);
socket.emit('error', {
message: `O nome "${clientName}" já está sendo usado por outro computador neste servidor. Escolha um nome exclusivo.`
});
setTimeout(() => {
socket.disconnect(true);
}, 500);
return;
}
// 2. Se for uma reconexão do mesmo clientId, desconectar e limpar os sockets antigos do mesmo cliente
const oldConnections = connectedClients.filter(c =>
c.clientId === clientId && c.socketId !== socket.id
);
for (const old of oldConnections) {
console.log(`🔄 Desconectando socket antigo ${old.socketId} para o mesmo clientId ${clientId}`);
const oldSocket = io.sockets.sockets.get(old.socketId);
if (oldSocket) {
oldSocket.emit('error', { message: 'Nova conexão estabelecida deste computador.' });
oldSocket.disconnect(true);
}
const idx = connectedClients.indexOf(old);
if (idx > -1) {
connectedClients.splice(idx, 1);
}
}
const clientInfo = {
socketId: socket.id,
type: data.type || 'unknown',
name: data.name || 'Unknown',
name: clientName,
version: data.version || '1.0.0',
system: data.system || 'unknown',
clientId: clientId,
connectedAt: new Date().toISOString()
};