admin: Pick challenge title from challenge.json

This commit is contained in:
nemunaire 2022-06-04 18:21:41 +02:00
parent d09c1741a2
commit 58af047a26
2 changed files with 17 additions and 8 deletions

View file

@ -85,7 +85,7 @@ func getROSettings(c *gin.Context) {
})
}
func getChallengeInfo(c *gin.Context) {
func GetChallengeInfo() (*settings.ChallengeInfo, error) {
var challengeinfo string
var err error
if sync.GlobalImporter == nil {
@ -103,18 +103,25 @@ func getChallengeInfo(c *gin.Context) {
if err != nil {
log.Println("Unable to retrieve challenge.json:", err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Unable to retrive challenge.json: %s", err.Error())})
return
return nil, fmt.Errorf("Unable to retrive challenge.json: %w", err)
}
s, err := settings.ReadChallengeInfo(challengeinfo)
if err != nil {
log.Println("Unable to ReadChallengeInfo:", err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Unable to read challenge info: %s", err.Error())})
return
return nil, fmt.Errorf("Unable to read challenge info: %w", err)
}
c.JSON(http.StatusOK, s)
return s, nil
}
func getChallengeInfo(c *gin.Context) {
if s, err := GetChallengeInfo(); err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
} else {
c.JSON(http.StatusOK, s)
}
}
func saveChallengeInfo(c *gin.Context) {