sync: Create empty file for nginx gzip-static module
This commit is contained in:
parent
24a1e86c19
commit
f4c3f1e15e
2 changed files with 24 additions and 1 deletions
|
@ -101,6 +101,7 @@ func declareStaticRoutes(router *gin.RouterGroup, cfg *settings.Settings, baseUR
|
||||||
})
|
})
|
||||||
|
|
||||||
router.GET("/files/*_", func(c *gin.Context) {
|
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"))))
|
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) {
|
||||||
|
|
|
@ -4,7 +4,9 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
@ -173,12 +175,32 @@ func SyncExerciceFiles(i Importer, exercice *fic.Exercice, exceptions *CheckExce
|
||||||
} else if f.(*fic.EFile).Size == 0 {
|
} else if f.(*fic.EFile).Size == 0 {
|
||||||
errs = append(errs, NewFileError(exercice, fname, fmt.Errorf("imported file is empty!")))
|
errs = append(errs, NewFileError(exercice, fname, fmt.Errorf("imported file is empty!")))
|
||||||
} else {
|
} else {
|
||||||
|
file := f.(*fic.EFile)
|
||||||
|
|
||||||
// Call checks hooks
|
// Call checks hooks
|
||||||
for _, h := range hooks.fileHooks {
|
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))
|
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
|
return
|
||||||
|
|
Reference in a new issue