Fix: cannot edit file in remote server / Modify: separate preview and text-file content controller

This commit is contained in:
HFO4
2020-01-04 15:49:08 +08:00
parent 93dc25aabb
commit d94896041e
10 changed files with 84 additions and 16 deletions

View File

@@ -143,7 +143,7 @@ func Preview(c *gin.Context) {
var service explorer.SingleFileService
if err := c.ShouldBindUri(&service); err == nil {
res := service.PreviewContent(ctx, c)
res := service.PreviewContent(ctx, c, false)
// 是否需要重定向
if res.Code == -301 {
c.Redirect(301, res.Data.(string))
@@ -158,6 +158,24 @@ func Preview(c *gin.Context) {
}
}
// PreviewText 预览文本文件
func PreviewText(c *gin.Context) {
// 创建上下文
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var service explorer.SingleFileService
if err := c.ShouldBindUri(&service); err == nil {
res := service.PreviewContent(ctx, c, true)
// 是否有错误发生
if res.Code != 0 {
c.JSON(200, res)
}
} else {
c.JSON(200, ErrorResponse(err))
}
}
// GetDocPreview 获取DOC文件预览地址
func GetDocPreview(c *gin.Context) {
// 创建上下文