this repo has no description
1import { createDb } from "db";
2import type { BlobRef } from "db/schema";
3import * as dbschema from "db/schema";
4
5const db = createDb();
6
7const COLLECTION = "ca.ansxor.catnip.track";
8
9const SAMPLE_DIDS = [
10 "did:plc:ragtjsm2j2vknwkz3zp4oxrd",
11 "did:plc:7iza6de2dwap2sbkpav7c6c6",
12 "did:plc:ewvi7nxzyoun6zhxrhs64oiz",
13 "did:plc:ia76kvnndjutgedggx2ibrem",
14 "did:plc:z72i7hdynmk6r22z27h6tvur",
15];
16
17const SAMPLE_TITLES = [
18 "Midnight Echoes",
19 "Solar Flare",
20 "Velvet Haze",
21 "Neon Dreams",
22 "Crystal Waves",
23 "Amber Glow",
24 "Static Bloom",
25 "Phantom Drift",
26 "Cobalt Rain",
27 "Hollow Sun",
28];
29
30function generateTid(): string {
31 const now = BigInt(Date.now()) * 1000n;
32 const clockId = BigInt(Math.floor(Math.random() * 1024));
33 const tid = (now << 10n) | clockId;
34 const chars = "234567abcdefghijklmnopqrstuvwxyz";
35 let result = "";
36 let remaining = tid;
37 for (let i = 0; i < 13; i++) {
38 result = chars[Number(remaining & 31n)] + result;
39 remaining >>= 5n;
40 }
41 return result;
42}
43
44function randomCid(): string {
45 const bytes = crypto.getRandomValues(new Uint8Array(32));
46 return (
47 "bafyrei" +
48 Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("")
49 );
50}
51
52const did = SAMPLE_DIDS[Math.floor(Math.random() * SAMPLE_DIDS.length)];
53const rkey = generateTid();
54const uri = `at://${did}/${COLLECTION}/${rkey}`;
55const cid = randomCid();
56const title = SAMPLE_TITLES[Math.floor(Math.random() * SAMPLE_TITLES.length)];
57
58const audioBlobRef: BlobRef = {
59 $type: "blob",
60 ref: { $link: randomCid() },
61 mimeType: "audio/ogg",
62 size: Math.floor(Math.random() * 10_000_000) + 1_000_000,
63};
64
65const now = new Date();
66
67await db.insert(dbschema.tracks).values({
68 uri,
69 did,
70 rkey,
71 cid,
72 title,
73 createdAt: now,
74 audio: audioBlobRef,
75});
76
77// Create an artist entry for the DID and link it
78const [artist] = await db
79 .insert(dbschema.artists)
80 .values({ did })
81 .onConflictDoNothing()
82 .returning();
83
84const artistId =
85 artist?.id ??
86 (await db.query.artists.findFirst({ where: (a, { eq }) => eq(a.did, did) }))!
87 .id;
88
89await db.insert(dbschema.trackArtists).values({
90 trackUri: uri,
91 artistId,
92 position: 0,
93});
94
95console.log(uri);
96
97process.exit(0);