Fix user profile images
This commit is contained in:
parent
cd1043215c
commit
2c8ef0b476
@ -3,7 +3,7 @@
|
|||||||
<a class="unstyled-link" href="/{{.Handle}}">
|
<a class="unstyled-link" href="/{{.Handle}}">
|
||||||
<img
|
<img
|
||||||
class="profile-image"
|
class="profile-image"
|
||||||
src="{{if .IsContentDownloaded}}/content/profile_images/{{.ProfileImageLocalPath}}{{else}}{{.ProfileImageUrl}}{{end}}"
|
src="/content/{{.GetProfileImageLocalPath}}"
|
||||||
/>
|
/>
|
||||||
</a>
|
</a>
|
||||||
<span class="name-and-handle">
|
<span class="name-and-handle">
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const DEFAULT_PROFILE_IMAGE_URL = "https://abs.twimg.com/sticky/default_profile_images/default_profile.png"
|
const DEFAULT_PROFILE_IMAGE_URL = "https://abs.twimg.com/sticky/default_profile_images/default_profile.png"
|
||||||
|
const DEFAULT_PROFILE_IMAGE = "default_profile.png"
|
||||||
|
|
||||||
type UserID int64
|
type UserID int64
|
||||||
type UserHandle string
|
type UserHandle string
|
||||||
@ -244,3 +245,14 @@ func (u User) GetTinyProfileImageLocalPath() string {
|
|||||||
|
|
||||||
return string(u.Handle) + "_profile_" + path.Base(u.GetTinyProfileImageUrl())
|
return string(u.Handle) + "_profile_" + path.Base(u.GetTinyProfileImageUrl())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Compute a path that will actually contain an image on disk (relative to the Profile)
|
||||||
|
// TODO: why there are so many functions that appear to do roughly the same thing?
|
||||||
|
func (u User) GetProfileImageLocalPath() string {
|
||||||
|
if u.IsContentDownloaded || u.ProfileImageLocalPath == DEFAULT_PROFILE_IMAGE {
|
||||||
|
return fmt.Sprintf("/profile_images/%s", u.ProfileImageLocalPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
r := regexp.MustCompile(`(\.\w{2,4})$`)
|
||||||
|
return fmt.Sprintf("/profile_images/%s", r.ReplaceAllString(u.ProfileImageLocalPath, "_normal$1"))
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user