Feat: get permanent URL for OneDrive policy

This commit is contained in:
HFO4
2021-03-20 12:33:39 +08:00
parent 6fb419d998
commit a5f80a4431
5 changed files with 72 additions and 5 deletions

View File

@@ -88,6 +88,29 @@ func AnonymousGetContent(c *gin.Context) {
}
}
// AnonymousPermLink 文件签名后的永久链接
func AnonymousPermLink(c *gin.Context) {
// 创建上下文
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var service explorer.FileAnonymousGetService
if err := c.ShouldBindUri(&service); err == nil {
res := service.Source(ctx, c)
// 是否需要重定向
if res.Code == -302 {
c.Redirect(302, res.Data.(string))
return
}
// 是否有错误发生
if res.Code != 0 {
c.JSON(200, res)
}
} else {
c.JSON(200, ErrorResponse(err))
}
}
// GetSource 获取文件的外链地址
func GetSource(c *gin.Context) {
// 创建上下文

View File

@@ -162,8 +162,10 @@ func InitMasterRouter() *gin.Engine {
{
file := sign.Group("file")
{
// 文件外链
// 文件外链(直接输出文件数据)
file.GET("get/:id/:name", controllers.AnonymousGetContent)
// 文件外链(301跳转)
file.GET("source/:id/:name", controllers.AnonymousPermLink)
// 下載已经打包好的文件
file.GET("archive/:id/archive.zip", controllers.DownloadArchive)
// 下载文件