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
|
.obsidian
|
||||||
|
|
7
funcs.go
7
funcs.go
|
@ -34,6 +34,9 @@ func ImportProfile(fromSession *AtprotoSession, toSession *AtprotoSession, dryru
|
||||||
}
|
}
|
||||||
profile := BskyActorProfile{}
|
profile := BskyActorProfile{}
|
||||||
err = json.Unmarshal(getProfileResponse.Value, &profile)
|
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{
|
newProfile := BskyActorProfile{
|
||||||
LexiconTypeID: "app.bsky.actor.profile",
|
LexiconTypeID: "app.bsky.actor.profile",
|
||||||
|
@ -53,6 +56,7 @@ func ImportProfile(fromSession *AtprotoSession, toSession *AtprotoSession, dryru
|
||||||
}
|
}
|
||||||
|
|
||||||
if !dryrun {
|
if !dryrun {
|
||||||
|
if profile.Avatar != nil {
|
||||||
// import avatar
|
// import avatar
|
||||||
avatarBytes, err := GetAtprotoBlob(fromSession.PdsUrl, fromSession.Did, profile.Avatar.Ref.Link)
|
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 err != nil { return errors.New(fmt.Sprintf("failed to download avatar: %v\n", err)) }
|
||||||
|
@ -60,7 +64,9 @@ func ImportProfile(fromSession *AtprotoSession, toSession *AtprotoSession, dryru
|
||||||
avatarBlob, err := UploadAtprotoBlob(toSession, avatarBytes, profile.Avatar.MimeType)
|
avatarBlob, err := UploadAtprotoBlob(toSession, avatarBytes, profile.Avatar.MimeType)
|
||||||
if err != nil { return errors.New(fmt.Sprintf("failed to upload avatar: %v\n", err)) }
|
if err != nil { return errors.New(fmt.Sprintf("failed to upload avatar: %v\n", err)) }
|
||||||
newProfile.Avatar = avatarBlob
|
newProfile.Avatar = avatarBlob
|
||||||
|
}
|
||||||
|
|
||||||
|
if profile.Banner != nil {
|
||||||
// import banner
|
// import banner
|
||||||
bannerBytes, err := GetAtprotoBlob(fromSession.PdsUrl, fromSession.Did, profile.Banner.Ref.Link)
|
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 err != nil { return errors.New(fmt.Sprintf("failed to download banner: %v\n", err)) }
|
||||||
|
@ -68,6 +74,7 @@ func ImportProfile(fromSession *AtprotoSession, toSession *AtprotoSession, dryru
|
||||||
bannerBlob, err := UploadAtprotoBlob(toSession, bannerBytes, profile.Banner.MimeType)
|
bannerBlob, err := UploadAtprotoBlob(toSession, bannerBytes, profile.Banner.MimeType)
|
||||||
if err != nil { return errors.New(fmt.Sprintf("failed to upload banner: %v\n", err)) }
|
if err != nil { return errors.New(fmt.Sprintf("failed to upload banner: %v\n", err)) }
|
||||||
newProfile.Banner = bannerBlob
|
newProfile.Banner = bannerBlob
|
||||||
|
}
|
||||||
|
|
||||||
// import all details
|
// import all details
|
||||||
_, err = PutAtprotoRecord(toSession, "app.bsky.actor.profile", newProfile)
|
_, err = PutAtprotoRecord(toSession, "app.bsky.actor.profile", newProfile)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue