diff --git a/file/exporter.go b/file/exporter.go index dcb4775..e300f98 100644 --- a/file/exporter.go +++ b/file/exporter.go @@ -9,6 +9,27 @@ import ( "github.com/golang/glog" ) +// GetZip handles request of retrieving zip file. +func GetZip(w http.ResponseWriter, r *http.Request) { + q := r.URL.Query() + path := q["path"][0] + + if ".zip" != filepath.Ext(path) { + http.Error(w, "Bad Request", 400) + + return + } + + if !util.File.IsExist(path) { + http.Error(w, "Not Found", 404) + + return + } + + w.Header().Set("Content-type", "application/zip") + http.ServeFile(w, r, path) +} + // CreateZip handles request of creating zip. func CreateZip(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{"succ": true} diff --git a/main.go b/main.go index 3d7689a..d2ba49e 100644 --- a/main.go +++ b/main.go @@ -282,7 +282,8 @@ func main() { http.HandleFunc("/file/find/name", handlerWrapper(file.Find)) // file export/import - http.HandleFunc("/file/zip", handlerWrapper(file.CreateZip)) + http.HandleFunc("/file/zip", handlerWrapper(file.GetZip)) + http.HandleFunc("/file/zip/new", handlerWrapper(file.CreateZip)) // editor http.HandleFunc("/editor/ws", handlerWrapper(editor.WSHandler))