feat(offline_download): add transmission (close #4102 in #7232)

This commit is contained in:
Shelton Zhu
2024-09-28 23:15:58 +08:00
committed by GitHub
parent 6106a2d4cc
commit bdf4b52885
8 changed files with 248 additions and 8 deletions

View File

@ -30,6 +30,10 @@ func SetAria2(c *gin.Context) {
return
}
_tool, err := tool.Tools.Get("aria2")
if err != nil {
common.ErrorResp(c, err, 500)
return
}
version, err := _tool.Init()
if err != nil {
common.ErrorResp(c, err, 500)
@ -74,6 +78,37 @@ func OfflineDownloadTools(c *gin.Context) {
common.SuccessResp(c, tools)
}
type SetTransmissionReq struct {
Uri string `json:"uri" form:"uri"`
Seedtime string `json:"seedtime" form:"seedtime"`
}
func SetTransmission(c *gin.Context) {
var req SetTransmissionReq
if err := c.ShouldBind(&req); err != nil {
common.ErrorResp(c, err, 400)
return
}
items := []model.SettingItem{
{Key: conf.TransmissionUri, Value: req.Uri, Type: conf.TypeString, Group: model.OFFLINE_DOWNLOAD, Flag: model.PRIVATE},
{Key: conf.TransmissionSeedtime, Value: req.Seedtime, Type: conf.TypeNumber, Group: model.OFFLINE_DOWNLOAD, Flag: model.PRIVATE},
}
if err := op.SaveSettingItems(items); err != nil {
common.ErrorResp(c, err, 500)
return
}
_tool, err := tool.Tools.Get("transmission")
if err != nil {
common.ErrorResp(c, err, 500)
return
}
if _, err := _tool.Init(); err != nil {
common.ErrorResp(c, err, 500)
return
}
common.SuccessResp(c, "ok")
}
type AddOfflineDownloadReq struct {
Urls []string `json:"urls"`
Path string `json:"path"`

View File

@ -62,7 +62,7 @@ func Init(e *gin.Engine) {
api.GET("/auth/get_sso_id", handles.SSOLoginCallback)
api.GET("/auth/sso_get_token", handles.SSOLoginCallback)
//webauthn
// webauthn
webauthn.GET("/webauthn_begin_registration", handles.BeginAuthnRegistration)
webauthn.POST("/webauthn_finish_registration", handles.FinishAuthnRegistration)
webauthn.GET("/webauthn_begin_login", handles.BeginAuthnLogin)
@ -125,6 +125,7 @@ func admin(g *gin.RouterGroup) {
setting.POST("/reset_token", handles.ResetToken)
setting.POST("/set_aria2", handles.SetAria2)
setting.POST("/set_qbit", handles.SetQbittorrent)
setting.POST("/set_transmission", handles.SetTransmission)
task := g.Group("/task")
handles.SetupTaskRoute(task)
@ -159,14 +160,15 @@ func _fs(g *gin.RouterGroup) {
g.PUT("/put", middlewares.FsUp, handles.FsStream)
g.PUT("/form", middlewares.FsUp, handles.FsForm)
g.POST("/link", middlewares.AuthAdmin, handles.Link)
//g.POST("/add_aria2", handles.AddOfflineDownload)
//g.POST("/add_qbit", handles.AddQbittorrent)
// g.POST("/add_aria2", handles.AddOfflineDownload)
// g.POST("/add_qbit", handles.AddQbittorrent)
// g.POST("/add_transmission", handles.SetTransmission)
g.POST("/add_offline_download", handles.AddOfflineDownload)
}
func Cors(r *gin.Engine) {
config := cors.DefaultConfig()
//config.AllowAllOrigins = true
// config.AllowAllOrigins = true
config.AllowOrigins = conf.Conf.Cors.AllowOrigins
config.AllowHeaders = conf.Conf.Cors.AllowHeaders
config.AllowMethods = conf.Conf.Cors.AllowMethods