feat(source link): create perm source link with shorter url

This commit is contained in:
HFO4
2022-10-29 11:06:07 +08:00
parent 1f836a4b8b
commit 8d7ecedf47
11 changed files with 204 additions and 53 deletions

29
middleware/file.go Normal file
View File

@ -0,0 +1,29 @@
package middleware
import (
model "github.com/cloudreve/Cloudreve/v3/models"
"github.com/cloudreve/Cloudreve/v3/pkg/serializer"
"github.com/gin-gonic/gin"
)
// ValidateSourceLink validates if the perm source link is a valid redirect link
func ValidateSourceLink() gin.HandlerFunc {
return func(c *gin.Context) {
linkID, ok := c.Get("object_id")
if !ok {
c.JSON(200, serializer.Err(serializer.CodeFileNotFound, "", nil))
c.Abort()
return
}
sourceLink, err := model.GetSourceLinkByID(linkID)
if err != nil || sourceLink.File.ID == 0 || sourceLink.File.Name != c.Param("name") {
c.JSON(200, serializer.Err(serializer.CodeFileNotFound, "", nil))
c.Abort()
return
}
c.Set("source_link", sourceLink)
c.Next()
}
}