A decentralized music tracking and discovery platform built on AT Protocol 馃幍
at 2b044aaed2c433aca9688cbd767408dc80f1fc4f 112 lines 2.9 kB view raw
1import chalk from "chalk"; 2import { ctx } from "context"; 3import * as FeedGenerator from "lexicon/types/app/rocksky/feed/generator"; 4import { createAgent } from "lib/agent"; 5import prompts from "prompts"; 6 7const args = process.argv.slice(2); 8 9if (args.length === 0) { 10 console.error("Please provide user author identifier (handle or DID)."); 11 console.log(`Usage: ${chalk.cyan("npm run feed -- <handle|did>")}`); 12 process.exit(1); 13} 14 15const name = await prompts({ 16 type: "text", 17 name: "value", 18 message: "What is the feed name?", 19}); 20 21if (name.value.length < 3 || name.value.length > 240) { 22 console.error("Feed name must be between 3 and 240 characters."); 23 process.exit(1); 24} 25 26const description = await prompts({ 27 type: "text", 28 name: "value", 29 message: "Please provide a short description of the feed", 30}); 31 32if (description.value.length > 3000) { 33 console.error("Description is too long. Maximum length is 3000 characters."); 34 process.exit(1); 35} 36 37const did = await prompts({ 38 type: "text", 39 name: "value", 40 message: "What is the feed DID?", 41}); 42 43if (!/^did:web:[a-zA-Z0-9_.-]{3,30}$/.test(did.value)) { 44 console.error( 45 "Invalid DID format. It should start with 'did:web:' followed by 3 to 30 alphanumeric characters, underscores, hyphens, or periods." 46 ); 47 process.exit(1); 48} 49 50const rkey = await prompts({ 51 type: "text", 52 name: "value", 53 message: "What is the record key (rkey) for the feed?", 54}); 55 56if (!/^[a-zA-Z0-9_-]{3,30}$/.test(rkey.value)) { 57 console.error( 58 "Invalid record key. Only alphanumeric characters, underscores, and hyphens are allowed. Length must be between 3 and 30 characters." 59 ); 60 process.exit(1); 61} 62 63console.log("Creating feed with the following details:"); 64 65console.log("Feed name:", name.value); 66console.log("Description:", description.value); 67console.log("DID:", did.value); 68console.log("Record key (rkey):", rkey.value); 69 70let confirm = await prompts({ 71 type: "confirm", 72 name: "value", 73 message: "Do you want to proceed?", 74 initial: true, 75}); 76 77if (!confirm.value) { 78 console.log("Feed creation cancelled."); 79 process.exit(0); 80} 81 82let userDid = args[0]; 83 84if (!userDid.startsWith("did:plc:")) { 85 userDid = await ctx.baseIdResolver.handle.resolve(userDid); 86} 87 88const agent = await createAgent(ctx.oauthClient, userDid); 89 90console.log( 91 `Writing ${chalk.greenBright("app.rocksky.feed.generator")} record...` 92); 93 94const record: FeedGenerator.Record = { 95 $type: "app.rocksky.feed.generator", 96 displayName: name.value, 97 description: description.value, 98 did: did.value, 99 createdAt: new Date().toISOString(), 100}; 101 102const res = await agent.com.atproto.repo.createRecord({ 103 repo: agent.assertDid, 104 collection: "app.rocksky.feed.generator", 105 record, 106 rkey: rkey.value, 107}); 108 109console.log(chalk.greenBright("Feed created successfully!")); 110console.log(`Record created at: ${chalk.cyan(res.data.uri)}`); 111 112process.exit(0);