sync: Create empty file for nginx gzip-static module
This commit is contained in:
parent
24a1e86c19
commit
f4c3f1e15e
@ -101,6 +101,7 @@ func declareStaticRoutes(router *gin.RouterGroup, cfg *settings.Settings, baseUR
|
||||
})
|
||||
|
||||
router.GET("/files/*_", func(c *gin.Context) {
|
||||
// TODO: handle .gz file here
|
||||
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) {
|
||||
|
@ -4,7 +4,9 @@ import (
|
||||
"bufio"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"unicode"
|
||||
@ -173,12 +175,32 @@ func SyncExerciceFiles(i Importer, exercice *fic.Exercice, exceptions *CheckExce
|
||||
} else if f.(*fic.EFile).Size == 0 {
|
||||
errs = append(errs, NewFileError(exercice, fname, fmt.Errorf("imported file is empty!")))
|
||||
} else {
|
||||
file := f.(*fic.EFile)
|
||||
|
||||
// Call checks hooks
|
||||
for _, h := range hooks.fileHooks {
|
||||
for _, e := range h(f.(*fic.EFile), exceptions) {
|
||||
for _, e := range h(file, exceptions) {
|
||||
errs = append(errs, NewFileError(exercice, fname, e))
|
||||
}
|
||||
}
|
||||
|
||||
// Create empty non-gziped file for nginx gzip-static module
|
||||
if len(file.ChecksumShown) > 0 && strings.HasSuffix(file.Name, ".gz") {
|
||||
file.Name = strings.TrimSuffix(file.Name, ".gz")
|
||||
file.Path = strings.TrimSuffix(file.Path, ".gz")
|
||||
|
||||
fd, err := os.Create(path.Join(fic.FilesDir, file.Path))
|
||||
if err == nil {
|
||||
fd.Close()
|
||||
|
||||
_, err = file.Update()
|
||||
if err != nil {
|
||||
log.Println("Unable to update file after .gz removal:", err.Error())
|
||||
}
|
||||
} else {
|
||||
log.Printf("Unable to create %q: %s", file.Path, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user