mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Feat: download / preview files in slave side
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/HFO4/cloudreve/pkg/filesystem/fsctx"
|
||||
"github.com/HFO4/cloudreve/pkg/filesystem/local"
|
||||
"github.com/HFO4/cloudreve/pkg/serializer"
|
||||
"github.com/HFO4/cloudreve/service/explorer"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/url"
|
||||
"strconv"
|
||||
@@ -80,3 +81,37 @@ func SlaveUpload(c *gin.Context) {
|
||||
Code: 0,
|
||||
})
|
||||
}
|
||||
|
||||
// SlaveDownload 从机文件下载
|
||||
func SlaveDownload(c *gin.Context) {
|
||||
// 创建上下文
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
var service explorer.SlaveDownloadService
|
||||
if err := c.ShouldBindUri(&service); err == nil {
|
||||
res := service.ServeFile(ctx, c, true)
|
||||
if res.Code != 0 {
|
||||
c.JSON(200, res)
|
||||
}
|
||||
} else {
|
||||
c.JSON(200, ErrorResponse(err))
|
||||
}
|
||||
}
|
||||
|
||||
// SlavePreview 从机文件预览
|
||||
func SlavePreview(c *gin.Context) {
|
||||
// 创建上下文
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
var service explorer.SlaveDownloadService
|
||||
if err := c.ShouldBindUri(&service); err == nil {
|
||||
res := service.ServeFile(ctx, c, false)
|
||||
if res.Code != 0 {
|
||||
c.JSON(200, res)
|
||||
}
|
||||
} else {
|
||||
c.JSON(200, ErrorResponse(err))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user