|
|
@ -3,10 +3,10 @@ package controllers
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/cloudreve/Cloudreve/v3/pkg/filesystem"
|
|
|
|
"net/http"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
|
|
model "github.com/cloudreve/Cloudreve/v3/models"
|
|
|
|
model "github.com/cloudreve/Cloudreve/v3/models"
|
|
|
|
"github.com/cloudreve/Cloudreve/v3/pkg/filesystem"
|
|
|
|
|
|
|
|
"github.com/cloudreve/Cloudreve/v3/pkg/request"
|
|
|
|
"github.com/cloudreve/Cloudreve/v3/pkg/request"
|
|
|
|
"github.com/cloudreve/Cloudreve/v3/pkg/serializer"
|
|
|
|
"github.com/cloudreve/Cloudreve/v3/pkg/serializer"
|
|
|
|
"github.com/cloudreve/Cloudreve/v3/service/explorer"
|
|
|
|
"github.com/cloudreve/Cloudreve/v3/service/explorer"
|
|
|
@ -102,12 +102,26 @@ func AnonymousPermLink(c *gin.Context) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetSource 获取文件的外链地址
|
|
|
|
|
|
|
|
func GetSource(c *gin.Context) {
|
|
|
|
func GetSource(c *gin.Context) {
|
|
|
|
// 创建上下文
|
|
|
|
// 创建上下文
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var service explorer.ItemIDService
|
|
|
|
|
|
|
|
if err := c.ShouldBindJSON(&service); err == nil {
|
|
|
|
|
|
|
|
res := service.Sources(ctx, c)
|
|
|
|
|
|
|
|
c.JSON(200, res)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
c.JSON(200, ErrorResponse(err))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Thumb 获取文件缩略图
|
|
|
|
|
|
|
|
func Thumb(c *gin.Context) {
|
|
|
|
|
|
|
|
// 创建上下文
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
|
|
fs, err := filesystem.NewFileSystemFromContext(c)
|
|
|
|
fs, err := filesystem.NewFileSystemFromContext(c)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
c.JSON(200, serializer.Err(serializer.CodePolicyNotAllowed, err.Error(), err))
|
|
|
|
c.JSON(200, serializer.Err(serializer.CodePolicyNotAllowed, err.Error(), err))
|
|
|
@ -121,21 +135,6 @@ func GetSource(c *gin.Context) {
|
|
|
|
c.JSON(200, serializer.ParamErr("文件不存在", err))
|
|
|
|
c.JSON(200, serializer.ParamErr("文件不存在", err))
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Thumb 获取文件缩略图
|
|
|
|
|
|
|
|
func Thumb(c *gin.Context) {
|
|
|
|
|
|
|
|
// 创建上下文
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var service explorer.ItemIDService
|
|
|
|
|
|
|
|
if err := c.ShouldBindJSON(&service); err == nil {
|
|
|
|
|
|
|
|
res := service.Sources(ctx, c)
|
|
|
|
|
|
|
|
c.JSON(200, res)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
c.JSON(200, ErrorResponse(err))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取缩略图
|
|
|
|
// 获取缩略图
|
|
|
|
resp, err := fs.GetThumb(ctx, fileID.(uint))
|
|
|
|
resp, err := fs.GetThumb(ctx, fileID.(uint))
|
|
|
|