实现导入

This commit is contained in:
Minho
2018-01-30 18:13:25 +08:00
parent fa9388056c
commit 8e4bb134d6
5 changed files with 179 additions and 0 deletions

View File

@@ -20,6 +20,8 @@ import (
"github.com/lifei6671/mindoc/models"
"github.com/lifei6671/mindoc/utils"
"github.com/lifei6671/mindoc/utils/pagination"
"net/http"
"github.com/lifei6671/mindoc/converter"
)
type BookController struct {
@@ -449,6 +451,30 @@ func (c *BookController) Create() {
c.JsonResult(6001, "error")
}
func (c *BookController) Import() {
file, moreFile, err := c.GetFile("import-file")
if err == http.ErrMissingFile {
c.JsonResult(6003, "没有发现需要上传的文件")
}
defer file.Close()
beego.Info(moreFile.Filename)
tempPath := filepath.Join(os.TempDir(),c.CruSession.SessionID())
os.MkdirAll(tempPath,0766)
tempPath = filepath.Join(tempPath,moreFile.Filename)
err = c.SaveToFile("import-file", tempPath)
converter.Resolve(tempPath)
}
// CreateToken 创建访问来令牌.
func (c *BookController) CreateToken() {