mirror of https://github.com/Xhofe/alist
parent
4741a75c92
commit
f3db23a41e
|
@ -158,6 +158,7 @@ func InitialSettings() []model.SettingItem {
|
||||||
|
|
||||||
// qbittorrent settings
|
// qbittorrent settings
|
||||||
{Key: conf.QbittorrentUrl, Value: "http://admin:adminadmin@localhost:8080/", Type: conf.TypeString, Group: model.SINGLE, Flag: model.PRIVATE},
|
{Key: conf.QbittorrentUrl, Value: "http://admin:adminadmin@localhost:8080/", Type: conf.TypeString, Group: model.SINGLE, Flag: model.PRIVATE},
|
||||||
|
{Key: conf.QbittorrentSeedtime, Value: "0", Type: conf.TypeNumber, Group: model.SINGLE, Flag: model.PRIVATE},
|
||||||
}
|
}
|
||||||
if flags.Dev {
|
if flags.Dev {
|
||||||
initialSettingItems = append(initialSettingItems, []model.SettingItem{
|
initialSettingItems = append(initialSettingItems, []model.SettingItem{
|
||||||
|
|
|
@ -61,7 +61,8 @@ const (
|
||||||
SSOLoginplatform = "sso_login_platform"
|
SSOLoginplatform = "sso_login_platform"
|
||||||
|
|
||||||
// qbittorrent
|
// qbittorrent
|
||||||
QbittorrentUrl = "qbittorrent_url"
|
QbittorrentUrl = "qbittorrent_url"
|
||||||
|
QbittorrentSeedtime = "qbittorrent_seedtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/alist-org/alist/v3/internal/conf"
|
"github.com/alist-org/alist/v3/internal/conf"
|
||||||
"github.com/alist-org/alist/v3/internal/errs"
|
"github.com/alist-org/alist/v3/internal/errs"
|
||||||
"github.com/alist-org/alist/v3/internal/op"
|
"github.com/alist-org/alist/v3/internal/op"
|
||||||
|
"github.com/alist-org/alist/v3/internal/setting"
|
||||||
"github.com/alist-org/alist/v3/pkg/task"
|
"github.com/alist-org/alist/v3/pkg/task"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
@ -50,6 +51,7 @@ func AddURL(ctx context.Context, url string, dstDirPath string) error {
|
||||||
tsk: tsk,
|
tsk: tsk,
|
||||||
tempDir: tempDir,
|
tempDir: tempDir,
|
||||||
dstDirPath: dstDirPath,
|
dstDirPath: dstDirPath,
|
||||||
|
seedtime: setting.GetInt(conf.QbittorrentSeedtime, 0),
|
||||||
}
|
}
|
||||||
return m.Loop()
|
return m.Loop()
|
||||||
},
|
},
|
||||||
|
|
|
@ -2,23 +2,26 @@ package qbittorrent
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/alist-org/alist/v3/internal/model"
|
"github.com/alist-org/alist/v3/internal/model"
|
||||||
"github.com/alist-org/alist/v3/internal/op"
|
"github.com/alist-org/alist/v3/internal/op"
|
||||||
"github.com/alist-org/alist/v3/pkg/task"
|
"github.com/alist-org/alist/v3/pkg/task"
|
||||||
"github.com/alist-org/alist/v3/pkg/utils"
|
"github.com/alist-org/alist/v3/pkg/utils"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"sync"
|
|
||||||
"sync/atomic"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Monitor struct {
|
type Monitor struct {
|
||||||
tsk *task.Task[string]
|
tsk *task.Task[string]
|
||||||
tempDir string
|
tempDir string
|
||||||
dstDirPath string
|
dstDirPath string
|
||||||
|
seedtime int
|
||||||
finish chan struct{}
|
finish chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,17 +117,27 @@ func (m *Monitor) complete() error {
|
||||||
log.Debugf("files len: %d", len(files))
|
log.Debugf("files len: %d", len(files))
|
||||||
// delete qbittorrent task but do not delete the files before transferring to avoid qbittorrent
|
// delete qbittorrent task but do not delete the files before transferring to avoid qbittorrent
|
||||||
// accessing downloaded files and throw `cannot access the file because it is being used by another process` error
|
// accessing downloaded files and throw `cannot access the file because it is being used by another process` error
|
||||||
err = qbclient.Delete(m.tsk.ID, false)
|
// err = qbclient.Delete(m.tsk.ID, false)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
// upload files
|
// upload files
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(len(files))
|
wg.Add(len(files))
|
||||||
go func() {
|
go func() {
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
err := os.RemoveAll(m.tempDir)
|
|
||||||
m.finish <- struct{}{}
|
m.finish <- struct{}{}
|
||||||
|
if m.seedtime < 0 {
|
||||||
|
log.Debugf("do not delete qb task %s", m.tsk.ID)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Debugf("delete qb task %s after %d minutes", m.tsk.ID, m.seedtime)
|
||||||
|
<-time.After(time.Duration(m.seedtime) * time.Minute)
|
||||||
|
err := qbclient.Delete(m.tsk.ID, true)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorln(err.Error())
|
||||||
|
}
|
||||||
|
err = os.RemoveAll(m.tempDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("failed to remove qbittorrent temp dir: %+v", err.Error())
|
log.Errorf("failed to remove qbittorrent temp dir: %+v", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -151,7 +164,7 @@ func (m *Monitor) complete() error {
|
||||||
Modified: time.Now(),
|
Modified: time.Now(),
|
||||||
IsFolder: false,
|
IsFolder: false,
|
||||||
},
|
},
|
||||||
ReadCloser: f,
|
ReadCloser: struct{ io.ReadSeekCloser }{f},
|
||||||
Mimetype: mimetype,
|
Mimetype: mimetype,
|
||||||
}
|
}
|
||||||
return op.Put(tsk.Ctx, storage, dstDir, stream, tsk.SetProgress)
|
return op.Put(tsk.Ctx, storage, dstDir, stream, tsk.SetProgress)
|
||||||
|
|
|
@ -10,7 +10,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type SetQbittorrentReq struct {
|
type SetQbittorrentReq struct {
|
||||||
Url string `json:"url" form:"url"`
|
Url string `json:"url" form:"url"`
|
||||||
|
Seedtime string `json:"seedtime" form:"seedtime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetQbittorrent(c *gin.Context) {
|
func SetQbittorrent(c *gin.Context) {
|
||||||
|
@ -19,14 +20,11 @@ func SetQbittorrent(c *gin.Context) {
|
||||||
common.ErrorResp(c, err, 400)
|
common.ErrorResp(c, err, 400)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
item := &model.SettingItem{
|
items := []model.SettingItem{
|
||||||
Key: conf.QbittorrentUrl,
|
{Key: conf.QbittorrentUrl, Value: req.Url, Type: conf.TypeString, Group: model.SINGLE, Flag: model.PRIVATE},
|
||||||
Value: req.Url,
|
{Key: conf.QbittorrentSeedtime, Value: req.Seedtime, Type: conf.TypeNumber, Group: model.SINGLE, Flag: model.PRIVATE},
|
||||||
Type: conf.TypeString,
|
|
||||||
Group: model.SINGLE,
|
|
||||||
Flag: model.PRIVATE,
|
|
||||||
}
|
}
|
||||||
if err := op.SaveSettingItem(item); err != nil {
|
if err := op.SaveSettingItems(items); err != nil {
|
||||||
common.ErrorResp(c, err, 500)
|
common.ErrorResp(c, err, 500)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue