feat: complete NutriScan redesign

This commit is contained in:
evandrodevbr committed 2026-07-16 16:31:50 -03:00
1 parent c1fe4af997
commit f71cd167b3
163 files changed
+30802 -14169

No files matched your search

+41 -7
View File
@@ -331,16 +331,50 @@ export class JsonCacheManager {
let saved = 0;
let failed = 0;
for (const product of products) {
const success = await this.saveProduct(product);
if (success) {
saved++;
} else {
failed++;
try {
await this.loadCache();
if (!this.cacheData) {
this.cacheData = {
products: {},
lastUpdated: 0,
version: "1.0.0",
};
}
// Adiciona todos os produtos ao objeto em memória primeiro
for (const product of products) {
try {
const code = product.code;
const existingProduct = this.cacheData.products[code];
if (existingProduct) {
this.cacheData.products[code] = this.mergeProductData(
existingProduct,
product
);
console.log(`[JSON Cache] Produto atualizado na memória: ${code}`);
} else {
this.cacheData.products[code] = this.convertToCachedProduct(product);
console.log(`[JSON Cache] Produto adicionado na memória: ${code}`);
}
saved++;
} catch (err) {
failed++;
}
}
// Salva no disco uma única vez após processar todo o lote
if (saved > 0) {
this.cacheData.lastUpdated = Date.now();
await this.saveCache();
console.log(`[JSON Cache] Lote salvo no disco! Total processado: ${saved} produtos.`);
}
} catch (error) {
console.error("[JSON Cache] Erro ao salvar lote de produtos:", error);
}
console.log(`[JSON Cache] Salvos: ${saved}, Falharam: ${failed}`);
return { saved, failed };
}
+7 -7
View File
@@ -217,14 +217,14 @@ export function sortProducts(
// Funções Auxiliares de Baixo Nível
function calculateCompletenessScore(p: Product): number {
let s = 0;
if (p.product_name) s += 10;
if (p.product_name) s += 20;
if (p.brands) s += 10;
if (p.image_url) s += 15;
if (p.nutriments?.energy_100g !== undefined) s += 20;
if (p.nutrition_grades) s += 15;
if (p.nova_group) s += 10;
if (p.ingredients_text) s += 10;
if (p.categories) s += 10;
if (p.image_url || p.image_front_url || p.image_front_small_url || p.image_small_url) s += 30;
if (p.nutriments?.energy_100g !== undefined) s += 15;
if (p.nutrition_grades) s += 10;
if (p.nova_group) s += 5;
if (p.ingredients_text) s += 5;
if (p.categories) s += 5;
return s;
}