import { createDb } from "db"; import type { BlobRef } from "db/schema"; import * as dbschema from "db/schema"; const db = createDb(); const COLLECTION = "ca.ansxor.catnip.track"; const SAMPLE_DIDS = [ "did:plc:ragtjsm2j2vknwkz3zp4oxrd", "did:plc:7iza6de2dwap2sbkpav7c6c6", "did:plc:ewvi7nxzyoun6zhxrhs64oiz", "did:plc:ia76kvnndjutgedggx2ibrem", "did:plc:z72i7hdynmk6r22z27h6tvur", ]; const SAMPLE_TITLES = [ "Midnight Echoes", "Solar Flare", "Velvet Haze", "Neon Dreams", "Crystal Waves", "Amber Glow", "Static Bloom", "Phantom Drift", "Cobalt Rain", "Hollow Sun", ]; function generateTid(): string { const now = BigInt(Date.now()) * 1000n; const clockId = BigInt(Math.floor(Math.random() * 1024)); const tid = (now << 10n) | clockId; const chars = "234567abcdefghijklmnopqrstuvwxyz"; let result = ""; let remaining = tid; for (let i = 0; i < 13; i++) { result = chars[Number(remaining & 31n)] + result; remaining >>= 5n; } return result; } function randomCid(): string { const bytes = crypto.getRandomValues(new Uint8Array(32)); return ( "bafyrei" + Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("") ); } const did = SAMPLE_DIDS[Math.floor(Math.random() * SAMPLE_DIDS.length)]; const rkey = generateTid(); const uri = `at://${did}/${COLLECTION}/${rkey}`; const cid = randomCid(); const title = SAMPLE_TITLES[Math.floor(Math.random() * SAMPLE_TITLES.length)]; const audioBlobRef: BlobRef = { $type: "blob", ref: { $link: randomCid() }, mimeType: "audio/ogg", size: Math.floor(Math.random() * 10_000_000) + 1_000_000, }; const now = new Date(); await db.insert(dbschema.tracks).values({ uri, did, rkey, cid, title, createdAt: now, audio: audioBlobRef, }); // Create an artist entry for the DID and link it const [artist] = await db .insert(dbschema.artists) .values({ did }) .onConflictDoNothing() .returning(); const artistId = artist?.id ?? (await db.query.artists.findFirst({ where: (a, { eq }) => eq(a.did, did) }))! .id; await db.insert(dbschema.trackArtists).values({ trackUri: uri, artistId, position: 0, }); console.log(uri); process.exit(0);