forked from bluesky-social/atproto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get posts method (bluesky-social#876)
* implement getPosts method * tests * bsky tests * comment out test * Handle stripping record-with-media viewer info in bsky tests --------- Co-authored-by: Devin Ivy <[email protected]>
- Loading branch information
Showing
27 changed files
with
1,663 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"lexicon": 1, | ||
"id": "app.bsky.feed.getPosts", | ||
"defs": { | ||
"main": { | ||
"type": "query", | ||
"description": "A view of an actor's feed.", | ||
"parameters": { | ||
"type": "params", | ||
"required": ["uris"], | ||
"properties": { | ||
"uris": { | ||
"type": "array", | ||
"items": {"type": "string", "format": "at-uri"}, | ||
"maxLength": 25 | ||
} | ||
} | ||
}, | ||
"output": { | ||
"encoding": "application/json", | ||
"schema": { | ||
"type": "object", | ||
"required": ["posts"], | ||
"properties": { | ||
"posts": { | ||
"type": "array", | ||
"items": {"type": "ref", "ref": "app.bsky.feed.defs#postView"} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* GENERATED CODE - DO NOT MODIFY | ||
*/ | ||
import { Headers, XRPCError } from '@atproto/xrpc' | ||
import { ValidationResult, BlobRef } from '@atproto/lexicon' | ||
import { isObj, hasProp } from '../../../../util' | ||
import { lexicons } from '../../../../lexicons' | ||
import { CID } from 'multiformats/cid' | ||
import * as AppBskyFeedDefs from './defs' | ||
|
||
export interface QueryParams { | ||
uris: string[] | ||
} | ||
|
||
export type InputSchema = undefined | ||
|
||
export interface OutputSchema { | ||
posts: AppBskyFeedDefs.PostView[] | ||
[k: string]: unknown | ||
} | ||
|
||
export interface CallOptions { | ||
headers?: Headers | ||
} | ||
|
||
export interface Response { | ||
success: boolean | ||
headers: Headers | ||
data: OutputSchema | ||
} | ||
|
||
export function toKnownErr(e: any) { | ||
if (e instanceof XRPCError) { | ||
} | ||
return e | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import * as common from '@atproto/common' | ||
import { Server } from '../../../../lexicon' | ||
import AppContext from '../../../../context' | ||
import { AtUri } from '@atproto/uri' | ||
import { PostView } from '@atproto/api/src/client/types/app/bsky/feed/defs' | ||
import { authOptionalVerifier } from '../util' | ||
|
||
export default function (server: Server, ctx: AppContext) { | ||
server.app.bsky.feed.getPosts({ | ||
auth: authOptionalVerifier, | ||
handler: async ({ params, auth }) => { | ||
const requester = auth.credentials.did | ||
|
||
const feedService = ctx.services.feed(ctx.db) | ||
|
||
const uris = common.dedupeStrs(params.uris) | ||
const dids = common.dedupeStrs( | ||
params.uris.map((uri) => new AtUri(uri).hostname), | ||
) | ||
|
||
const [actors, postViews, embeds] = await Promise.all([ | ||
feedService.getActorViews(Array.from(dids), requester), | ||
feedService.getPostViews(Array.from(uris), requester), | ||
feedService.embedsForPosts(Array.from(uris), requester), | ||
]) | ||
|
||
const posts: PostView[] = [] | ||
for (const uri of uris) { | ||
const post = feedService.formatPostView(uri, actors, postViews, embeds) | ||
if (post) { | ||
posts.push(post) | ||
} | ||
} | ||
|
||
return { | ||
encoding: 'application/json', | ||
body: { posts }, | ||
} | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.