admin: Able to export an archive for static publication
Some checks failed
continuous-integration/drone/tag Build is failing
Some checks failed
continuous-integration/drone/tag Build is failing
This commit is contained in:
parent
9172f36be7
commit
f0377f5f5d
85
admin/api/export.go
Normal file
85
admin/api/export.go
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"archive/zip"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"path"
|
||||||
|
|
||||||
|
"srs.epita.fr/fic-server/libfic"
|
||||||
|
"srs.epita.fr/fic-server/settings"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func declareExportRoutes(router *gin.RouterGroup) {
|
||||||
|
router.GET("/archive.zip", func(c *gin.Context) {
|
||||||
|
challengeinfo, err := GetChallengeInfo()
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
my, err := fic.MyJSONTeam(nil, true)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
s, err := settings.ReadSettings(path.Join(settings.SettingsDir, settings.SettingsFile))
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
teams, err := fic.ExportTeams(false)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
themes, err := fic.ExportThemes()
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Writer.WriteHeader(http.StatusOK)
|
||||||
|
c.Header("Content-Disposition", "attachment; filename=archive.zip")
|
||||||
|
c.Header("Content-Type", "application/zip")
|
||||||
|
|
||||||
|
w := zip.NewWriter(c.Writer)
|
||||||
|
|
||||||
|
// challenge.json
|
||||||
|
f, err := w.Create("challenge.json")
|
||||||
|
if err == nil {
|
||||||
|
json.NewEncoder(f).Encode(challengeinfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
// my.json
|
||||||
|
f, err = w.Create("my.json")
|
||||||
|
if err == nil {
|
||||||
|
json.NewEncoder(f).Encode(my)
|
||||||
|
}
|
||||||
|
|
||||||
|
// settings.json
|
||||||
|
f, err = w.Create("settings.json")
|
||||||
|
if err == nil {
|
||||||
|
json.NewEncoder(f).Encode(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
// teams.json
|
||||||
|
f, err = w.Create("teams.json")
|
||||||
|
if err == nil {
|
||||||
|
json.NewEncoder(f).Encode(teams)
|
||||||
|
}
|
||||||
|
|
||||||
|
// themes.json
|
||||||
|
f, err = w.Create("themes.json")
|
||||||
|
if err == nil {
|
||||||
|
json.NewEncoder(f).Encode(themes)
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Close()
|
||||||
|
})
|
||||||
|
}
|
@ -11,6 +11,7 @@ func DeclareRoutes(router *gin.RouterGroup) {
|
|||||||
declareClaimsRoutes(apiRoutes)
|
declareClaimsRoutes(apiRoutes)
|
||||||
declareEventsRoutes(apiRoutes)
|
declareEventsRoutes(apiRoutes)
|
||||||
declareExercicesRoutes(apiRoutes)
|
declareExercicesRoutes(apiRoutes)
|
||||||
|
declareExportRoutes(apiRoutes)
|
||||||
declareFilesGlobalRoutes(apiRoutes)
|
declareFilesGlobalRoutes(apiRoutes)
|
||||||
declareFilesRoutes(apiRoutes)
|
declareFilesRoutes(apiRoutes)
|
||||||
declareGlobalExercicesRoutes(apiRoutes)
|
declareGlobalExercicesRoutes(apiRoutes)
|
||||||
|
@ -459,6 +459,7 @@
|
|||||||
Regénérer les fichiers statiques
|
Regénérer les fichiers statiques
|
||||||
</button>
|
</button>
|
||||||
<button ng-if="settings.wip" ng-click="switchToProd()" class="btn btn-danger my-1" type="button"><span class="glyphicon glyphicon-lock" aria-hidden="true"></span> Activer le mode challenge</button>
|
<button ng-if="settings.wip" ng-click="switchToProd()" class="btn btn-danger my-1" type="button"><span class="glyphicon glyphicon-lock" aria-hidden="true"></span> Activer le mode challenge</button>
|
||||||
|
<a href="api/archive.zip" class="btn btn-secondary my-1" type="button" target="_self"><span class="glyphicon glyphicon-download" aria-hidden="true"></span> Télécharger l'archive pour publication</a>
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
<h4>Changements anticipés</h4>
|
<h4>Changements anticipés</h4>
|
||||||
|
Loading…
Reference in New Issue
Block a user