This repository has no description
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798import { 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 itconst [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);