admin: Use logo from challengeinfo in ui template
This commit is contained in:
parent
7e301b8ecb
commit
f1ada8ce99
2 changed files with 18 additions and 4 deletions
|
|
@ -25,10 +25,24 @@ var assets embed.FS
|
|||
var indexPage []byte
|
||||
|
||||
func genIndex(baseURL string) {
|
||||
tplcfg := map[string]string{
|
||||
"logo": "img/logo.png",
|
||||
"title": "Challenge",
|
||||
"urlbase": path.Clean(path.Join(baseURL+"/", "nuke"))[:len(path.Clean(path.Join(baseURL+"/", "nuke")))-4],
|
||||
}
|
||||
|
||||
ci, err := api.GetChallengeInfo()
|
||||
if err == nil && ci != nil {
|
||||
tplcfg["title"] = ci.Title
|
||||
if len(ci.MainLogo) > 0 {
|
||||
tplcfg["logo"] = "/files/logo/" + path.Base(ci.MainLogo[0])
|
||||
}
|
||||
}
|
||||
|
||||
b := bytes.NewBufferString("")
|
||||
if indexTmpl, err := template.New("index").Parse(indextpl); err != nil {
|
||||
log.Fatal("Cannot create template:", err)
|
||||
} else if err = indexTmpl.Execute(b, map[string]string{"urlbase": path.Clean(path.Join(baseURL+"/", "nuke"))[:len(path.Clean(path.Join(baseURL+"/", "nuke")))-4]}); err != nil {
|
||||
} else if err = indexTmpl.Execute(b, tplcfg); err != nil {
|
||||
log.Fatal("An error occurs during template execution:", err)
|
||||
} else {
|
||||
indexPage = b.Bytes()
|
||||
|
|
@ -108,7 +122,7 @@ func declareStaticRoutes(router *gin.RouterGroup, cfg *settings.Settings, baseUR
|
|||
|
||||
router.GET("/files/*_", func(c *gin.Context) {
|
||||
// TODO: handle .gz file here
|
||||
http.ServeFile(c.Writer, c.Request, path.Join(fic.FilesDir, strings.TrimPrefix(c.Request.URL.Path, path.Join(baseURL, "files"))))
|
||||
http.ServeFile(c.Writer, c.Request, path.Join(fic.FilesDir, strings.TrimPrefix(strings.TrimPrefix(c.Request.URL.Path, baseURL), "/files")))
|
||||
})
|
||||
router.GET("/submissions/*_", func(c *gin.Context) {
|
||||
http.ServeFile(c.Writer, c.Request, path.Join(api.TimestampCheck, strings.TrimPrefix(c.Request.URL.Path, path.Join(baseURL, "submissions"))))
|
||||
|
|
|
|||
Reference in a new issue