mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
feat(source link): create perm source link with shorter url
This commit is contained in:
@@ -79,8 +79,8 @@ func AnonymousGetContent(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// AnonymousPermLink 文件签名后的永久链接
|
||||
func AnonymousPermLink(c *gin.Context) {
|
||||
// AnonymousPermLink Deprecated 文件签名后的永久链接
|
||||
func AnonymousPermLinkDeprecated(c *gin.Context) {
|
||||
// 创建上下文
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
@@ -102,6 +102,39 @@ func AnonymousPermLink(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// AnonymousPermLink 文件中转后的永久直链接
|
||||
func AnonymousPermLink(c *gin.Context) {
|
||||
// 创建上下文
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
sourceLinkRaw, ok := c.Get("source_link")
|
||||
if !ok {
|
||||
c.JSON(200, serializer.Err(serializer.CodeFileNotFound, "", nil))
|
||||
return
|
||||
}
|
||||
|
||||
sourceLink := sourceLinkRaw.(*model.SourceLink)
|
||||
|
||||
service := &explorer.FileAnonymousGetService{
|
||||
ID: sourceLink.FileID,
|
||||
Name: sourceLink.File.Name,
|
||||
}
|
||||
|
||||
res := service.Source(ctx, c)
|
||||
// 是否需要重定向
|
||||
if res.Code == -302 {
|
||||
c.Redirect(302, res.Data.(string))
|
||||
return
|
||||
}
|
||||
|
||||
// 是否有错误发生
|
||||
if res.Code != 0 {
|
||||
c.JSON(200, res)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func GetSource(c *gin.Context) {
|
||||
// 创建上下文
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
Reference in New Issue
Block a user