Update proxy-server.js
This commit is contained in:
parent
8015155f6d
commit
99c6e97f67
|
@ -10,10 +10,10 @@ const app = express();
|
||||||
const upload = multer({ storage: multer.memoryStorage() });
|
const upload = multer({ storage: multer.memoryStorage() });
|
||||||
|
|
||||||
// Configurações do modelo NSFW
|
// Configurações do modelo NSFW
|
||||||
const NSFW_THRESHOLD = 0.2; // Limiar para detecção de conteúdo explícito
|
const NSFW_THRESHOLD = 0.15; // Reduzido para ser mais sensível
|
||||||
const NSFW_CATEGORIES = ['porn', 'sexy', 'hentai', 'drawings', 'neutral', 'violence', 'gore'];
|
const NSFW_CATEGORIES = ['porn', 'sexy', 'hentai', 'drawings', 'neutral', 'violence', 'gore'];
|
||||||
|
|
||||||
// Lista de palavras-chave bloqueadas (baseada em filtros do Google, Instagram e Facebook)
|
// Lista de palavras-chave bloqueadas
|
||||||
const BLOCKED_KEYWORDS = [
|
const BLOCKED_KEYWORDS = [
|
||||||
// Palavras em português
|
// Palavras em português
|
||||||
'porn', 'sex', 'xxx', 'adult', 'nude', 'naked', 'nsfw', '18+',
|
'porn', 'sex', 'xxx', 'adult', 'nude', 'naked', 'nsfw', '18+',
|
||||||
|
@ -67,28 +67,43 @@ async function checkNSFW(file) {
|
||||||
const isVideo = ['.mp4', '.avi', '.mov', '.wmv', '.flv', '.mkv', '.webm'].includes(fileExt);
|
const isVideo = ['.mp4', '.avi', '.mov', '.wmv', '.flv', '.mkv', '.webm'].includes(fileExt);
|
||||||
|
|
||||||
if (isImage) {
|
if (isImage) {
|
||||||
|
// Processa a imagem em diferentes tamanhos para melhor detecção
|
||||||
const image = await tf.node.decodeImage(file.buffer);
|
const image = await tf.node.decodeImage(file.buffer);
|
||||||
const predictions = await model.classify(image);
|
const resized = tf.image.resizeBilinear(image, [224, 224]);
|
||||||
|
const expanded = resized.expandDims(0);
|
||||||
const nsfwScore = predictions.reduce((score, pred) => {
|
const normalized = expanded.div(255.0);
|
||||||
if (NSFW_CATEGORIES.includes(pred.className)) {
|
|
||||||
return score + pred.probability;
|
|
||||||
}
|
|
||||||
return score;
|
|
||||||
}, 0);
|
|
||||||
|
|
||||||
|
const predictions = await model.predict(normalized).data();
|
||||||
|
|
||||||
|
// Libera a memória
|
||||||
image.dispose();
|
image.dispose();
|
||||||
|
resized.dispose();
|
||||||
|
expanded.dispose();
|
||||||
|
normalized.dispose();
|
||||||
|
|
||||||
|
// Calcula o score NSFW
|
||||||
|
const nsfwScore = predictions[1]; // Índice 1 é geralmente a classe NSFW
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isNSFW: nsfwScore > NSFW_THRESHOLD,
|
isNSFW: nsfwScore > NSFW_THRESHOLD,
|
||||||
score: nsfwScore,
|
score: nsfwScore,
|
||||||
type: 'image'
|
type: 'image',
|
||||||
|
details: {
|
||||||
|
safe: predictions[0],
|
||||||
|
nsfw: predictions[1]
|
||||||
|
}
|
||||||
};
|
};
|
||||||
} else if (isVideo) {
|
} else if (isVideo) {
|
||||||
|
// Para vídeos, verifica o nome e extensão
|
||||||
|
const isBlocked = isBlockedFilename(file.originalname);
|
||||||
return {
|
return {
|
||||||
isNSFW: isBlockedFilename(file.originalname),
|
isNSFW: isBlocked,
|
||||||
score: 1.0,
|
score: isBlocked ? 1.0 : 0.0,
|
||||||
type: 'video'
|
type: 'video',
|
||||||
|
details: {
|
||||||
|
filename: file.originalname,
|
||||||
|
size: file.size
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,12 +134,10 @@ function isBlockedUrl(url) {
|
||||||
const urlObj = new URL(url);
|
const urlObj = new URL(url);
|
||||||
const lowerUrl = url.toLowerCase();
|
const lowerUrl = url.toLowerCase();
|
||||||
|
|
||||||
// Verifica domínios bloqueados
|
|
||||||
if (BLOCKED_DOMAINS.some(domain => urlObj.hostname.includes(domain))) {
|
if (BLOCKED_DOMAINS.some(domain => urlObj.hostname.includes(domain))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verifica palavras-chave na URL
|
|
||||||
return BLOCKED_KEYWORDS.some(keyword => lowerUrl.includes(keyword));
|
return BLOCKED_KEYWORDS.some(keyword => lowerUrl.includes(keyword));
|
||||||
} catch {
|
} catch {
|
||||||
return false;
|
return false;
|
||||||
|
@ -170,7 +183,8 @@ app.post('/upload', upload.single('file'), async (req, res) => {
|
||||||
reject: 'Recusar'
|
reject: 'Recusar'
|
||||||
},
|
},
|
||||||
type: nsfwCheck.type,
|
type: nsfwCheck.type,
|
||||||
score: nsfwCheck.score
|
score: nsfwCheck.score,
|
||||||
|
details: nsfwCheck.details
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,7 +210,6 @@ const proxy = createProxyMiddleware({
|
||||||
'^/api': ''
|
'^/api': ''
|
||||||
},
|
},
|
||||||
onProxyReq: (proxyReq, req, res) => {
|
onProxyReq: (proxyReq, req, res) => {
|
||||||
// Verifica URLs bloqueadas
|
|
||||||
if (isBlockedUrl(req.url)) {
|
if (isBlockedUrl(req.url)) {
|
||||||
res.status(403).json({
|
res.status(403).json({
|
||||||
error: '🚫 CONTEÚDO BLOQUEADO',
|
error: '🚫 CONTEÚDO BLOQUEADO',
|
||||||
|
|
Loading…
Reference in New Issue