CognxSafeTrack
chore: execute Sprint 38 technical debt resolution (Type Safety, Zod validation, Vitest, Mock LLM extracted)
d9879cf | import dotenv from 'dotenv'; | |
| dotenv.config({ path: '/Volumes/sms/edtech/.env' }); | |
| const { R2_ACCOUNT_ID, R2_BUCKET, R2_ACCESS_KEY_ID, R2_SECRET_ACCESS_KEY, R2_PUBLIC_URL } = process.env; | |
| if (!R2_ACCOUNT_ID || !R2_BUCKET || !R2_ACCESS_KEY_ID || !R2_SECRET_ACCESS_KEY || !R2_PUBLIC_URL) { | |
| console.error('β Missing R2 credentials'); process.exit(1); | |
| } | |
| import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3'; | |
| import fs from 'fs'; | |
| import path from 'path'; | |
| const ARTIFACTS_DIR = '/Users/macbookair/.gemini/antigravity/brain/ea618d02-1ee0-47c1-a2b7-aed00a3604bc'; | |
| const FALLBACK_IMG = path.join(ARTIFACTS_DIR, 'xaml_t1_j1_activity_1772065123770.png'); // branding fallback | |
| // Map: source filename β R2 key β JSON assignment (track + dayNumber) | |
| const IMAGE_MAP: Array<{ src: string; dest: string }> = [ | |
| // T2 | |
| { src: 't2_j1_revenus_1772296601828.png', dest: 'images/t2/bes1_revenus.png' }, | |
| { src: 't2_j2_marge_1772296618658.png', dest: 'images/t2/bes2_marge.png' }, | |
| { src: 't2_j3_rentabilite_1772296633763.png', dest: 'images/t2/bes3_rentabilite.png' }, | |
| { src: 't2_j4_fidelite_1772296648717.png', dest: 'images/t2/bes4_fidelite.png' }, | |
| { src: 't2_j5_cashflow_1772296699245.png', dest: 'images/t2/bes5_cashflow.png' }, | |
| { src: 't2_j6_investissement_1772296715463.png', dest: 'images/t2/bes6_investissement.png' }, | |
| { src: 't2_j7_bilan_1772296730048.png', dest: 'images/t2/bes7_bilan.png' }, | |
| // T3 | |
| { src: 't3_j1_emotion_1772296748716.png', dest: 'images/t3/bes1_emotion.png' }, | |
| { src: 't3_j2_argumentaire_1772296787528.png', dest: 'images/t3/bes2_argumentaire.png' }, | |
| { src: 't3_j3_objections_1772296804714.png', dest: 'images/t3/bes3_objections.png' }, | |
| { src: 't3_j4_storytelling_1772296820146.png', dest: 'images/t3/bes4_storytelling.png' }, | |
| { src: 't3_j5_whatsapp_script_1772296833989.png', dest: 'images/t3/bes5_whatsapp_script.png' }, | |
| { src: 't3_j6_pitch30s_1772296923075.png', dest: 'images/t3/bes6_pitch30s.png' }, | |
| { src: 't3_j7_pitch2min_1772296939049.png', dest: 'images/t3/bes7_pitch2min.png' }, | |
| { src: 't3_j8_simulation_1772296954409.png', dest: 'images/t3/bes8_simulation.png' }, | |
| // T4 | |
| { src: 't4_j1_formalisation_1772296968288.png', dest: 'images/t4/bes1_formalisation.png' }, | |
| { src: 't4_j2_avantages_fiscaux_1772297020898.png', dest: 'images/t4/bes2_avantages_fiscaux.png' }, | |
| ]; | |
| const client = new S3Client({ | |
| region: 'auto', | |
| endpoint: `https://${R2_ACCOUNT_ID}.r2.cloudflarestorage.com`, | |
| credentials: { accessKeyId: R2_ACCESS_KEY_ID!, secretAccessKey: R2_SECRET_ACCESS_KEY! }, | |
| }); | |
| async function uploadImg(srcFile: string, dest: string): Promise<string> { | |
| const srcPath = fs.existsSync(path.join(ARTIFACTS_DIR, srcFile)) | |
| ? path.join(ARTIFACTS_DIR, srcFile) | |
| : FALLBACK_IMG; | |
| const buf = fs.readFileSync(srcPath); | |
| await client.send(new PutObjectCommand({ | |
| Bucket: R2_BUCKET!, | |
| Key: dest, | |
| Body: buf, | |
| ContentType: 'image/png', | |
| CacheControl: 'public, max-age=31536000' | |
| })); | |
| return `${R2_PUBLIC_URL!.replace(/\/$/, '')}/${dest}`; | |
| } | |
| async function main() { | |
| console.log(`\nπ Uploading T2βT4 images to R2 bucket: ${R2_BUCKET}\n`); | |
| let ok = 0, failed = 0; | |
| for (const { src, dest } of IMAGE_MAP) { | |
| try { | |
| await uploadImg(src, dest); | |
| console.log(`β ${dest}`); | |
| ok++; | |
| } catch (e: unknown) { | |
| console.error(`β ${dest}: ${(e instanceof Error ? (e instanceof Error ? e.message : String(e)) : String(e))}`); | |
| failed++; | |
| } | |
| } | |
| console.log(`\nββ RΓSULTAT ββ`); | |
| console.log(`β Uploaded: ${ok}/${IMAGE_MAP.length}`); | |
| if (failed > 0) process.exit(1); | |
| } | |
| main().catch(e => { console.error(e); process.exit(1); }); | |