mirror of
https://github.com/aykhans/bsky-feedgen.git
synced 2025-05-31 02:50:03 +00:00
Add 'users', 'users/valid/', and 'users/invalid/' endpoints to API
This commit is contained in:
parent
50af73f26a
commit
12e51b5a22
@ -1,3 +1,3 @@
|
||||
package main
|
||||
|
||||
const version = "0.1.0"
|
||||
const version = "0.2.0"
|
||||
|
@ -34,6 +34,9 @@ func Run(
|
||||
"GET /xrpc/app.bsky.feed.getFeedSkeleton",
|
||||
authMiddleware.JWTAuthMiddleware(http.HandlerFunc(feedHandler.GetFeedSkeleton)),
|
||||
)
|
||||
mux.HandleFunc("GET /{feed}/users", feedHandler.GetAllUsers)
|
||||
mux.HandleFunc("GET /{feed}/users/valid/", feedHandler.GetValidUsers)
|
||||
mux.HandleFunc("GET /{feed}/users/invalid/", feedHandler.GetInvalidUsers)
|
||||
|
||||
httpServer := &http.Server{
|
||||
Addr: fmt.Sprintf(":%d", apiConfig.APIPort),
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"github.com/aykhans/bsky-feedgen/pkg/api/middleware"
|
||||
"github.com/aykhans/bsky-feedgen/pkg/api/response"
|
||||
"github.com/aykhans/bsky-feedgen/pkg/feed"
|
||||
generatorAz "github.com/aykhans/bsky-feedgen/pkg/generator/az"
|
||||
"github.com/aykhans/bsky-feedgen/pkg/types"
|
||||
"github.com/aykhans/bsky-feedgen/pkg/utils"
|
||||
"github.com/bluesky-social/indigo/api/bsky"
|
||||
@ -99,3 +100,46 @@ func (handler *FeedHandler) GetFeedSkeleton(w http.ResponseWriter, r *http.Reque
|
||||
Cursor: newCursor,
|
||||
})
|
||||
}
|
||||
|
||||
func (handler *FeedHandler) GetValidUsers(w http.ResponseWriter, r *http.Request) {
|
||||
feed := r.PathValue("feed")
|
||||
|
||||
validUsers := make([]string, 0)
|
||||
switch feed {
|
||||
case "AzPulse":
|
||||
validUsers = generatorAz.Users.GetValidUsers()
|
||||
}
|
||||
|
||||
response.JSON(w, 200, response.M{
|
||||
"feed": feed,
|
||||
"users": validUsers,
|
||||
})
|
||||
}
|
||||
|
||||
func (handler *FeedHandler) GetInvalidUsers(w http.ResponseWriter, r *http.Request) {
|
||||
feed := r.PathValue("feed")
|
||||
|
||||
invalidUsers := make([]string, 0)
|
||||
switch feed {
|
||||
case "AzPulse":
|
||||
invalidUsers = generatorAz.Users.GetInvalidUsers()
|
||||
}
|
||||
|
||||
response.JSON(w, 200, response.M{
|
||||
"feed": feed,
|
||||
"users": invalidUsers,
|
||||
})
|
||||
}
|
||||
|
||||
func (handler *FeedHandler) GetAllUsers(w http.ResponseWriter, r *http.Request) {
|
||||
feed := r.PathValue("feed")
|
||||
|
||||
responseData := response.M{"feed": feed}
|
||||
switch feed {
|
||||
case "AzPulse":
|
||||
responseData["valid_users"] = generatorAz.Users.GetValidUsers()
|
||||
responseData["invalid_users"] = generatorAz.Users.GetInvalidUsers()
|
||||
}
|
||||
|
||||
response.JSON(w, 200, responseData)
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ func (f *FeedAz) Describe(_ context.Context) bsky.FeedDescribeFeedGenerator_Feed
|
||||
|
||||
func (f *FeedAz) GetPage(
|
||||
ctx context.Context,
|
||||
_ string,
|
||||
_ string, // user did
|
||||
limit int64,
|
||||
cursor string,
|
||||
) ([]*bsky.FeedDefs_SkeletonFeedPost, *string, error) {
|
||||
|
@ -114,7 +114,7 @@ func (generator *Generator) IsValid(post *collections.Post) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
if isValidUser := users.IsValid(post.DID); isValidUser != nil {
|
||||
if isValidUser := Users.IsValid(post.DID); isValidUser != nil {
|
||||
return *isValidUser
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ package az
|
||||
|
||||
import "github.com/aykhans/bsky-feedgen/pkg/generator"
|
||||
|
||||
var users = generator.Users{
|
||||
var Users = generator.Users{
|
||||
// Invalid
|
||||
"did:plc:5zww7zorx2ajw7hqrhuix3ba": false,
|
||||
"did:plc:c4vhz47h566t2ntgd7gtawen": false,
|
||||
|
@ -4,6 +4,15 @@ import "github.com/aykhans/bsky-feedgen/pkg/utils"
|
||||
|
||||
type Users map[string]bool
|
||||
|
||||
// IsValid checks if a given DID exists in the Users map and returns its validity status.
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// did: The Decentralized Identifier string to check
|
||||
//
|
||||
// Returns:
|
||||
// - *bool: A pointer to the validity status if the DID exists in the map
|
||||
// - nil: If the DID does not exist in the map
|
||||
func (u Users) IsValid(did string) *bool {
|
||||
isValid, ok := u[did]
|
||||
if ok == false {
|
||||
@ -12,3 +21,49 @@ func (u Users) IsValid(did string) *bool {
|
||||
|
||||
return utils.ToPtr(isValid)
|
||||
}
|
||||
|
||||
// GetValidUsers returns a slice of DIDs that are marked as valid in the Users map.
|
||||
//
|
||||
// Returns:
|
||||
// - []string: A slice of valid DIDs, limited by the specified parameters
|
||||
func (u Users) GetValidUsers() []string {
|
||||
validUsers := make([]string, 0)
|
||||
|
||||
for did, isValid := range u {
|
||||
if isValid {
|
||||
validUsers = append(validUsers, did)
|
||||
}
|
||||
}
|
||||
|
||||
return validUsers
|
||||
}
|
||||
|
||||
// GetInvalidUsers returns a slice of DIDs that are marked as invalid in the Users map.
|
||||
//
|
||||
// Returns:
|
||||
// - []string: A slice of invalid DIDs, limited by the specified parameters
|
||||
func (u Users) GetInvalidUsers() []string {
|
||||
invalidUsers := make([]string, 0)
|
||||
|
||||
for did, isValid := range u {
|
||||
if !isValid {
|
||||
invalidUsers = append(invalidUsers, did)
|
||||
}
|
||||
}
|
||||
|
||||
return invalidUsers
|
||||
}
|
||||
|
||||
// GetAll returns a slice of all DIDs in the Users map, regardless of validity status.
|
||||
//
|
||||
// Returns:
|
||||
// - []string: A slice containing all DIDs in the map
|
||||
func (u Users) GetAll() []string {
|
||||
allUsers := make([]string, 0, len(u))
|
||||
|
||||
for did := range u {
|
||||
allUsers = append(allUsers, did)
|
||||
}
|
||||
|
||||
return allUsers
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user