A decentralized music tracking and discovery platform built on AT Protocol 🎵
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(feed): add prompts for record key and confirmation before feed creation

+48 -1
+48 -1
apps/api/src/scripts/feed.ts
··· 1 1 import chalk from "chalk"; 2 2 import { ctx } from "context"; 3 + import * as FeedGenerator from "lexicon/types/app/rocksky/feed/generator"; 3 4 import { createAgent } from "lib/agent"; 4 5 import prompts from "prompts"; 5 6 ··· 48 49 process.exit(1); 49 50 } 50 51 52 + const rkey = await prompts({ 53 + type: "text", 54 + name: "value", 55 + message: "What is the record key (rkey) for the feed?", 56 + }); 57 + 58 + if (!/^[a-zA-Z0-9_.-]{3,30}$/.test(rkey.value)) { 59 + console.error( 60 + "Invalid record key. Only alphanumeric characters, underscores, hyphens, and periods are allowed. Length must be between 3 and 30 characters." 61 + ); 62 + process.exit(1); 63 + } 64 + 65 + console.log("Creating feed with the following details:"); 66 + 51 67 console.log("Feed name:", name.value); 52 68 console.log("Description:", description.value); 53 69 console.log("DID:", did.value); 70 + console.log("Record key (rkey):", rkey.value); 71 + 72 + let confirm = await prompts({ 73 + type: "confirm", 74 + name: "value", 75 + message: "Do you want to proceed?", 76 + initial: true, 77 + }); 78 + 79 + if (!confirm.value) { 80 + console.log("Feed creation cancelled."); 81 + process.exit(0); 82 + } 54 83 55 84 let userDid = args[0]; 56 85 ··· 60 89 61 90 const agent = await createAgent(ctx.oauthClient, userDid); 62 91 63 - console.log("Creating feed..."); 92 + console.log("Writing app.rocksky.feed.generator record..."); 93 + 94 + const 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 + 102 + const 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 + 109 + console.log(chalk.greenBright("Feed created successfully!")); 110 + console.log(`Record created at: ${chalk.cyan(res.data.uri)}`); 64 111 65 112 process.exit(0);