mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Feat: get file source route / Fix: cache initialize at wrong time
This commit is contained in:
@@ -15,6 +15,40 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// GetSource 获取文件的外链地址
|
||||
func GetSource(c *gin.Context) {
|
||||
// 创建上下文
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
fs, err := filesystem.NewFileSystemFromContext(c)
|
||||
if err != nil {
|
||||
c.JSON(200, serializer.Err(serializer.CodePolicyNotAllowed, err.Error(), err))
|
||||
return
|
||||
}
|
||||
|
||||
// 获取文件ID
|
||||
fileID, err := strconv.ParseUint(c.Param("id"), 10, 32)
|
||||
if err != nil {
|
||||
c.JSON(200, serializer.ParamErr("无法解析文件ID", err))
|
||||
return
|
||||
}
|
||||
|
||||
sourceURL, err := fs.GetSource(ctx, uint(fileID))
|
||||
if err != nil {
|
||||
c.JSON(200, serializer.Err(serializer.CodeNotSet, err.Error(), err))
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, serializer.Response{
|
||||
Code: 0,
|
||||
Data: struct {
|
||||
URL string `json:"url"`
|
||||
}{URL: sourceURL},
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// Thumb 获取文件缩略图
|
||||
func Thumb(c *gin.Context) {
|
||||
// 创建上下文
|
||||
|
||||
@@ -41,12 +41,17 @@ func InitRouter() *gin.Engine {
|
||||
{
|
||||
// 测试用路由
|
||||
v3.GET("site/ping", controllers.Ping)
|
||||
// 用户登录
|
||||
v3.POST("user/session", controllers.UserLogin)
|
||||
// WebAuthn登陆初始化
|
||||
v3.GET("user/authn/:username", controllers.StartLoginAuthn)
|
||||
// WebAuthn登陆
|
||||
v3.POST("user/authn/finish/:username", controllers.FinishLoginAuthn)
|
||||
|
||||
// 不需要登录的用户相关路由
|
||||
{
|
||||
// 用户登录
|
||||
v3.POST("user/session", controllers.UserLogin)
|
||||
// WebAuthn登陆初始化
|
||||
v3.GET("user/authn/:username", controllers.StartLoginAuthn)
|
||||
// WebAuthn登陆
|
||||
v3.POST("user/authn/finish/:username", controllers.FinishLoginAuthn)
|
||||
}
|
||||
|
||||
// 验证码
|
||||
v3.GET("captcha", controllers.Captcha)
|
||||
// 站点全局配置
|
||||
@@ -80,6 +85,8 @@ func InitRouter() *gin.Engine {
|
||||
file.GET("download/*path", controllers.Download)
|
||||
// 下载文件
|
||||
file.GET("thumb/:id", controllers.Thumb)
|
||||
// 取得文件外链
|
||||
file.GET("source/:id", controllers.GetSource)
|
||||
}
|
||||
|
||||
// 目录
|
||||
|
||||
Reference in New Issue
Block a user