diff --git a/api/dropbox-sync.js b/api/dropbox-sync.js index eccf8bb..00ffd63 100644 --- a/api/dropbox-sync.js +++ b/api/dropbox-sync.js @@ -44,14 +44,21 @@ export default async function handler(req, res) { const { data: existingProducts } = await supabase .from('products') .select('product_id, status'); - - // Only skip if status is 'edited' or 'pending' (manual edits) + + // Protect products with status 'edited' or 'pending' const manuallyEditedIds = new Set( (existingProducts || []) .filter(p => p.status === 'edited' || p.status === 'pending') .map(p => p.product_id) ); + // Also protect any product that has history entries — they were edited at some point. + // If their status was accidentally reset to 'excel', this restores protection. + const { data: historyProducts } = await supabase + .from('products_history') + .select('product_id'); + (historyProducts || []).forEach(h => manuallyEditedIds.add(h.product_id)); + const productsToUpsert = []; for (const row of rows) { const productId = String(row[articleNoIdx]);