// Package public adds some public routes that can be used to give information
// to anonymous users, or to the not yet authentified cozy owner on its login
// page.
package public

import (
	"net/http"
	"time"

	"github.com/cozy/cozy-stack/pkg/statik/fs"
	"github.com/cozy/cozy-stack/web/middlewares"
	"github.com/cozy/cozy-stack/web/statik"
	"github.com/cozy/echo"
)

// Avatar returns the default avatar currently.
func Avatar(c echo.Context) error {
	inst := middlewares.GetInstance(c)
	f, ok := fs.Get("/images/default-avatar.png", inst.ContextName)
	if !ok {
		f, ok = fs.Get("/images/default-avatar.png", "")
		if !ok {
			return echo.NewHTTPError(http.StatusNotFound, "Page not found")
		}
	}
	handler := statik.NewHandler()
	handler.ServeFile(c.Response(), c.Request(), f, true)
	return nil
}

// Routes sets the routing for the public service
func Routes(router *echo.Group) {
	cacheControl := middlewares.CacheControl(middlewares.CacheOptions{
		MaxAge: 24 * time.Hour,
	})
	router.GET("/avatar", Avatar, cacheControl, middlewares.NeedInstance)
}

// Package public adds some public routes that can be used to give information
// to anonymous users, or to the not yet authentified cozy owner on its login
// page.
package public

import (
	"net/http"
	"time"

	"github.com/cozy/cozy-stack/pkg/statik/fs"
	"github.com/cozy/cozy-stack/web/middlewares"
	"github.com/cozy/cozy-stack/web/statik"
	"github.com/cozy/echo"
)

// Avatar returns the default avatar currently.
func Avatar(c echo.Context) error {
	f, ok := fs.Get("/images/default-avatar.png", "")
	if !ok {
		return echo.NewHTTPError(http.StatusNotFound, "Page not found")
	}
	handler := statik.NewHandler()
	handler.ServeFile(c.Response(), c.Request(), f, true)
	return nil
}

// Routes sets the routing for the public service
func Routes(router *echo.Group) {
	cacheControl := middlewares.CacheControl(middlewares.CacheOptions{
		MaxAge: 24 * time.Hour,
	})
	router.GET("/avatar", Avatar, cacheControl)
}

--- 
+++ 
@@ -15,9 +15,13 @@
 
 // Avatar returns the default avatar currently.
 func Avatar(c echo.Context) error {
-	f, ok := fs.Get("/images/default-avatar.png", "")
+	inst := middlewares.GetInstance(c)
+	f, ok := fs.Get("/images/default-avatar.png", inst.ContextName)
 	if !ok {
-		return echo.NewHTTPError(http.StatusNotFound, "Page not found")
+		f, ok = fs.Get("/images/default-avatar.png", "")
+		if !ok {
+			return echo.NewHTTPError(http.StatusNotFound, "Page not found")
+		}
 	}
 	handler := statik.NewHandler()
 	handler.ServeFile(c.Response(), c.Request(), f, true)
@@ -29,5 +33,5 @@
 	cacheControl := middlewares.CacheControl(middlewares.CacheOptions{
 		MaxAge: 24 * time.Hour,
 	})
-	router.GET("/avatar", Avatar, cacheControl)
+	router.GET("/avatar", Avatar, cacheControl, middlewares.NeedInstance)
 }
Allow to customize the default avatar by context
