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.
add getFeedSuggestions (bluesky-social#1542)
* add getFeedSuggestions lex * move to feed namespace * codegen * add table and migration * add endpoints * remove comment * add test * fix order * rename * just remove proxy check
- Loading branch information
1 parent
9a0fd91
commit f84027f
Showing
20 changed files
with
575 additions
and
1 deletion.
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,31 @@ | ||
{ | ||
"lexicon": 1, | ||
"id": "app.bsky.feed.getSuggestedFeeds", | ||
"defs": { | ||
"main": { | ||
"type": "query", | ||
"description": "Get a list of suggested feeds for the viewer.", | ||
"parameters": { | ||
"type": "params", | ||
"properties": { | ||
"limit": {"type": "integer", "minimum": 1, "maximum": 100, "default": 50}, | ||
"cursor": {"type": "string"} | ||
} | ||
}, | ||
"output": { | ||
"encoding": "application/json", | ||
"schema": { | ||
"type": "object", | ||
"required": ["feeds"], | ||
"properties": { | ||
"cursor": {"type": "string"}, | ||
"feeds": { | ||
"type": "array", | ||
"items": {"type": "ref", "ref": "app.bsky.feed.defs#generatorView"} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
packages/api/src/client/types/app/bsky/feed/getSuggestedFeeds.ts
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,38 @@ | ||
/** | ||
* 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 { | ||
limit?: number | ||
cursor?: string | ||
} | ||
|
||
export type InputSchema = undefined | ||
|
||
export interface OutputSchema { | ||
cursor?: string | ||
feeds: AppBskyFeedDefs.GeneratorView[] | ||
[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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Server } from '../../../../lexicon' | ||
import AppContext from '../../../../context' | ||
|
||
export default function (server: Server, ctx: AppContext) { | ||
server.app.bsky.feed.getSuggestedFeeds({ | ||
auth: ctx.authOptionalVerifier, | ||
handler: async ({ auth }) => { | ||
const viewer = auth.credentials.did | ||
|
||
const db = ctx.db.getReplica() | ||
const feedService = ctx.services.feed(db) | ||
const feedsRes = await db.db | ||
.selectFrom('suggested_feed') | ||
.orderBy('suggested_feed.order', 'asc') | ||
.selectAll() | ||
.execute() | ||
|
||
const genInfos = await feedService.getFeedGeneratorInfos( | ||
feedsRes.map((r) => r.uri), | ||
viewer, | ||
) | ||
const genList = Object.values(genInfos) | ||
|
||
const creators = genList.map((gen) => gen.creator) | ||
const profiles = await feedService.getActorInfos(creators, viewer) | ||
|
||
const feedViews = genList.map((gen) => | ||
feedService.views.formatFeedGeneratorView(gen, profiles), | ||
) | ||
|
||
return { | ||
encoding: 'application/json', | ||
body: { | ||
feeds: feedViews, | ||
}, | ||
} | ||
}, | ||
}) | ||
} |
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
13 changes: 13 additions & 0 deletions
13
packages/bsky/src/db/migrations/20230830T205507322Z-suggested-feeds.ts
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,13 @@ | ||
import { Kysely } from 'kysely' | ||
|
||
export async function up(db: Kysely<unknown>): Promise<void> { | ||
await db.schema | ||
.createTable('suggested_feed') | ||
.addColumn('uri', 'varchar', (col) => col.primaryKey()) | ||
.addColumn('order', 'integer', (col) => col.notNull()) | ||
.execute() | ||
} | ||
|
||
export async function down(db: Kysely<unknown>): Promise<void> { | ||
await db.schema.dropTable('suggested_feed').execute() | ||
} |
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,10 @@ | ||
export const tableName = 'suggested_feed' | ||
|
||
export interface SuggestedFeed { | ||
uri: string | ||
order: number | ||
} | ||
|
||
export type PartialDB = { | ||
[tableName]: SuggestedFeed | ||
} |
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
48 changes: 48 additions & 0 deletions
48
packages/bsky/src/lexicon/types/app/bsky/feed/getSuggestedFeeds.ts
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,48 @@ | ||
/** | ||
* GENERATED CODE - DO NOT MODIFY | ||
*/ | ||
import express from 'express' | ||
import { ValidationResult, BlobRef } from '@atproto/lexicon' | ||
import { lexicons } from '../../../../lexicons' | ||
import { isObj, hasProp } from '../../../../util' | ||
import { CID } from 'multiformats/cid' | ||
import { HandlerAuth } from '@atproto/xrpc-server' | ||
import * as AppBskyFeedDefs from './defs' | ||
|
||
export interface QueryParams { | ||
limit: number | ||
cursor?: string | ||
} | ||
|
||
export type InputSchema = undefined | ||
|
||
export interface OutputSchema { | ||
cursor?: string | ||
feeds: AppBskyFeedDefs.GeneratorView[] | ||
[k: string]: unknown | ||
} | ||
|
||
export type HandlerInput = undefined | ||
|
||
export interface HandlerSuccess { | ||
encoding: 'application/json' | ||
body: OutputSchema | ||
headers?: { [key: string]: string } | ||
} | ||
|
||
export interface HandlerError { | ||
status: number | ||
message?: string | ||
} | ||
|
||
export type HandlerOutput = HandlerError | HandlerSuccess | ||
export type HandlerReqCtx<HA extends HandlerAuth = never> = { | ||
auth: HA | ||
params: QueryParams | ||
input: HandlerInput | ||
req: express.Request | ||
res: express.Response | ||
} | ||
export type Handler<HA extends HandlerAuth = never> = ( | ||
ctx: HandlerReqCtx<HA>, | ||
) => Promise<HandlerOutput> | HandlerOutput |
Oops, something went wrong.