Something went wrong. Try again.
Monorepo for Aesthetic.Computer aesthetic.computer
Something went wrong. Try again.
3.2 kB ยท 118 lines
JavaScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119import { connect } from "./system/backend/database.mjs";import fs from "fs";
async function main() { console.log("๐ Connecting to database..."); const { db, disconnect } = await connect();
try { const data = { chats: [], handles: [], moods: [], paintings: [] };
// 1. Fetch Handles (Map user sub -> handle) console.log("๐ค Fetching handles..."); const handlesCollection = db.collection("@handles"); const allHandlesDocs = await handlesCollection.find({}).toArray(); const userToHandle = {}; allHandlesDocs.forEach(doc => { if (doc.handle) { userToHandle[doc._id] = "@" + doc.handle; data.handles.push("@" + doc.handle); } }); console.log(` Found ${data.handles.length} handles.`);
// Helper to resolve user const resolveUser = (userSub) => userToHandle[userSub] || "anon";
// 2. Fetch Chat Messages (Clock) console.log("๐ฐ๏ธ Fetching Clock chat..."); const clockCollection = db.collection("chat-clock"); const clockMessages = await clockCollection .find({}) .sort({ when: -1 }) .limit(50) .toArray(); clockMessages.forEach(msg => { data.chats.push({ from: resolveUser(msg.user), text: msg.text, when: msg.when, source: "clock" }); });
// 3. Fetch Chat Messages (System) console.log("๐ฌ Fetching System chat..."); const systemCollection = db.collection("chat-system"); const systemMessages = await systemCollection .find({}) .sort({ when: -1 }) .limit(50) .toArray();
systemMessages.forEach(msg => { data.chats.push({ from: resolveUser(msg.user), text: msg.text, when: msg.when, source: "system" }); }); console.log(` Found ${data.chats.length} total chat messages.`);
// 4. Fetch Moods console.log("๐ Fetching Moods..."); const moodsCollection = db.collection("moods"); const recentMoods = await moodsCollection .find({ deleted: { $ne: true } }) .sort({ when: -1 }) .limit(50) .toArray();
recentMoods.forEach(mood => { data.moods.push({ handle: resolveUser(mood.user), text: mood.mood, when: mood.when }); }); console.log(` Found ${data.moods.length} moods.`);
// 5. Fetch Paintings console.log("๐จ Fetching Paintings..."); const paintingsCollection = db.collection("paintings"); const recentPaintings = await paintingsCollection .find({}) .sort({ when: -1 }) .limit(50) .toArray();
recentPaintings.forEach(p => { data.paintings.push({ code: p.slug, // Assuming slug is the code user: resolveUser(p.user), when: p.when }); }); console.log(` Found ${data.paintings.length} paintings.`);
// Save to file fs.writeFileSync("wire_data.json", JSON.stringify(data, null, 2)); console.log("๐พ Saved data to wire_data.json");
} catch (err) { console.error("โ Error:", err); } finally { await disconnect(); console.log("๐ Disconnected."); }}
main();