fix possible nil pointer deref on empty avatar/banners
This commit is contained in:
parent
49324a64b1
commit
bb0066036c
2 changed files with 20 additions and 12 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
.DS_Store
|
||||
.obsidian
|
||||
|
|
31
funcs.go
31
funcs.go
|
@ -34,6 +34,9 @@ func ImportProfile(fromSession *AtprotoSession, toSession *AtprotoSession, dryru
|
|||
}
|
||||
profile := BskyActorProfile{}
|
||||
err = json.Unmarshal(getProfileResponse.Value, &profile)
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("failed to parse source profile data: %v\n", err))
|
||||
}
|
||||
|
||||
newProfile := BskyActorProfile{
|
||||
LexiconTypeID: "app.bsky.actor.profile",
|
||||
|
@ -53,21 +56,25 @@ func ImportProfile(fromSession *AtprotoSession, toSession *AtprotoSession, dryru
|
|||
}
|
||||
|
||||
if !dryrun {
|
||||
// import avatar
|
||||
avatarBytes, err := GetAtprotoBlob(fromSession.PdsUrl, fromSession.Did, profile.Avatar.Ref.Link)
|
||||
if err != nil { return errors.New(fmt.Sprintf("failed to download avatar: %v\n", err)) }
|
||||
if profile.Avatar != nil {
|
||||
// import avatar
|
||||
avatarBytes, err := GetAtprotoBlob(fromSession.PdsUrl, fromSession.Did, profile.Avatar.Ref.Link)
|
||||
if err != nil { return errors.New(fmt.Sprintf("failed to download avatar: %v\n", err)) }
|
||||
|
||||
avatarBlob, err := UploadAtprotoBlob(toSession, avatarBytes, profile.Avatar.MimeType)
|
||||
if err != nil { return errors.New(fmt.Sprintf("failed to upload avatar: %v\n", err)) }
|
||||
newProfile.Avatar = avatarBlob
|
||||
avatarBlob, err := UploadAtprotoBlob(toSession, avatarBytes, profile.Avatar.MimeType)
|
||||
if err != nil { return errors.New(fmt.Sprintf("failed to upload avatar: %v\n", err)) }
|
||||
newProfile.Avatar = avatarBlob
|
||||
}
|
||||
|
||||
// import banner
|
||||
bannerBytes, err := GetAtprotoBlob(fromSession.PdsUrl, fromSession.Did, profile.Banner.Ref.Link)
|
||||
if err != nil { return errors.New(fmt.Sprintf("failed to download banner: %v\n", err)) }
|
||||
if profile.Banner != nil {
|
||||
// import banner
|
||||
bannerBytes, err := GetAtprotoBlob(fromSession.PdsUrl, fromSession.Did, profile.Banner.Ref.Link)
|
||||
if err != nil { return errors.New(fmt.Sprintf("failed to download banner: %v\n", err)) }
|
||||
|
||||
bannerBlob, err := UploadAtprotoBlob(toSession, bannerBytes, profile.Banner.MimeType)
|
||||
if err != nil { return errors.New(fmt.Sprintf("failed to upload banner: %v\n", err)) }
|
||||
newProfile.Banner = bannerBlob
|
||||
bannerBlob, err := UploadAtprotoBlob(toSession, bannerBytes, profile.Banner.MimeType)
|
||||
if err != nil { return errors.New(fmt.Sprintf("failed to upload banner: %v\n", err)) }
|
||||
newProfile.Banner = bannerBlob
|
||||
}
|
||||
|
||||
// import all details
|
||||
_, err = PutAtprotoRecord(toSession, "app.bsky.actor.profile", newProfile)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue