Fix user profile images

This commit is contained in:
Alessio 2023-08-13 15:55:04 -03:00
parent cd1043215c
commit 2c8ef0b476
2 changed files with 13 additions and 1 deletions

View File

@ -3,7 +3,7 @@
<a class="unstyled-link" href="/{{.Handle}}">
<img
class="profile-image"
src="{{if .IsContentDownloaded}}/content/profile_images/{{.ProfileImageLocalPath}}{{else}}{{.ProfileImageUrl}}{{end}}"
src="/content/{{.GetProfileImageLocalPath}}"
/>
</a>
<span class="name-and-handle">

View File

@ -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 = "default_profile.png"
type UserID int64
type UserHandle string
@ -244,3 +245,14 @@ func (u User) GetTinyProfileImageLocalPath() string {
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"))
}