Import logos from challenge.json
Some checks are pending
continuous-integration/drone/push Build is running
Some checks are pending
continuous-integration/drone/push Build is running
This commit is contained in:
parent
f4188ec289
commit
11a12e1d44
5 changed files with 81 additions and 27 deletions
|
@ -118,7 +118,6 @@ func GetChallengeInfo() (*settings.ChallengeInfo, error) {
|
|||
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)
|
||||
}
|
||||
|
@ -132,17 +131,26 @@ func saveChallengeInfo(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
jenc, err := json.Marshal(info)
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": err.Error()})
|
||||
return
|
||||
}
|
||||
if sync.GlobalImporter != nil {
|
||||
jenc, err := json.Marshal(info)
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
err = sync.WriteFileContent(sync.GlobalImporter, "challenge.json", jenc)
|
||||
if err != nil {
|
||||
log.Println("Unable to SaveChallengeInfo:", err.Error())
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Unable to save challenge info: %s", err.Error())})
|
||||
return
|
||||
err = sync.WriteFileContent(sync.GlobalImporter, "challenge.json", jenc)
|
||||
if err != nil {
|
||||
log.Println("Unable to SaveChallengeInfo:", err.Error())
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Unable to save challenge info: %s", err.Error())})
|
||||
return
|
||||
}
|
||||
|
||||
err = sync.ImportChallengeInfo(info)
|
||||
if err != nil {
|
||||
log.Println("Unable to ImportChallengeInfo:", err.Error())
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Something goes wrong when trying to import related files: %s", err.Error())})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if err := settings.SaveChallengeInfo(path.Join(settings.SettingsDir, settings.ChallengeFile), info); err != nil {
|
||||
|
|
Reference in a new issue