cover avatars with AvatarResBase config setting
This commit is contained in:
parent
4606a49886
commit
e9819389af
|
@ -124,7 +124,7 @@ type config struct {
|
||||||
ExtraCSPOrigins string
|
ExtraCSPOrigins string
|
||||||
StaticResBase string // /s/
|
StaticResBase string // /s/
|
||||||
//DynStaticResBase string
|
//DynStaticResBase string
|
||||||
//AvatarResBase string
|
AvatarResBase string // /uploads/
|
||||||
|
|
||||||
Noavatar string // ? - Move this into the settings table?
|
Noavatar string // ? - Move this into the settings table?
|
||||||
ItemsPerPage int // ? - Move this into the settings table?
|
ItemsPerPage int // ? - Move this into the settings table?
|
||||||
|
@ -249,6 +249,20 @@ func ProcessConfig() (err error) {
|
||||||
if Config.StaticResBase != "" {
|
if Config.StaticResBase != "" {
|
||||||
StaticFiles.Prefix = Config.StaticResBase
|
StaticFiles.Prefix = Config.StaticResBase
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uurl, err = url.Parse(Config.AvatarResBase)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "failed to parse Config.AvatarResBase: ")
|
||||||
|
}
|
||||||
|
host2 := uurl.Hostname()
|
||||||
|
if host != host2 && !local(host) {
|
||||||
|
Config.ExtraCSPOrigins += " " + host
|
||||||
|
Config.RefNoRef = true // Avoid leaking origin data to the CDN
|
||||||
|
}
|
||||||
|
if Config.AvatarResBase == "" {
|
||||||
|
Config.AvatarResBase = "/uploads/"
|
||||||
|
}
|
||||||
|
|
||||||
if !Config.DisableDefaultNoavatar {
|
if !Config.DisableDefaultNoavatar {
|
||||||
noavatarCache200 = make([]string, 5)
|
noavatarCache200 = make([]string, 5)
|
||||||
noavatarCache48 = make([]string, 5)
|
noavatarCache48 = make([]string, 5)
|
||||||
|
|
|
@ -790,10 +790,11 @@ func buildNoavatar(uid, width int) string {
|
||||||
}
|
}
|
||||||
return StaticFiles.Prefix + "n" + strconv.Itoa(uid) + "-" + strconv.Itoa(width) + ".png?i=0"
|
return StaticFiles.Prefix + "n" + strconv.Itoa(uid) + "-" + strconv.Itoa(width) + ".png?i=0"
|
||||||
}
|
}
|
||||||
|
// ? - Add a prefix setting to make this faster?
|
||||||
return strings.Replace(strings.Replace(Config.Noavatar, "{id}", strconv.Itoa(uid), 1), "{width}", strconv.Itoa(width), 1)
|
return strings.Replace(strings.Replace(Config.Noavatar, "{id}", strconv.Itoa(uid), 1), "{width}", strconv.Itoa(width), 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ? Make this part of *User?
|
// ? - Make this part of *User?
|
||||||
// TODO: Write tests for this
|
// TODO: Write tests for this
|
||||||
func BuildAvatar(uid int, avatar string) (normalAvatar, microAvatar string) {
|
func BuildAvatar(uid int, avatar string) (normalAvatar, microAvatar string) {
|
||||||
if avatar == "" {
|
if avatar == "" {
|
||||||
|
@ -804,10 +805,10 @@ func BuildAvatar(uid int, avatar string) (normalAvatar, microAvatar string) {
|
||||||
}
|
}
|
||||||
if avatar[0] == '.' {
|
if avatar[0] == '.' {
|
||||||
if avatar[1] == '.' {
|
if avatar[1] == '.' {
|
||||||
normalAvatar = "/uploads/avatar_" + strconv.Itoa(uid) + "_tmp" + avatar[1:]
|
normalAvatar = Config.AvatarResBase+"avatar_" + strconv.Itoa(uid) + "_tmp" + avatar[1:]
|
||||||
return normalAvatar, normalAvatar
|
return normalAvatar, normalAvatar
|
||||||
}
|
}
|
||||||
normalAvatar = "/uploads/avatar_" + strconv.Itoa(uid) + avatar
|
normalAvatar = Config.AvatarResBase+"avatar_" + strconv.Itoa(uid) + avatar
|
||||||
return normalAvatar, normalAvatar
|
return normalAvatar, normalAvatar
|
||||||
}
|
}
|
||||||
return avatar, avatar
|
return avatar, avatar
|
||||||
|
|
|
@ -130,6 +130,8 @@ ExtraCSPOrigins - Extra origins which may want whitelisted in the default Conten
|
||||||
|
|
||||||
StaticResBase - The default prefix for static resource files. May be a path or an external domain like a CDN domain. Default: /s/
|
StaticResBase - The default prefix for static resource files. May be a path or an external domain like a CDN domain. Default: /s/
|
||||||
|
|
||||||
|
AvatarResBase - The default prefix for avatar files. May be a path or an external domain like a CDN domain. Default: /uploads/
|
||||||
|
|
||||||
NoAvatar - The default avatar to use for users when they don't have their own. The default for this may change in the near future to better utilise HTTP/2. Example: https://api.adorable.io/avatars/{width}/{id}.png
|
NoAvatar - The default avatar to use for users when they don't have their own. The default for this may change in the near future to better utilise HTTP/2. Example: https://api.adorable.io/avatars/{width}/{id}.png
|
||||||
|
|
||||||
ItemsPerPage - The number of posts, topics, etc. you want on each page.
|
ItemsPerPage - The number of posts, topics, etc. you want on each page.
|
||||||
|
|
Loading…
Reference in New Issue