wip bsky client for the web & android
0
fork

Configure Feed

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

at main 57 lines 1.5 kB view raw
1import type { AppBskyFeedDefs } from '@atcute/bluesky' 2import type { ComAtprotoRepoStrongRef } from '@atcute/atproto' 3import { ok } from '@atcute/client' 4import type { ActorIdentifier, Blob, LegacyBlob } from '@atcute/lexicons' 5import { isLegacyBlob } from '@atcute/lexicons/interfaces' 6 7import { useToastStore } from '@/stores/toast' 8import { useAuthStore } from '@/stores/auth' 9 10import type { CollectionString } from '@/types/atproto' 11 12const toast = useToastStore() 13const auth = useAuthStore() 14 15export function createStrongRef(post: AppBskyFeedDefs.PostView): ComAtprotoRepoStrongRef.Main { 16 return { 17 $type: 'com.atproto.repo.strongRef', 18 cid: post.cid, 19 uri: post.uri, 20 } 21} 22 23export function blobUrl(pdsUrl: string, did: ActorIdentifier, blob: LegacyBlob | Blob): string { 24 let cid: string 25 26 if (isLegacyBlob(blob)) cid = blob.cid 27 else cid = blob.ref.$link 28 29 return `${pdsUrl}/xrpc/com.atproto.sync.getBlob?did=${did}&cid=${cid}` 30} 31 32export async function createRecord( 33 collection: CollectionString, 34 record: Record<string, unknown>, 35 message: { error: string; success: string } = { 36 error: 'Failed to perform action', 37 success: 'Yayyyyyy done!!', 38 }, 39) { 40 const rpc = auth.getRpc() 41 42 try { 43 await ok( 44 rpc.post('com.atproto.repo.createRecord', { 45 input: { 46 collection, 47 repo: auth.session!.info.sub, 48 record: { $type: collection, ...record }, 49 }, 50 }), 51 ) 52 toast.success(message.success) 53 } catch (e) { 54 console.error(message.error, e) 55 toast.error(message.error) 56 } 57}