this repo has no description
0
fork

Configure Feed

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

Merge branch 'main' of github.com:aliceisjustplaying/whos-alice

alice 6f0b0a53 06faaa5f

+34 -48
+9 -9
scripts/publishFeedGen.ts
··· 25 25 26 26 // (Optional) A description of your feed 27 27 // Ex: Top trending content from the whole network 28 - const description = 'Tweets from all the Alices.' 28 + const description = 'Posts from all the Alices.' 29 29 30 30 // (Optional) The path to an image to be used as your feed's avatar 31 31 // Ex: ~/path/to/avatar.jpeg ··· 45 45 const agent = new AtpAgent({ service: 'https://bsky.social' }) 46 46 await agent.login({ identifier: handle, password }) 47 47 48 - // try { 49 - // await agent.api.app.bsky.feed.describeFeedGenerator() 50 - // } catch (err) { 51 - // throw new Error( 52 - // 'The bluesky server is not ready to accept published custom feeds yet', 53 - // ) 54 - // } 48 + try { 49 + await agent.api.app.bsky.feed.describeFeedGenerator() 50 + } catch (err) { 51 + throw new Error( 52 + 'The bluesky server is not ready to accept published custom feeds yet', 53 + ) 54 + } 55 55 56 56 let avatarRef: BlobRef | undefined 57 57 if (avatar) { ··· 70 70 avatarRef = blobRes.data.blob 71 71 } 72 72 73 - await agent.api.com.atproto.repo.createRecord({ 73 + await agent.api.com.atproto.repo.putRecord({ 74 74 repo: agent.session?.did ?? '', 75 75 collection: ids.AppBskyFeedGenerator, 76 76 rkey: recordName,
+25 -2
src/server.ts
··· 9 9 import { FirehoseSubscription } from './subscription' 10 10 import { AppContext, Config } from './config' 11 11 import wellKnown from './well-known' 12 - import AtpAgent from '@atproto/api' 12 + import AtpAgent, { AtpSessionData, AtpSessionEvent } from '@atproto/api' 13 13 import * as process from 'node:process' 14 14 15 15 export class FeedGenerator { ··· 20 20 public cfg: Config 21 21 public agent: AtpAgent 22 22 public didResolver: DidResolver 23 + public session: string | null 23 24 24 25 constructor( 25 26 app: express.Application, ··· 67 68 68 69 async start(): Promise<http.Server> { 69 70 await migrateToLatest(this.db) 70 - this.agent = new AtpAgent({ service: 'https://bsky.social' }) 71 + this.agent = new AtpAgent({ 72 + service: 'https://bsky.social', 73 + persistSession: (evt: AtpSessionEvent, sess?: AtpSessionData) => { 74 + // store the session-data for reuse 75 + switch (evt) { 76 + case 'create': 77 + if (!sess) throw new Error('should be unreachable') 78 + this.session = JSON.stringify(sess) 79 + break 80 + case 'create-failed': 81 + this.session = null 82 + console.error('Could not create session') 83 + break 84 + case 'update': 85 + if (!sess) throw new Error('should be unreachable') 86 + this.session = JSON.stringify(sess) 87 + break 88 + case 'expired': 89 + this.session = null 90 + break 91 + } 92 + }, 93 + }) 71 94 await this.agent.login({ 72 95 identifier: process.env.HANDLE!, 73 96 password: process.env.PASSWORD!,
-37
src/subscription.ts
··· 4 4 isCommit, 5 5 } from './lexicon/types/com/atproto/sync/subscribeRepos' 6 6 import { FirehoseSubscriptionBase, getOpsByType } from './util/subscription' 7 - import { error } from 'console' 8 7 9 8 export class FirehoseSubscription extends FirehoseSubscriptionBase { 10 9 isAlice(alices, did) { ··· 35 34 } 36 35 }) 37 36 38 - // const repostsToDelete = ops.reposts.deletes.map((del) => del.uri) 39 - // const repostsToCreate = ops.reposts.creates 40 - // .filter((create) => { 41 - // // only alice posts 42 - // return alices.find((alice) => alice.did === create.author) 43 - // }) 44 - // .map((create) => { 45 - // // map alice-related posts to a db row 46 - // return { 47 - // uri: create.uri, 48 - // cid: create.cid, 49 - // indexedAt: new Date().toISOString(), 50 - // } 51 - // }) 52 - 53 37 if (postsToDelete.length > 0) { 54 38 console.log('🗑️ new deletes 🗑️: ', postsToDelete) 55 39 await this.db ··· 65 49 .onConflict((oc) => oc.doNothing()) 66 50 .execute() 67 51 } 68 - 69 - // if (repostsToDelete.length > 0) { 70 - // try { 71 - // await this.db 72 - // .deleteFrom('repost') 73 - // .where('uri', 'in', repostsToDelete) 74 - // .execute() 75 - // } catch (e) { 76 - // console.log( 77 - // "delete failed for whatever reason it's fine:", 78 - // repostsToDelete, 79 - // ) 80 - // } 81 - // } 82 - // if (repostsToCreate.length > 0) { 83 - // await this.db 84 - // .insertInto('repost') 85 - // .values(repostsToCreate) 86 - // .onConflict((oc) => oc.doNothing()) 87 - // .execute() 88 - // } 89 52 90 53 ops.posts.creates.forEach(async (create) => { 91 54 const user = await this.db