This commit is contained in:
parent
3dceae4be0
commit
e7a9ddc460
3 changed files with 27 additions and 21 deletions
17
handlers.go
17
handlers.go
|
|
@ -10,7 +10,7 @@ import (
|
|||
)
|
||||
|
||||
func downloadFile(w http.ResponseWriter, req *http.Request, fileName string) {
|
||||
Info.Println(fmt.Sprintf("server: will download %v", fileName))
|
||||
Info.Printf("server: will download %v\n", fileName)
|
||||
file, err := os.Open(fmt.Sprintf("%v/%v", SFU_FILES_DIR, fileName))
|
||||
if err != nil {
|
||||
Error.Println(err)
|
||||
|
|
@ -34,9 +34,9 @@ func fileExists(fileName string) bool {
|
|||
}
|
||||
|
||||
func deleteFile(w http.ResponseWriter, req *http.Request, fileName string) {
|
||||
Info.Println(fmt.Sprintf("server: will delete %v", fileName))
|
||||
Info.Printf("server: will delete %v\n", fileName)
|
||||
if !fileExists(fileName) {
|
||||
Error.Println(fmt.Sprintf("%v does not exist", fileName))
|
||||
Error.Printf("%v does not exist\n", fileName)
|
||||
http.Error(w, "File not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
|
@ -59,12 +59,12 @@ func uploadFile(w http.ResponseWriter, req *http.Request) {
|
|||
fileExists := fileExists(fileHeader.Filename)
|
||||
forceOverwrite := req.FormValue("force")
|
||||
if fileExists && forceOverwrite != "true" {
|
||||
Error.Println(fmt.Sprintf("file %v already exists", fileHeader.Filename))
|
||||
Error.Printf("file %v already exists\n", fileHeader.Filename)
|
||||
http.Error(w, "File already exists", http.StatusConflict)
|
||||
return
|
||||
}
|
||||
if !fileExists || (forceOverwrite == "true" && fileExists) {
|
||||
Info.Println(fmt.Sprintf("server: will upload %v", fileHeader.Filename))
|
||||
Info.Printf("server: will upload %v\n", fileHeader.Filename)
|
||||
out, err := os.Create(fmt.Sprintf("%v/%v", SFU_FILES_DIR, fileHeader.Filename))
|
||||
if err != nil {
|
||||
Error.Println(err)
|
||||
|
|
@ -83,15 +83,14 @@ func uploadFile(w http.ResponseWriter, req *http.Request) {
|
|||
return
|
||||
}
|
||||
http.Error(w, "internal server error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
func listFiles(w http.ResponseWriter, req *http.Request) {
|
||||
Info.Println(fmt.Sprintf("server: will list uploaded files on %v", SFU_FILES_DIR))
|
||||
Info.Printf("server: will list uploaded files on %v\n", SFU_FILES_DIR)
|
||||
files, err := ioutil.ReadDir(SFU_FILES_DIR)
|
||||
if err != nil {
|
||||
Warning.Println(fmt.Sprintf("%v does not exist", SFU_FILES_DIR))
|
||||
Info.Println(fmt.Sprintf("will create %v", SFU_FILES_DIR))
|
||||
Warning.Printf("%v does not exist\n", SFU_FILES_DIR)
|
||||
Info.Printf("will create %v\n", SFU_FILES_DIR)
|
||||
_ = os.Mkdir(SFU_FILES_DIR, os.ModePerm)
|
||||
}
|
||||
fmt.Fprint(w, "<html><body><ol>")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue