Feat: preview shared file

This commit is contained in:
HFO4
2020-01-28 13:40:19 +08:00
parent 7f0feebf42
commit 1ff4d59978
5 changed files with 85 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
package controllers
import (
"context"
"github.com/HFO4/cloudreve/service/share"
"github.com/gin-gonic/gin"
)
@@ -37,3 +38,26 @@ func GetShareDownload(c *gin.Context) {
c.JSON(200, ErrorResponse(err))
}
}
// PreviewShare 预览分享文件内容
func PreviewShare(c *gin.Context) {
// 创建上下文
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var service share.SingleFileService
if err := c.ShouldBindUri(&service); err == nil {
res := service.PreviewContent(ctx, c, false)
// 是否需要重定向
if res.Code == -301 {
c.Redirect(301, res.Data.(string))
return
}
// 是否有错误发生
if res.Code != 0 {
c.JSON(200, res)
}
} else {
c.JSON(200, ErrorResponse(err))
}
}

View File

@@ -116,6 +116,12 @@ func UserLogin(c *gin.Context) {
}
// UserSignOut 用户退出登录
func UserSignOut(c *gin.Context) {
util.DeleteSession(c, "user_id")
c.JSON(200, serializer.Response{})
}
// UserMe 获取当前登录的用户
func UserMe(c *gin.Context) {
currUser := CurrentUser(c)