WIP: fix: webfinger before loading search results for /explore/users/ #10

Draft
realaravinth wants to merge 11 commits from task-600 into forgejo
Showing only changes of commit 96316a8f31 - Show all commits

View file

@ -43,6 +43,21 @@ func GetActor(id string) (*ap.Actor, error) {
return actorObj, nil return actorObj, nil
} }
func GetPersonAvatar(ctx context.Context, person *ap.Person) ([]byte, error) {
avatarObj := new(ap.Image)
ap.CopyItemProperties(avatarObj, person.Icon)
log.Info("Getting avatar from link : %s", avatarObj.URL.GetLink().String())
r, err := http.Get(avatarObj.URL.GetLink().String())
if err != nil {
log.Error("Got error while fetching avatar fn: %w", err)
return nil, err
}
defer r.Body.Close()
return io.ReadAll(r.Body)
}
func SavePerson(ctx context.Context, person *ap.Person) (*user.User, error) { func SavePerson(ctx context.Context, person *ap.Person) (*user.User, error) {
fmt.Println(person.ID.String()) fmt.Println(person.ID.String())
@ -91,6 +106,16 @@ func SavePerson(ctx context.Context, person *ap.Person) (*user.User, error) {
return nil, err return nil, err
} }
avatar, err := GetPersonAvatar(ctx, person)
if err != nil {
log.Error("Got error while fetching avatar: %w", err)
return nil, err
}
if u.IsUploadAvatarChanged(avatar) {
_ = user_service.UploadAvatar(ctx, u, avatar)
}
if err = federation.CreateFederatedUser(ctx, u, &federatedHost); err != nil { if err = federation.CreateFederatedUser(ctx, u, &federatedHost); err != nil {
return nil, err return nil, err
} }