A decentralized music tracking and discovery platform built on AT Protocol 馃幍 rocksky.app
spotify atproto lastfm musicbrainz scrobbling listenbrainz
96
fork

Configure Feed

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

at feat/pgpull 55 lines 1.7 kB view raw
1import type { 2 NodeSavedSession, 3 NodeSavedSessionStore, 4 NodeSavedState, 5 NodeSavedStateStore, 6} from "@atproto/oauth-client-node"; 7import type { Database } from "../db"; 8 9export class StateStore implements NodeSavedStateStore { 10 constructor(private db: Database) {} 11 async get(key: string): Promise<NodeSavedState | undefined> { 12 const result = await this.db 13 .selectFrom("auth_state") 14 .selectAll() 15 .where("key", "=", key) 16 .executeTakeFirst(); 17 if (!result) return; 18 return JSON.parse(result.state) as NodeSavedState; 19 } 20 async set(key: string, val: NodeSavedState) { 21 const state = JSON.stringify(val); 22 await this.db 23 .insertInto("auth_state") 24 .values({ key, state }) 25 .onConflict((oc) => oc.doUpdateSet({ state })) 26 .execute(); 27 } 28 async del(key: string) { 29 // await this.db.deleteFrom("auth_state").where("key", "=", key).execute(); 30 } 31} 32 33export class SessionStore implements NodeSavedSessionStore { 34 constructor(private db: Database) {} 35 async get(key: string): Promise<NodeSavedSession | undefined> { 36 const result = await this.db 37 .selectFrom("auth_session") 38 .selectAll() 39 .where("key", "=", key) 40 .executeTakeFirst(); 41 if (!result) return; 42 return JSON.parse(result.session) as NodeSavedSession; 43 } 44 async set(key: string, val: NodeSavedSession) { 45 const session = JSON.stringify(val); 46 await this.db 47 .insertInto("auth_session") 48 .values({ key, session }) 49 .onConflict((oc) => oc.doUpdateSet({ session })) 50 .execute(); 51 } 52 async del(key: string) { 53 // await this.db.deleteFrom("auth_session").where("key", "=", key).execute(); 54 } 55}