~nature/galaxy-go

36bd66b80b6bb064195219ae537b0437ef7175fe — LordNature 4 years ago 9e1b02b master
upload.go: Moved extension check to its own function.
1 files changed, 10 insertions(+), 1 deletions(-)

M upload.go
M upload.go => upload.go +10 -1
@@ 30,6 30,15 @@ func authCheck(user string, key string) bool {
	return false
}

func extCheck(extension string) bool {
	switch extension {
	case ".png", ".jpg", ".zip", ".tar", ".gz", ".pdf", ".txt", ".aac",
	".mp4", ".mkv", ".mp3", ".flac", ".ogg":
		return true
	}
	return false
}

func uploadHandler(w http.ResponseWriter, r *http.Request) {
	if r.Method != "POST" {
		http.Error(w, "403 - Access Denied upload GET", http.StatusForbidden)


@@ 64,7 73,7 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
	}

	ext := path.Ext(header.Filename)
	if ext != ".png" && ext != ".jpg" && ext != ".zip" && ext != ".txt" && ext != ".gz" && ext != ".pdf" {
	if !extCheck(ext) {
		fmt.Fprintf(w, "Invalid File Extension\n")
		return
	}