|
|
@ -1,14 +1,21 @@ |
|
|
package rest |
|
|
package rest |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
|
|
|
"encoding/json" |
|
|
|
|
|
"fmt" |
|
|
|
|
|
"io" |
|
|
"net/http" |
|
|
"net/http" |
|
|
|
|
|
"os" |
|
|
|
|
|
"os/exec" |
|
|
"strconv" |
|
|
"strconv" |
|
|
"strings" |
|
|
"strings" |
|
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
"github.com/eyebluecn/tank/code/core" |
|
|
"github.com/eyebluecn/tank/code/core" |
|
|
"github.com/eyebluecn/tank/code/tool/builder" |
|
|
"github.com/eyebluecn/tank/code/tool/builder" |
|
|
"github.com/eyebluecn/tank/code/tool/i18n" |
|
|
"github.com/eyebluecn/tank/code/tool/i18n" |
|
|
"github.com/eyebluecn/tank/code/tool/result" |
|
|
"github.com/eyebluecn/tank/code/tool/result" |
|
|
|
|
|
"github.com/eyebluecn/tank/code/tool/util" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
type MatterController struct { |
|
|
type MatterController struct { |
|
|
@ -84,7 +91,8 @@ func (this *MatterController) RegisterRoutes() map[string]func(writer http.Respo |
|
|
routeMap["/api/matter/change/privacy"] = this.Wrap(this.ChangePrivacy, USER_ROLE_USER) |
|
|
routeMap["/api/matter/change/privacy"] = this.Wrap(this.ChangePrivacy, USER_ROLE_USER) |
|
|
routeMap["/api/matter/move"] = this.Wrap(this.Move, USER_ROLE_USER) // wait less
|
|
|
routeMap["/api/matter/move"] = this.Wrap(this.Move, USER_ROLE_USER) // wait less
|
|
|
routeMap["/api/matter/detail"] = this.Wrap(this.Detail, USER_ROLE_USER) |
|
|
routeMap["/api/matter/detail"] = this.Wrap(this.Detail, USER_ROLE_USER) |
|
|
routeMap["/api/matter/page"] = this.Wrap(this.Page, USER_ROLE_GUEST) //done
|
|
|
routeMap["/api/matter/page"] = this.Wrap(this.Page, USER_ROLE_GUEST) //done
|
|
|
|
|
|
routeMap["/api/matter/save"] = this.Wrap(this.FileSave, USER_ROLE_GUEST) //done
|
|
|
|
|
|
|
|
|
//mirror local files.
|
|
|
//mirror local files.
|
|
|
routeMap["/api/matter/mirror"] = this.Wrap(this.Mirror, USER_ROLE_USER) |
|
|
routeMap["/api/matter/mirror"] = this.Wrap(this.Mirror, USER_ROLE_USER) |
|
|
@ -112,7 +120,6 @@ func (this *MatterController) Detail(writer http.ResponseWriter, request *http.R |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (this *MatterController) Page(writer http.ResponseWriter, request *http.Request) *result.WebResult { |
|
|
func (this *MatterController) Page(writer http.ResponseWriter, request *http.Request) *result.WebResult { |
|
|
|
|
|
|
|
|
pageStr := request.FormValue("page") |
|
|
pageStr := request.FormValue("page") |
|
|
pageSizeStr := request.FormValue("pageSize") |
|
|
pageSizeStr := request.FormValue("pageSize") |
|
|
orderCreateTime := request.FormValue("orderCreateTime") |
|
|
orderCreateTime := request.FormValue("orderCreateTime") |
|
|
@ -229,6 +236,68 @@ func (this *MatterController) CreateDirectory(writer http.ResponseWriter, reques |
|
|
return this.Success(matter) |
|
|
return this.Success(matter) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type OfficeBack struct { |
|
|
|
|
|
Status int |
|
|
|
|
|
Key string |
|
|
|
|
|
Url string |
|
|
|
|
|
FileType string |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (this *MatterController) FileSave(writer http.ResponseWriter, request *http.Request) *result.WebResult { |
|
|
|
|
|
body, err := io.ReadAll(request.Body) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
panic(err) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
filePath := request.URL.Query().Get("info") |
|
|
|
|
|
//如果filePath不是文件路径,panic
|
|
|
|
|
|
if !FILE_PATTERN.MatchString(filePath) || strings.Contains(filePath, "..") { |
|
|
|
|
|
panic("不合规的文件路径:" + filePath) |
|
|
|
|
|
} |
|
|
|
|
|
var back OfficeBack |
|
|
|
|
|
if err := json.Unmarshal(body, &back); err != nil { |
|
|
|
|
|
panic(err) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if back.Status != 2 { |
|
|
|
|
|
writer.Write([]byte(`{"error":0}`)) |
|
|
|
|
|
writer.WriteHeader(http.StatusOK) |
|
|
|
|
|
return nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 发起 GET 请求
|
|
|
|
|
|
resp, err := http.Get(back.Url) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
panic(err) |
|
|
|
|
|
} |
|
|
|
|
|
defer resp.Body.Close() |
|
|
|
|
|
|
|
|
|
|
|
filePath = util.GetHomePath() + "/matter/" + filePath //在matterpath中操作
|
|
|
|
|
|
//windows os should be "copy" command
|
|
|
|
|
|
cmd := exec.Command("cp", filePath, filePath+fmt.Sprint(time.Now().UnixMilli())) |
|
|
|
|
|
if err = cmd.Run(); err != nil { |
|
|
|
|
|
panic(err) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 创建本地文件, 如果已经存在,将清空文件,所以前面要做一个拷贝备份
|
|
|
|
|
|
file, err := os.Create(filePath) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
panic(err) |
|
|
|
|
|
} |
|
|
|
|
|
defer file.Close() |
|
|
|
|
|
|
|
|
|
|
|
// 将响应体中的数据写入本地文件
|
|
|
|
|
|
buffer := make([]byte, 1024*1024) // 1MB 缓冲区
|
|
|
|
|
|
_, err = io.CopyBuffer(file, resp.Body, buffer) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
panic(back.Key + ": 文件流写入失败!!") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
writer.Write([]byte(`{"error":0}`)) |
|
|
|
|
|
writer.WriteHeader(http.StatusOK) |
|
|
|
|
|
return nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func (this *MatterController) Upload(writer http.ResponseWriter, request *http.Request) *result.WebResult { |
|
|
func (this *MatterController) Upload(writer http.ResponseWriter, request *http.Request) *result.WebResult { |
|
|
|
|
|
|
|
|
puuid := request.FormValue("puuid") |
|
|
puuid := request.FormValue("puuid") |
|
|
|