mirror of
https://github.com/simon-ding/polaris.git
synced 2026-05-26 20:47:57 +08:00
feat: transmission use hash instead of id
This commit is contained in:
@@ -53,7 +53,7 @@ func (c *Client) GetAll() ([]*Torrent, error) {
|
|||||||
var torrents []*Torrent
|
var torrents []*Torrent
|
||||||
for _, t := range all {
|
for _, t := range all {
|
||||||
torrents = append(torrents, &Torrent{
|
torrents = append(torrents, &Torrent{
|
||||||
ID: *t.ID,
|
Hash: *t.HashString,
|
||||||
c: c.c,
|
c: c.c,
|
||||||
Config: c.cfg,
|
Config: c.cfg,
|
||||||
})
|
})
|
||||||
@@ -86,12 +86,12 @@ func (c *Client) Download(link, dir string) (*Torrent, error) {
|
|||||||
DownloadDir: &dir,
|
DownloadDir: &dir,
|
||||||
})
|
})
|
||||||
log.Infof("get torrent info: %+v", t)
|
log.Infof("get torrent info: %+v", t)
|
||||||
if t.ID == nil {
|
if t.HashString == nil {
|
||||||
return nil, fmt.Errorf("download torrent error: %v", link)
|
return nil, fmt.Errorf("download torrent error: %v", link)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Torrent{
|
return &Torrent{
|
||||||
ID: *t.ID,
|
Hash: *t.HashString,
|
||||||
c: c.c,
|
c: c.c,
|
||||||
Config: c.cfg,
|
Config: c.cfg,
|
||||||
}, err
|
}, err
|
||||||
@@ -100,7 +100,7 @@ func (c *Client) Download(link, dir string) (*Torrent, error) {
|
|||||||
type Torrent struct {
|
type Torrent struct {
|
||||||
//t *transmissionrpc.Torrent
|
//t *transmissionrpc.Torrent
|
||||||
c *transmissionrpc.Client
|
c *transmissionrpc.Client
|
||||||
ID int64 `json:"id"`
|
Hash string `json:"hash"`
|
||||||
Config
|
Config
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@ func (t *Torrent) reloadClient() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *Torrent) getTorrent() transmissionrpc.Torrent {
|
func (t *Torrent) getTorrent() transmissionrpc.Torrent {
|
||||||
r, err := t.c.TorrentGetAllFor(context.TODO(), []int64{t.ID})
|
r, err := t.c.TorrentGetAllForHashes(context.TODO(), []string{t.Hash})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("get torrent info for error: %v", err)
|
log.Errorf("get torrent info for error: %v", err)
|
||||||
}
|
}
|
||||||
@@ -122,7 +122,7 @@ func (t *Torrent) getTorrent() transmissionrpc.Torrent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *Torrent) Exists() bool {
|
func (t *Torrent) Exists() bool {
|
||||||
r, err := t.c.TorrentGetAllFor(context.TODO(), []int64{t.ID})
|
r, err := t.c.TorrentGetAllForHashes(context.TODO(), []string{t.Hash})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("get torrent info for error: %v", err)
|
log.Errorf("get torrent info for error: %v", err)
|
||||||
}
|
}
|
||||||
@@ -155,7 +155,7 @@ func (t *Torrent) Progress() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *Torrent) Stop() error {
|
func (t *Torrent) Stop() error {
|
||||||
return t.c.TorrentStopIDs(context.TODO(), []int64{t.ID})
|
return t.c.TorrentStopHashes(context.TODO(), []string{t.Hash})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Torrent) SeedRatio() *float64 {
|
func (t *Torrent) SeedRatio() *float64 {
|
||||||
@@ -163,12 +163,13 @@ func (t *Torrent) SeedRatio() *float64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *Torrent) Start() error {
|
func (t *Torrent) Start() error {
|
||||||
return t.c.TorrentStartIDs(context.TODO(), []int64{t.ID})
|
return t.c.TorrentStartHashes(context.TODO(), []string{t.Hash})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Torrent) Remove() error {
|
func (t *Torrent) Remove() error {
|
||||||
|
tt := t.getTorrent()
|
||||||
return t.c.TorrentRemove(context.TODO(), transmissionrpc.TorrentRemovePayload{
|
return t.c.TorrentRemove(context.TODO(), transmissionrpc.TorrentRemovePayload{
|
||||||
IDs: []int64{t.ID},
|
IDs: []int64{*tt.ID},
|
||||||
DeleteLocalData: true,
|
DeleteLocalData: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ func (s *Server) GetMediaDownloadHistory(c *gin.Context) (interface{}, error) {
|
|||||||
|
|
||||||
type TorrentInfo struct {
|
type TorrentInfo struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
ID int64 `json:"id"`
|
ID string `json:"id"`
|
||||||
SeedRatio float32 `json:"seed_ratio"`
|
SeedRatio float32 `json:"seed_ratio"`
|
||||||
Progress int `json:"progress"`
|
Progress int `json:"progress"`
|
||||||
}
|
}
|
||||||
@@ -128,7 +128,7 @@ func (s *Server) GetAllTorrents(c *gin.Context) (interface{}, error) {
|
|||||||
}
|
}
|
||||||
infos = append(infos, TorrentInfo{
|
infos = append(infos, TorrentInfo{
|
||||||
Name: t.Name(),
|
Name: t.Name(),
|
||||||
ID: t.ID,
|
ID: t.Hash,
|
||||||
Progress: t.Progress(),
|
Progress: t.Progress(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Function(int) onDelete() {
|
Function(String) onDelete() {
|
||||||
return (id) {
|
return (id) {
|
||||||
final f = ref
|
final f = ref
|
||||||
.read(activitiesDataProvider("active").notifier)
|
.read(activitiesDataProvider("active").notifier)
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class ActivityData extends AutoDisposeFamilyAsyncNotifier<List<Activity>, String
|
|||||||
return activities;
|
return activities;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> deleteActivity(int id) async {
|
Future<void> deleteActivity(String id) async {
|
||||||
final dio = await APIs.getDio();
|
final dio = await APIs.getDio();
|
||||||
var resp = await dio.delete("${APIs.activityUrl}$id");
|
var resp = await dio.delete("${APIs.activityUrl}$id");
|
||||||
final sp = ServerResponse.fromJson(resp.data);
|
final sp = ServerResponse.fromJson(resp.data);
|
||||||
@@ -72,7 +72,7 @@ class Activity {
|
|||||||
required this.size,
|
required this.size,
|
||||||
required this.seedRatio});
|
required this.seedRatio});
|
||||||
|
|
||||||
final int? id;
|
final String? id;
|
||||||
final int? mediaId;
|
final int? mediaId;
|
||||||
final int? episodeId;
|
final int? episodeId;
|
||||||
final String? sourceTitle;
|
final String? sourceTitle;
|
||||||
|
|||||||
Reference in New Issue
Block a user