admin: Can import videos
This commit is contained in:
parent
dfe62e0b97
commit
223f44572e
7 changed files with 59 additions and 6 deletions
|
@ -4,6 +4,8 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"srs.epita.fr/fic-server/admin/sync"
|
||||
|
@ -87,6 +89,39 @@ func declareSyncRoutes(router *gin.RouterGroup) {
|
|||
// Exercices
|
||||
declareSyncExercicesRoutes(apiSyncRoutes)
|
||||
declareSyncExercicesRoutes(apiSyncThemesRoutes)
|
||||
|
||||
// Videos sync imports resolution.mp4 from path stored in database.
|
||||
apiSyncRoutes.POST("/videos", func(c *gin.Context) {
|
||||
exercices, err := fic.GetExercices()
|
||||
if err != nil {
|
||||
log.Println("Unable to GetExercices:", err.Error())
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Unable to retrieve exercices list."})
|
||||
return
|
||||
}
|
||||
|
||||
for _, e := range exercices {
|
||||
if len(e.VideoURI) == 0 || !strings.HasPrefix(e.VideoURI, "$RFILES$/") {
|
||||
continue
|
||||
}
|
||||
|
||||
vpath, err := url.PathUnescape(strings.TrimPrefix(e.VideoURI, "$RFILES$/"))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusExpectationFailed, gin.H{"errmsg": fmt.Sprintf("Unable to perform URL unescape: %s", err.Error())})
|
||||
return
|
||||
}
|
||||
|
||||
_, err = sync.ImportFile(sync.GlobalImporter, vpath, func(filePath, URI string) (interface{}, error) {
|
||||
e.VideoURI = path.Join("$FILES$", strings.TrimPrefix(filePath, fic.FilesDir))
|
||||
return e.Update()
|
||||
})
|
||||
if err != nil {
|
||||
c.JSON(http.StatusExpectationFailed, gin.H{"errmsg": err.Error()})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, true)
|
||||
})
|
||||
}
|
||||
|
||||
func declareSyncExercicesRoutes(router *gin.RouterGroup) {
|
||||
|
|
Reference in a new issue