db: Add a published attribute, filled by challenge.txt

This commit is contained in:
nemunaire 2022-10-31 18:52:29 +01:00
parent 6b7ed273b7
commit a28f108b8a
7 changed files with 75 additions and 19 deletions

View file

@ -5,6 +5,7 @@ import (
"fmt"
"log"
"net/http"
"path/filepath"
"strconv"
"srs.epita.fr/fic-server/admin/sync"
@ -166,8 +167,14 @@ func createExerciceFile(c *gin.Context) {
return
}
paramsFiles, err := sync.GetExerciceFilesParams(sync.GlobalImporter, exercice.(*fic.Exercice))
if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
return
}
var uf uploadedFile
err := c.ShouldBindJSON(&uf)
err = c.ShouldBindJSON(&uf)
if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": err.Error()})
return
@ -178,7 +185,12 @@ func createExerciceFile(c *gin.Context) {
if digest, err := hex.DecodeString(uf.Digest); err != nil {
return nil, err
} else {
return exercice.(*fic.Exercice).ImportFile(filePath, origin, digest, nil)
published := true
if f, exists := paramsFiles[filepath.Base(filePath)]; exists {
published = !f.Hidden
}
return exercice.(*fic.Exercice).ImportFile(filePath, origin, digest, nil, published)
}
})
if err != nil {