-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent1_audit.js
More file actions
60 lines (47 loc) · 1.92 KB
/
Copy pathagent1_audit.js
File metadata and controls
60 lines (47 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const { createClient } = require('@supabase/supabase-js');
const dotenv = require('dotenv');
const fs = require('fs');
const path = require('path');
const envPath = path.resolve(__dirname, '.env.local');
const envConfig = dotenv.parse(fs.readFileSync(envPath));
for (const k in envConfig) {
process.env[k] = envConfig[k];
}
const supabase = createClient(process.env.NEXT_PUBLIC_SUPABASE_URL, process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY);
async function audit() {
console.log("Starting Agent 1 Audit...");
const { data: products, error } = await supabase
.from('products')
.select('id, name, slug, description')
.order('name');
if (error) { console.error(error); return; }
const report = [];
const urlMap = new Map();
for (const p of products) {
const { data: images } = await supabase.from('product_images').select('url, is_primary').eq('product_id', p.id);
// Check 1: Duplicate Images
if (images) {
images.forEach(img => {
if (urlMap.has(img.url)) {
report.push({
type: "DUPLICATE_IMAGE_USE",
product: p.name,
other_product: urlMap.get(img.url),
url: img.url
});
} else {
urlMap.set(img.url, p.name);
}
});
}
// Check 2: Color Mismatch (Heuristic)
const nameLower = p.name.toLowerCase();
if (nameLower.includes('rose') || nameLower.includes('pink')) {
// We can't check image color programmatically without logic, but we can check if we previously flagged it
}
console.log(`Audited: ${p.name} - ${images ? images.length : 0} images`);
}
console.log("\n--- VIOLATION REPORT ---");
console.log(JSON.stringify(report, null, 2));
}
audit();