Add getter for User tiny-profile-image URL

This commit is contained in:
Alessio 2022-01-04 13:15:47 -05:00
parent e06b0bff30
commit 80f6787aa0
2 changed files with 16 additions and 0 deletions

View File

@ -148,3 +148,15 @@ func (u User) compute_banner_image_local_path() string {
} }
return string(u.Handle) + "_banner_" + base_name return string(u.Handle) + "_banner_" + base_name
} }
/**
* Get the URL where we would expect to find a User's tiny profile image
*/
func (u User) GetTinyProfileImageUrl() string {
// Check that the format is as expected
r := regexp.MustCompile(`(\.\w{2,4})$`)
if !r.MatchString(u.ProfileImageUrl) {
panic(fmt.Sprintf("Weird profile image url: %s", u.ProfileImageUrl))
}
return r.ReplaceAllString(u.ProfileImageUrl, "_normal$1")
}

View File

@ -64,6 +64,10 @@ func TestParseSingleUser(t *testing.T) {
if user.ProfileImageUrl != expectedProfileImage { if user.ProfileImageUrl != expectedProfileImage {
t.Errorf("Expected %q, got %q", expectedProfileImage, user.ProfileImageUrl) t.Errorf("Expected %q, got %q", expectedProfileImage, user.ProfileImageUrl)
} }
expected_tiny_profile_image := "https://pbs.twimg.com/profile_images/1064051934812913664/Lbwdb_C9_normal.jpg"
if user.GetTinyProfileImageUrl() != expected_tiny_profile_image {
t.Errorf("Expected %q, got %q", expected_tiny_profile_image, user.GetTinyProfileImageUrl())
}
expectedBannerImage := "https://pbs.twimg.com/profile_banners/44067298/1615134676" expectedBannerImage := "https://pbs.twimg.com/profile_banners/44067298/1615134676"
if user.BannerImageUrl != expectedBannerImage { if user.BannerImageUrl != expectedBannerImage {
t.Errorf("Expected %q, got %q", expectedBannerImage, user.BannerImageUrl) t.Errorf("Expected %q, got %q", expectedBannerImage, user.BannerImageUrl)