File size: 3,810 Bytes
ab7ffa3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
489821f
ab7ffa3
 
d9879cf
 
ab7ffa3
 
 
 
 
 
 
 
 
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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); });