Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
hexbee
Cloudreve
提交
d3015957
C
Cloudreve
项目概览
hexbee
/
Cloudreve
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Cloudreve
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
d3015957
编写于
2月 08, 2020
作者:
H
HFO4
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Feat: list downloading file
上级
356ac8d6
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
95 addition
and
1 deletion
+95
-1
models/download.go
models/download.go
+8
-0
pkg/aria2/caller.go
pkg/aria2/caller.go
+9
-1
pkg/serializer/aria2.go
pkg/serializer/aria2.go
+54
-0
routers/controllers/aria2.go
routers/controllers/aria2.go
+11
-0
routers/router.go
routers/router.go
+2
-0
service/aria2/manage.go
service/aria2/manage.go
+11
-0
未找到文件。
models/download.go
浏览文件 @
d3015957
...
...
@@ -71,6 +71,14 @@ func GetDownloadsByStatus(status ...int) []Download {
return
tasks
}
// GetDownloadsByStatusAndUser 根据状态检索和用户ID下载
// TODO 测试
func
GetDownloadsByStatusAndUser
(
uid
uint
,
status
...
int
)
[]
Download
{
var
tasks
[]
Download
DB
.
Where
(
"user_id = ? and status in (?)"
,
uid
,
status
)
.
Find
(
&
tasks
)
return
tasks
}
// GetDownloadByGid 根据GID和用户ID查找下载
func
GetDownloadByGid
(
gid
string
,
uid
uint
)
(
*
Download
,
error
)
{
download
:=
&
Download
{}
...
...
pkg/aria2/caller.go
浏览文件 @
d3015957
...
...
@@ -39,7 +39,15 @@ func (client *RPCService) Init(server, secret string, timeout int, options []int
// Status 查询下载状态
func
(
client
*
RPCService
)
Status
(
task
*
model
.
Download
)
(
rpc
.
StatusInfo
,
error
)
{
return
client
.
caller
.
TellStatus
(
task
.
GID
)
res
,
err
:=
client
.
caller
.
TellStatus
(
task
.
GID
)
if
err
!=
nil
{
// 失败后重试
util
.
Log
()
.
Debug
(
"无法获取离线下载状态,%s,10秒钟后重试"
,
err
)
time
.
Sleep
(
time
.
Duration
(
10
)
*
time
.
Second
)
res
,
err
=
client
.
caller
.
TellStatus
(
task
.
GID
)
}
return
res
,
err
}
// Cancel 取消下载
...
...
pkg/serializer/aria2.go
0 → 100644
浏览文件 @
d3015957
package
serializer
import
(
model
"github.com/HFO4/cloudreve/models"
"github.com/zyxar/argo/rpc"
"path"
)
// DownloadListResponse 下载列表响应条目
type
DownloadListResponse
struct
{
UpdateTime
int64
`json:"update"`
Name
string
`json:"name"`
Status
int
`json:"status"`
UserID
uint
`json:"uid"`
Error
string
`json:"error"`
Dst
string
`json:"dst"`
Total
uint64
`json:"total"`
Downloaded
uint64
`json:"downloaded"`
Speed
int
`json:"speed"`
Info
rpc
.
StatusInfo
`json:"info"`
}
// BuildDownloadingResponse 构建正在下载的列表响应
func
BuildDownloadingResponse
(
tasks
[]
model
.
Download
)
Response
{
resp
:=
make
([]
DownloadListResponse
,
0
,
len
(
tasks
))
for
i
:=
0
;
i
<
len
(
tasks
);
i
++
{
fileName
:=
""
if
len
(
tasks
[
i
]
.
StatusInfo
.
Files
)
>
0
{
fileName
=
path
.
Base
(
tasks
[
i
]
.
StatusInfo
.
Files
[
0
]
.
Path
)
}
// 过滤敏感信息
tasks
[
i
]
.
StatusInfo
.
Dir
=
""
for
i2
:=
0
;
i2
<
len
(
tasks
[
i
]
.
StatusInfo
.
Files
);
i2
++
{
tasks
[
i
]
.
StatusInfo
.
Files
[
i2
]
.
Path
=
path
.
Base
(
tasks
[
i
]
.
StatusInfo
.
Files
[
i2
]
.
Path
)
}
resp
=
append
(
resp
,
DownloadListResponse
{
UpdateTime
:
tasks
[
i
]
.
UpdatedAt
.
Unix
(),
Name
:
fileName
,
Status
:
tasks
[
i
]
.
Status
,
UserID
:
tasks
[
i
]
.
UserID
,
Error
:
tasks
[
i
]
.
Error
,
Dst
:
tasks
[
i
]
.
Dst
,
Total
:
tasks
[
i
]
.
TotalSize
,
Downloaded
:
tasks
[
i
]
.
DownloadedSize
,
Speed
:
tasks
[
i
]
.
Speed
,
Info
:
tasks
[
i
]
.
StatusInfo
,
})
}
return
Response
{
Data
:
resp
}
}
routers/controllers/aria2.go
浏览文件 @
d3015957
...
...
@@ -81,3 +81,14 @@ func CancelAria2Download(c *gin.Context) {
c
.
JSON
(
200
,
ErrorResponse
(
err
))
}
}
// ListDownloading 获取正在下载中的任务
func
ListDownloading
(
c
*
gin
.
Context
)
{
var
service
aria2
.
DownloadListService
if
err
:=
c
.
ShouldBindQuery
(
&
service
);
err
==
nil
{
res
:=
service
.
Downloading
(
c
,
CurrentUser
(
c
))
c
.
JSON
(
200
,
res
)
}
else
{
c
.
JSON
(
200
,
ErrorResponse
(
err
))
}
}
routers/router.go
浏览文件 @
d3015957
...
...
@@ -284,6 +284,8 @@ func InitMasterRouter() *gin.Engine {
aria2
.
PUT
(
"select/:gid"
,
controllers
.
SelectAria2File
)
// 取消下载任务
aria2
.
DELETE
(
"task/:gid"
,
controllers
.
CancelAria2Download
)
// 获取正在下载中的任务
aria2
.
GET
(
"downloading"
,
controllers
.
ListDownloading
)
}
// 目录
...
...
service/aria2/manage.go
浏览文件 @
d3015957
...
...
@@ -17,6 +17,17 @@ type DownloadTaskService struct {
GID
string
`uri:"gid" binding:"required"`
}
// DownloadListService 下载列表服务
type
DownloadListService
struct
{
}
// Downloading 获取正在下载中的任务
func
(
service
*
DownloadListService
)
Downloading
(
c
*
gin
.
Context
,
user
*
model
.
User
)
serializer
.
Response
{
// 查找下载记录
downloads
:=
model
.
GetDownloadsByStatusAndUser
(
user
.
ID
,
aria2
.
Downloading
,
aria2
.
Paused
,
aria2
.
Ready
)
return
serializer
.
BuildDownloadingResponse
(
downloads
)
}
// Delete 取消下载任务
func
(
service
*
DownloadTaskService
)
Delete
(
c
*
gin
.
Context
)
serializer
.
Response
{
userCtx
,
_
:=
c
.
Get
(
"user"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录