fix hard-coded frontend max_upload_size validation (#20)

This commit is contained in:
X3STeNLiTE 2020-04-08 22:53:54 +07:00 committed by GitHub
parent cb8d61538d
commit 20bf93c86d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 21 deletions

View file

@ -204,7 +204,9 @@ func (a *App) indexHandler(w http.ResponseWriter, r *http.Request) {
// HTTP handler for /upload
func (a *App) uploadHandler(w http.ResponseWriter, r *http.Request) {
if r.Method == "GET" {
ctx := &struct{}{}
ctx := map[string]interface{}{
"MAX_UPLOAD_SIZE": a.Config.Server.MaxUploadSize,
}
a.render("upload", w, ctx)
} else if r.Method == "POST" {
r.ParseMultipartForm(a.Config.Server.MaxUploadSize)

File diff suppressed because one or more lines are too long

View file

@ -1,8 +1,9 @@
// common variables
let configMaxUploadSize = window['MAX_UPLOAD_SIZE'];
let iBytesUploaded = 0
let iBytesTotal = 0
let iPreviousBytesLoaded = 0
let iMaxFilesize = 104857600 // 100MB
let iMaxFilesize = configMaxUploadSize ? (+configMaxUploadSize) : (100 * 1024 * 1024); // 100MB
let timer = 0
let uploadInProgress = 'n/a'
let isProcessing = false

View file

@ -36,5 +36,6 @@
</div>
{{end}}
{{define "scripts"}}
<script>window['MAX_UPLOAD_SIZE'] = '{{.MAX_UPLOAD_SIZE}}';</script>
<script type="application/javascript" src="/static/upload.js"></script>
{{end}}