From 1c3c96e3715b37244d3ee6d6c6915f552d35e7b0 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 16 May 2019 17:25:47 +0800 Subject: [PATCH] =?UTF-8?q?:lock:=20#355=20=E5=88=A0=E9=99=A4=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- file/importer.go | 77 ------------------------------------------------ main.go | 1 - 2 files changed, 78 deletions(-) delete mode 100644 file/importer.go diff --git a/file/importer.go b/file/importer.go deleted file mode 100644 index fc5392f..0000000 --- a/file/importer.go +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) 2014-2019, b3log.org & hacpai.com -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package file - -import ( - "io" - "mime/multipart" - "net/http" - "os" - "path/filepath" - - "github.com/b3log/wide/util" -) - -type fileInfo struct { - Name string `json:"name"` - Type string `json:"type"` - Error string `json:"error,omitempty"` -} - -func handleUpload(p *multipart.Part, dir string) (fi *fileInfo) { - fi = &fileInfo{ - Name: p.FileName(), - Type: p.Header.Get("Content-Type"), - } - - path := filepath.Clean(dir + "/" + fi.Name) - f, _ := os.Create(path) - - io.Copy(f, p) - - f.Close() - - return -} - -func handleUploads(r *http.Request, dir string) (fileInfos []*fileInfo) { - fileInfos = make([]*fileInfo, 0) - mr, err := r.MultipartReader() - - part, err := mr.NextPart() - - for err == nil { - if name := part.FormName(); name != "" { - if part.FileName() != "" { - fileInfos = append(fileInfos, handleUpload(part, dir)) - } - } - - part, err = mr.NextPart() - } - - return -} - -// UploadHandler handles request of file upload. -func UploadHandler(w http.ResponseWriter, r *http.Request) { - result := util.NewResult() - defer util.RetResult(w, r, result) - - q := r.URL.Query() - dir := q["path"][0] - - result.Data = handleUploads(r, dir) -} diff --git a/main.go b/main.go index 3a5ac61..6b1c314 100644 --- a/main.go +++ b/main.go @@ -145,7 +145,6 @@ func main() { // file export/import http.HandleFunc(conf.Wide.Context+"/file/zip/new", handlerWrapper(file.CreateZipHandler)) http.HandleFunc(conf.Wide.Context+"/file/zip", handlerWrapper(file.GetZipHandler)) - http.HandleFunc(conf.Wide.Context+"/file/upload", handlerWrapper(file.UploadHandler)) http.HandleFunc(conf.Wide.Context+"/file/decompress", handlerWrapper(file.DecompressHandler)) // editor