Monorepo for Aesthetic.Computer
aesthetic.computer
1#!/usr/bin/env node
2// Sync missing kidlisp records for @jeffrey to ATProto
3
4import { connect } from "../../system/backend/database.mjs";
5import { createMediaRecord, MediaTypes } from "../../system/backend/media-atproto.mjs";
6
7const isDryRun = process.argv[2] !== 'live';
8
9async function main() {
10 console.log(`\n🔄 SYNC @JEFFREY KIDLISP TO ATPROTO`);
11 console.log(` Mode: ${isDryRun ? '🔍 DRY RUN' : '⚡ LIVE'}\n`);
12
13 const database = await connect();
14
15 // Get @jeffrey user
16 const jeffreyUser = await database.db.collection('users').findOne({'atproto.handle': 'jeffrey.at.aesthetic.computer'});
17 if (!jeffreyUser) {
18 console.error('❌ @jeffrey user not found');
19 await database.disconnect();
20 process.exit(1);
21 }
22
23 // Find kidlisp missing rkey
24 const kidlispCollection = database.db.collection('kidlisp');
25 const missing = await kidlispCollection.find({
26 user: jeffreyUser._id,
27 $or: [
28 { 'atproto.rkey': { $exists: false } },
29 { 'atproto.rkey': null }
30 ]
31 }).toArray();
32
33 console.log(`📝 Found ${missing.length} kidlisp records missing ATProto records`);
34
35 if (missing.length === 0) {
36 console.log('✅ All kidlisp already synced!');
37 await database.disconnect();
38 process.exit(0);
39 }
40
41 if (isDryRun) {
42 console.log(`\n🔍 DRY RUN - Would create ATProto records for:`);
43 missing.forEach(k => {
44 console.log(` - ${k.code}: "${k.source?.substring(0, 50)}..."`);
45 });
46 console.log(`\n💡 Run with 'live' argument to apply changes`);
47 await database.disconnect();
48 process.exit(0);
49 }
50
51 // Create ATProto records
52 let created = 0;
53 let failed = 0;
54
55 for (const kidlisp of missing) {
56 try {
57 const result = await createMediaRecord(
58 database,
59 MediaTypes.KIDLISP,
60 kidlisp,
61 { userSub: jeffreyUser._id }
62 );
63
64 if (result.error) {
65 console.log(`⚠️ Failed ${kidlisp.code}: ${result.error}`);
66 failed++;
67 } else {
68 console.log(`✅ Created ${kidlisp.code} → rkey: ${result.rkey}`);
69 created++;
70 }
71 } catch (error) {
72 console.error(`❌ Error creating ${kidlisp.code}:`, error.message);
73 failed++;
74 }
75 }
76
77 console.log(`\n📊 Results:`);
78 console.log(` ✅ Created: ${created}`);
79 console.log(` ❌ Failed: ${failed}`);
80
81 await database.disconnect();
82 process.exit(0);
83}
84
85main().catch(err => {
86 console.error('❌ Error:', err);
87 process.exit(1);
88});