admin: Fix video route
This commit is contained in:
parent
b92381f007
commit
4a190f51c5
8 changed files with 28 additions and 7 deletions
|
@ -98,14 +98,14 @@ func declareStaticRoutes(router *gin.RouterGroup, cfg *settings.Settings, baseUR
|
||||||
})
|
})
|
||||||
|
|
||||||
router.GET("/files/*_", func(c *gin.Context) {
|
router.GET("/files/*_", func(c *gin.Context) {
|
||||||
http.ServeFile(c.Writer, c.Request, path.Join(fic.FilesDir, strings.TrimPrefix(c.Request.URL.Path, "/files")))
|
http.ServeFile(c.Writer, c.Request, path.Join(fic.FilesDir, strings.TrimPrefix(c.Request.URL.Path, path.Join(baseURL, "files"))))
|
||||||
})
|
})
|
||||||
router.GET("/submissions/*_", func(c *gin.Context) {
|
router.GET("/submissions/*_", func(c *gin.Context) {
|
||||||
http.ServeFile(c.Writer, c.Request, path.Join(api.TimestampCheck, strings.TrimPrefix(c.Request.URL.Path, "/submissions")))
|
http.ServeFile(c.Writer, c.Request, path.Join(api.TimestampCheck, strings.TrimPrefix(c.Request.URL.Path, path.Join(baseURL, "submissions"))))
|
||||||
})
|
})
|
||||||
router.GET("/vids/*_", func(c *gin.Context) {
|
router.GET("/vids/*_", func(c *gin.Context) {
|
||||||
if importer, ok := sync.GlobalImporter.(sync.LocalImporter); ok {
|
if importer, ok := sync.GlobalImporter.(sync.DirectAccessImporter); ok {
|
||||||
http.ServeFile(c.Writer, c.Request, path.Join(importer.Base, strings.TrimPrefix(c.Request.URL.Path, "/vids")))
|
http.ServeFile(c.Writer, c.Request, importer.GetLocalPath(strings.TrimPrefix(c.Request.URL.Path, path.Join(baseURL, "vids"))))
|
||||||
} else {
|
} else {
|
||||||
c.AbortWithError(http.StatusBadRequest, errors.New("Only available with local importer."))
|
c.AbortWithError(http.StatusBadRequest, errors.New("Only available with local importer."))
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,6 +84,11 @@ angular.module("FICApp")
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
angular.module("FICApp")
|
angular.module("FICApp")
|
||||||
|
.filter("escapeURL", function() {
|
||||||
|
return function(input) {
|
||||||
|
return encodeURIComponent(input);
|
||||||
|
}
|
||||||
|
})
|
||||||
.filter("stripHTML", function() {
|
.filter("stripHTML", function() {
|
||||||
return function(input) {
|
return function(input) {
|
||||||
if (!input)
|
if (!input)
|
||||||
|
|
|
@ -7,5 +7,5 @@
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<video src="vids/{{exercice.videoURI}}" controls style="height: 80vh; margin: auto;"></video>
|
<video src="vids/{{exercice.videoURI.replace('\$FILES\$/','').replace('?', '%3F')}}" controls style="height: 80vh; margin: auto;"></video>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -235,6 +235,7 @@ func BuildExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]*
|
||||||
errs = append(errs, fmt.Sprintf("%q: resolution.mp4: The file is empty!", edir))
|
errs = append(errs, fmt.Sprintf("%q: resolution.mp4: The file is empty!", edir))
|
||||||
e.VideoURI = ""
|
e.VideoURI = ""
|
||||||
} else {
|
} else {
|
||||||
|
e.VideoURI = path.Join("$FILES$", e.VideoURI)
|
||||||
resolutionFound = true
|
resolutionFound = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,11 @@ type Importer interface {
|
||||||
stat(filename string) (os.FileInfo, error)
|
stat(filename string) (os.FileInfo, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DirectAccessImporter abstracts importer that support direct file access through a local path
|
||||||
|
type DirectAccessImporter interface {
|
||||||
|
GetLocalPath(p ...string) string
|
||||||
|
}
|
||||||
|
|
||||||
// GlobalImporter stores the main importer instance to use for global imports.
|
// GlobalImporter stores the main importer instance to use for global imports.
|
||||||
var GlobalImporter Importer
|
var GlobalImporter Importer
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,10 @@ func (i GitImporter) toURL(filename string) string {
|
||||||
return i.li.toURL(filename)
|
return i.li.toURL(filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i GitImporter) GetLocalPath(filename ...string) string {
|
||||||
|
return i.li.GetLocalPath(filename...)
|
||||||
|
}
|
||||||
|
|
||||||
func (i GitImporter) importFile(URI string, next func(string, string) (interface{}, error)) (interface{}, error) {
|
func (i GitImporter) importFile(URI string, next func(string, string) (interface{}, error)) (interface{}, error) {
|
||||||
return i.li.importFile(URI, next)
|
return i.li.importFile(URI, next)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
)
|
)
|
||||||
|
@ -53,9 +54,14 @@ func (i LocalImporter) exists(filename string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i LocalImporter) toURL(filename string) string {
|
func (i LocalImporter) toURL(filename string) string {
|
||||||
|
log.Println(i.Base, filename, path.Join(i.Base, filename))
|
||||||
return path.Join(i.Base, filename)
|
return path.Join(i.Base, filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i LocalImporter) GetLocalPath(p ...string) string {
|
||||||
|
return i.toURL(path.Join(p...))
|
||||||
|
}
|
||||||
|
|
||||||
func (i LocalImporter) importFile(URI string, next func(string, string) (interface{}, error)) (interface{}, error) {
|
func (i LocalImporter) importFile(URI string, next func(string, string) (interface{}, error)) (interface{}, error) {
|
||||||
if i.Symlink {
|
if i.Symlink {
|
||||||
dest := getDestinationFilePath(URI)
|
dest := getDestinationFilePath(URI)
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
Solution du défi
|
Solution du défi
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardBody class="text-indent ratio ratio-16x9">
|
<CardBody class="text-indent ratio ratio-16x9">
|
||||||
<iframe type="text/html" src="{uri}" class="embed-responsive-item" title="Vidéo de résolution">
|
<iframe type="text/html" src="{uri.replace('$FILES$','/resolution')}" class="embed-responsive-item" title="Vidéo de résolution">
|
||||||
Regardez la vidéo de résolution de ce défi : <a href="{uri}">{uri}</a>.
|
Regardez la vidéo de résolution de ce défi : <a href="{uri.replace('$FILES$','/resolution')}">{uri.replace('$FILES$','/resolution')}</a>.
|
||||||
</iframe>
|
</iframe>
|
||||||
</CardBody>
|
</CardBody>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
Reference in a new issue