feat: get remote person's avatar and assign to user
This commit is contained in:
parent
7feb8481ac
commit
96316a8f31
1 changed files with 25 additions and 0 deletions
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue