Monorepo for Aesthetic.Computer
aesthetic.computer
1// fix-tezos-network-prod.mjs - One-time function to fix tezos-kidlisp network in production
2// DELETE THIS FILE AFTER RUNNING ONCE
3
4import { connect } from "../../backend/database.mjs";
5import { hasAdmin } from "../../backend/authorization.mjs";
6
7export async function handler(event) {
8 // Require admin access
9 const authHeader = event.headers.authorization;
10 if (!authHeader) {
11 return {
12 statusCode: 401,
13 body: JSON.stringify({ error: "Authorization required" })
14 };
15 }
16
17 const token = authHeader.replace(/^Bearer /, "");
18 const isAdmin = await hasAdmin(token);
19
20 if (!isAdmin) {
21 return {
22 statusCode: 403,
23 body: JSON.stringify({ error: "Admin access required" })
24 };
25 }
26
27 try {
28 const database = await connect();
29 const secrets = database.db.collection("secrets");
30
31 // Check current value
32 const current = await secrets.findOne({ _id: "tezos-kidlisp" });
33
34 const log = [];
35 log.push("Current configuration:");
36 log.push(` - address: ${current.address}`);
37 log.push(` - network: ${current.network}`);
38
39 if (current.network === "mainnet") {
40 log.push("\n✅ Already set to mainnet!");
41 await database.disconnect();
42 return {
43 statusCode: 200,
44 body: JSON.stringify({ message: log.join("\n"), changed: false })
45 };
46 }
47
48 // Update to mainnet
49 log.push("\n🔧 Updating network from 'ghostnet' to 'mainnet'...");
50
51 const result = await secrets.updateOne(
52 { _id: "tezos-kidlisp" },
53 { $set: { network: "mainnet" } }
54 );
55
56 if (result.modifiedCount > 0) {
57 log.push("✅ Successfully updated!");
58
59 // Verify
60 const updated = await secrets.findOne({ _id: "tezos-kidlisp" });
61 log.push("\nVerified:");
62 log.push(` - address: ${updated.address}`);
63 log.push(` - network: ${updated.network}`);
64 }
65
66 await database.disconnect();
67
68 return {
69 statusCode: 200,
70 headers: { "Content-Type": "application/json" },
71 body: JSON.stringify({
72 message: log.join("\n"),
73 changed: true,
74 result: result.modifiedCount
75 })
76 };
77 } catch (error) {
78 return {
79 statusCode: 500,
80 body: JSON.stringify({ error: error.message })
81 };
82 }
83}