2019-12-30 06:08:38 -05:00
|
|
|
|
package controllers
|
|
|
|
|
|
|
|
|
|
import (
|
2021-01-06 03:35:31 -05:00
|
|
|
|
model "github.com/cloudreve/Cloudreve/v3/models"
|
|
|
|
|
"path"
|
2020-06-05 01:45:24 -05:00
|
|
|
|
"strconv"
|
|
|
|
|
|
2020-11-21 04:34:55 -05:00
|
|
|
|
"github.com/cloudreve/Cloudreve/v3/pkg/serializer"
|
|
|
|
|
"github.com/cloudreve/Cloudreve/v3/pkg/util"
|
|
|
|
|
"github.com/cloudreve/Cloudreve/v3/service/callback"
|
2019-12-30 06:08:38 -05:00
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// RemoteCallback 远程上传回调
|
|
|
|
|
func RemoteCallback(c *gin.Context) {
|
|
|
|
|
var callbackBody callback.RemoteUploadCallbackService
|
|
|
|
|
if err := c.ShouldBindJSON(&callbackBody); err == nil {
|
2020-01-14 21:14:15 -05:00
|
|
|
|
res := callback.ProcessCallback(callbackBody, c)
|
2019-12-30 06:08:38 -05:00
|
|
|
|
c.JSON(200, res)
|
|
|
|
|
} else {
|
|
|
|
|
c.JSON(200, ErrorResponse(err))
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-14 21:14:15 -05:00
|
|
|
|
|
|
|
|
|
// QiniuCallback 七牛上传回调
|
|
|
|
|
func QiniuCallback(c *gin.Context) {
|
2020-01-16 00:36:13 -05:00
|
|
|
|
var callbackBody callback.UploadCallbackService
|
2020-01-14 21:14:15 -05:00
|
|
|
|
if err := c.ShouldBindJSON(&callbackBody); err == nil {
|
|
|
|
|
res := callback.ProcessCallback(callbackBody, c)
|
|
|
|
|
if res.Code != 0 {
|
2020-10-26 02:33:28 -05:00
|
|
|
|
c.JSON(401, serializer.GeneralUploadCallbackFailed{Error: res.Msg})
|
2020-01-14 21:14:15 -05:00
|
|
|
|
} else {
|
|
|
|
|
c.JSON(200, res)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
c.JSON(401, ErrorResponse(err))
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-16 00:36:13 -05:00
|
|
|
|
|
|
|
|
|
// OSSCallback 阿里云OSS上传回调
|
|
|
|
|
func OSSCallback(c *gin.Context) {
|
|
|
|
|
var callbackBody callback.UploadCallbackService
|
|
|
|
|
if err := c.ShouldBindJSON(&callbackBody); err == nil {
|
2020-01-16 02:50:58 -05:00
|
|
|
|
if callbackBody.PicInfo == "," {
|
|
|
|
|
callbackBody.PicInfo = ""
|
|
|
|
|
}
|
2020-01-16 00:36:13 -05:00
|
|
|
|
res := callback.ProcessCallback(callbackBody, c)
|
|
|
|
|
c.JSON(200, res)
|
|
|
|
|
} else {
|
|
|
|
|
c.JSON(200, ErrorResponse(err))
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-17 21:40:03 -05:00
|
|
|
|
|
|
|
|
|
// UpyunCallback 又拍云上传回调
|
|
|
|
|
func UpyunCallback(c *gin.Context) {
|
|
|
|
|
var callbackBody callback.UpyunCallbackService
|
|
|
|
|
if err := c.ShouldBind(&callbackBody); err == nil {
|
|
|
|
|
if callbackBody.Code != 200 {
|
|
|
|
|
util.Log().Debug(
|
|
|
|
|
"又拍云回调返回错误代码%d,信息:%s",
|
|
|
|
|
callbackBody.Code,
|
|
|
|
|
callbackBody.Message,
|
|
|
|
|
)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
res := callback.ProcessCallback(callbackBody, c)
|
|
|
|
|
c.JSON(200, res)
|
|
|
|
|
} else {
|
|
|
|
|
c.JSON(200, ErrorResponse(err))
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-20 01:34:21 -05:00
|
|
|
|
|
|
|
|
|
// OneDriveCallback OneDrive上传完成客户端回调
|
|
|
|
|
func OneDriveCallback(c *gin.Context) {
|
|
|
|
|
var callbackBody callback.OneDriveCallback
|
|
|
|
|
if err := c.ShouldBindJSON(&callbackBody); err == nil {
|
|
|
|
|
res := callbackBody.PreProcess(c)
|
|
|
|
|
c.JSON(200, res)
|
|
|
|
|
} else {
|
|
|
|
|
c.JSON(200, ErrorResponse(err))
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-22 23:38:32 -05:00
|
|
|
|
|
2020-03-01 04:57:18 -05:00
|
|
|
|
// OneDriveOAuth OneDrive 授权回调
|
|
|
|
|
func OneDriveOAuth(c *gin.Context) {
|
|
|
|
|
var callbackBody callback.OneDriveOauthService
|
|
|
|
|
if err := c.ShouldBindQuery(&callbackBody); err == nil {
|
|
|
|
|
res := callbackBody.Auth(c)
|
2021-01-06 03:35:31 -05:00
|
|
|
|
redirect := model.GetSiteURL()
|
|
|
|
|
redirect.Path = path.Join(redirect.Path, "/admin/policy")
|
2020-03-02 03:20:33 -05:00
|
|
|
|
queries := redirect.Query()
|
|
|
|
|
queries.Add("code", strconv.Itoa(res.Code))
|
|
|
|
|
queries.Add("msg", res.Msg)
|
|
|
|
|
queries.Add("err", res.Error)
|
|
|
|
|
redirect.RawQuery = queries.Encode()
|
2021-01-06 03:35:31 -05:00
|
|
|
|
c.Redirect(303, redirect.String())
|
2020-03-01 04:57:18 -05:00
|
|
|
|
} else {
|
|
|
|
|
c.JSON(200, ErrorResponse(err))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-22 23:38:32 -05:00
|
|
|
|
// COSCallback COS上传完成客户端回调
|
|
|
|
|
func COSCallback(c *gin.Context) {
|
|
|
|
|
var callbackBody callback.COSCallback
|
|
|
|
|
if err := c.ShouldBindQuery(&callbackBody); err == nil {
|
|
|
|
|
res := callbackBody.PreProcess(c)
|
|
|
|
|
c.JSON(200, res)
|
|
|
|
|
} else {
|
|
|
|
|
c.JSON(200, ErrorResponse(err))
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-05 01:45:24 -05:00
|
|
|
|
|
|
|
|
|
// S3Callback S3上传完成客户端回调
|
|
|
|
|
func S3Callback(c *gin.Context) {
|
2020-10-11 00:05:14 -05:00
|
|
|
|
c.Header("Access-Control-Allow-Origin", "*")
|
2020-06-05 01:45:24 -05:00
|
|
|
|
var callbackBody callback.S3Callback
|
|
|
|
|
if err := c.ShouldBindQuery(&callbackBody); err == nil {
|
|
|
|
|
res := callbackBody.PreProcess(c)
|
|
|
|
|
c.JSON(200, res)
|
|
|
|
|
} else {
|
|
|
|
|
c.JSON(200, ErrorResponse(err))
|
|
|
|
|
}
|
|
|
|
|
}
|