forked from AlistGo/alist
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(qbittorrent): authorization and logging in support * feat(qbittorrent/client): support `AddFromLink` * refactor(qbittorrent/client): check authorization when getting a new client * feat(qbittorrent/client): support `GetInfo` * test(qbittorrent/client): update test cases * feat(qbittorrent): init qbittorrent client on bootstrap * feat(qbittorrent): support setting webui url via gin * feat(qbittorrent/client): support deleting * feat(qbittorrent/client): parse `TorrentStatus` enum when unmarshalling json in `GetInfo()` * feat(qbittorrent/client): support getting files by id * feat(qbittorrent): support adding qbittorrent tasks via gin * refactor(qbittorrent/client): return a `Client` interface in `New()` instead of `*client` * refactor: task handle * chore: fix typo * chore: change path --------- Co-authored-by: Andy Hsu <[email protected]>
- Loading branch information
Showing
14 changed files
with
932 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package bootstrap | ||
|
||
import ( | ||
"github.com/alist-org/alist/v3/internal/qbittorrent" | ||
"github.com/alist-org/alist/v3/pkg/utils" | ||
) | ||
|
||
func InitQbittorrent() { | ||
go func() { | ||
err := qbittorrent.InitClient() | ||
if err != nil { | ||
utils.Log.Infof("qbittorrent not ready.") | ||
} | ||
}() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ const ( | |
ARIA2 | ||
INDEX | ||
GITHUB | ||
QBITTORRENT | ||
) | ||
|
||
const ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package qbittorrent | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"path/filepath" | ||
|
||
"github.com/alist-org/alist/v3/internal/conf" | ||
"github.com/alist-org/alist/v3/internal/errs" | ||
"github.com/alist-org/alist/v3/internal/op" | ||
"github.com/alist-org/alist/v3/pkg/task" | ||
"github.com/google/uuid" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func AddURL(ctx context.Context, url string, dstDirPath string) error { | ||
// check storage | ||
storage, dstDirActualPath, err := op.GetStorageAndActualPath(dstDirPath) | ||
if err != nil { | ||
return errors.WithMessage(err, "failed get storage") | ||
} | ||
// check is it could upload | ||
if storage.Config().NoUpload { | ||
return errors.WithStack(errs.UploadNotSupported) | ||
} | ||
// check path is valid | ||
obj, err := op.Get(ctx, storage, dstDirActualPath) | ||
if err != nil { | ||
if !errs.IsObjectNotFound(err) { | ||
return errors.WithMessage(err, "failed get object") | ||
} | ||
} else { | ||
if !obj.IsDir() { | ||
// can't add to a file | ||
return errors.WithStack(errs.NotFolder) | ||
} | ||
} | ||
// call qbittorrent | ||
id := uuid.NewString() | ||
tempDir := filepath.Join(conf.Conf.TempDir, "qbittorrent", id) | ||
err = qbclient.AddFromLink(url, tempDir, id) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to add url %s", url) | ||
} | ||
DownTaskManager.Submit(task.WithCancelCtx(&task.Task[string]{ | ||
ID: id, | ||
Name: fmt.Sprintf("download %s to [%s](%s)", url, storage.GetStorage().MountPath, dstDirActualPath), | ||
Func: func(tsk *task.Task[string]) error { | ||
m := &Monitor{ | ||
tsk: tsk, | ||
tempDir: tempDir, | ||
dstDirPath: dstDirPath, | ||
} | ||
return m.Loop() | ||
}, | ||
})) | ||
return nil | ||
} |
Oops, something went wrong.