落地输入合规、探索题库、报告日/时辰刷新、账号头像、OEJTS 量表,并补齐 H5 埋点与 Admin 漏斗;同步 ESS 工件、切至自建 Git、清理 GitHub Actions。 Co-authored-by: Cursor <cursoragent@cursor.com>
37 lines
762 B
Go
37 lines
762 B
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
"path/filepath"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/yuxingu/digital-psychology/apps/api/internal/avatar"
|
|
)
|
|
|
|
// MediaHandler serves uploaded media files.
|
|
type MediaHandler struct {
|
|
AvatarDir string
|
|
}
|
|
|
|
// Register mounts public media routes.
|
|
func (h *MediaHandler) Register(api *gin.RouterGroup) {
|
|
api.GET("/media/avatars/:file", h.ServeAvatar)
|
|
}
|
|
|
|
// ServeAvatar streams a stored avatar image.
|
|
func (h *MediaHandler) ServeAvatar(c *gin.Context) {
|
|
dir := h.AvatarDir
|
|
if dir == "" {
|
|
dir = "data/avatars"
|
|
}
|
|
full, err := avatar.ResolveAbs(dir, c.Param("file"))
|
|
if err != nil {
|
|
c.Status(http.StatusNotFound)
|
|
return
|
|
}
|
|
c.Header("Cache-Control", "public, max-age=86400")
|
|
c.File(full)
|
|
_ = filepath.Ext(full)
|
|
}
|