#156 retrieve zip file

This commit is contained in:
Liang Ding 2014-11-24 11:17:42 +08:00
parent a2d4817e15
commit 26823c4cb9
2 changed files with 23 additions and 1 deletions

View File

@ -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}

View File

@ -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))