mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-23 19:11:58 +01:00
name change of avatar
This commit is contained in:
parent
409e4cde7a
commit
4662a73ac3
3 changed files with 10 additions and 10 deletions
|
@ -9,7 +9,7 @@ It is recommend to use this way
|
||||||
|
|
||||||
cacheDir := "./cache"
|
cacheDir := "./cache"
|
||||||
defaultImg := "./default.jpg"
|
defaultImg := "./default.jpg"
|
||||||
http.Handle("/avatar/", avatar.HttpHandler(cacheDir, defaultImg))
|
http.Handle("/avatar/", avatar.CacheServer(cacheDir, defaultImg))
|
||||||
*/
|
*/
|
||||||
package avatar
|
package avatar
|
||||||
|
|
||||||
|
@ -135,12 +135,12 @@ func (this *Avatar) UpdateTimeout(timeout time.Duration) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
type avatarHandler struct {
|
type service struct {
|
||||||
cacheDir string
|
cacheDir string
|
||||||
altImage string
|
altImage string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *avatarHandler) mustInt(r *http.Request, defaultValue int, keys ...string) int {
|
func (this *service) mustInt(r *http.Request, defaultValue int, keys ...string) int {
|
||||||
var v int
|
var v int
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
if _, err := fmt.Sscanf(r.FormValue(k), "%d", &v); err == nil {
|
if _, err := fmt.Sscanf(r.FormValue(k), "%d", &v); err == nil {
|
||||||
|
@ -150,7 +150,7 @@ func (this *avatarHandler) mustInt(r *http.Request, defaultValue int, keys ...st
|
||||||
return defaultValue
|
return defaultValue
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *avatarHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (this *service) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
urlPath := r.URL.Path
|
urlPath := r.URL.Path
|
||||||
hash := urlPath[strings.LastIndex(urlPath, "/")+1:]
|
hash := urlPath[strings.LastIndex(urlPath, "/")+1:]
|
||||||
size := this.mustInt(r, 80, "s", "size") // default size = 80*80
|
size := this.mustInt(r, 80, "s", "size") // default size = 80*80
|
||||||
|
@ -183,9 +183,9 @@ func (this *avatarHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// http.Handle("/avatar/", avatar.HttpHandler("./cache"))
|
// http.Handle("/avatar/", avatar.CacheServer("./cache"))
|
||||||
func HttpHandler(cacheDir string, defaultImgPath string) http.Handler {
|
func CacheServer(cacheDir string, defaultImgPath string) http.Handler {
|
||||||
return &avatarHandler{
|
return &service{
|
||||||
cacheDir: cacheDir,
|
cacheDir: cacheDir,
|
||||||
altImage: defaultImgPath,
|
altImage: defaultImgPath,
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ func TestFetchMany(t *testing.T) {
|
||||||
// wget http://www.artsjournal.com/artfulmanager/wp/wp-content/uploads/2013/12/200x200xmirror_cat.jpg.pagespeed.ic.GOZSv6v1_H.jpg -O default.jpg
|
// wget http://www.artsjournal.com/artfulmanager/wp/wp-content/uploads/2013/12/200x200xmirror_cat.jpg.pagespeed.ic.GOZSv6v1_H.jpg -O default.jpg
|
||||||
/*
|
/*
|
||||||
func TestHttp(t *testing.T) {
|
func TestHttp(t *testing.T) {
|
||||||
http.Handle("/", avatar.HttpHandler("./", "default.jpg"))
|
http.Handle("/", avatar.CacheServer("./", "default.jpg"))
|
||||||
http.ListenAndServe(":8001", nil)
|
http.ListenAndServe(":8001", nil)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
4
web.go
4
web.go
|
@ -96,8 +96,8 @@ func runWeb(*cli.Context) {
|
||||||
m.Get("/stars", reqSignIn, user.Stars)
|
m.Get("/stars", reqSignIn, user.Stars)
|
||||||
m.Get("/help", routers.Help)
|
m.Get("/help", routers.Help)
|
||||||
|
|
||||||
avatarCache := avatar.HttpHandler("public/img/avatar/", "public/img/avatar_default.jpg")
|
avt := avatar.CacheServer("public/img/avatar/", "public/img/avatar_default.jpg")
|
||||||
m.Get("/avatar/:hash", avatarCache.ServeHTTP)
|
m.Get("/avatar/:hash", avt.ServeHTTP)
|
||||||
|
|
||||||
m.Group("/user", func(r martini.Router) {
|
m.Group("/user", func(r martini.Router) {
|
||||||
r.Any("/login", binding.BindIgnErr(auth.LogInForm{}), user.SignIn)
|
r.Any("/login", binding.BindIgnErr(auth.LogInForm{}), user.SignIn)
|
||||||
|
|
Loading…
Reference in a new issue