Skip to content

Commit

Permalink
feat: add upload progress and fix panic
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-ding committed Nov 17, 2024
1 parent 7d5ce8b commit ba3f6de
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
9 changes: 9 additions & 0 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,15 @@ func (s *StorageInfo) ToWebDavSetting() WebdavSetting {
}
}

func (s *StorageInfo) ToAlistSetting() WebdavSetting {
return WebdavSetting{
URL: s.Settings["url"],
User: s.Settings["user"],
Password: s.Settings["password"],
ChangeFileHash: s.Settings["change_file_hash"],
}
}

type WebdavSetting struct {
URL string `json:"url"`
User string `json:"user"`
Expand Down
8 changes: 6 additions & 2 deletions server/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import (

type Activity struct {
*ent.History
Progress int `json:"progress"`
SeedRatio float64 `json:"seed_ratio"`
Progress int `json:"progress"`
SeedRatio float64 `json:"seed_ratio"`
UploadProgress float64 `json:"upload_progress"`
}

func (s *Server) GetAllActivities(c *gin.Context) (interface{}, error) {
Expand All @@ -44,6 +45,9 @@ func (s *Server) GetAllActivities(c *gin.Context) (interface{}, error) {
} else {
a.SeedRatio = r
}
if task.UploadProgresser != nil {
a.UploadProgress = task.UploadProgresser()
}
}
}
activities = append(activities, a)
Expand Down
2 changes: 2 additions & 0 deletions server/core/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ func (c *Client) moveCompletedTask(id int) (err1 error) {
if err := stImpl.Copy(filepath.Join(c.db.GetDownloadDir(), torrentName), r.TargetDir); err != nil {
return errors.Wrap(err, "move file")
}
torrent.UploadProgresser = stImpl.UploadProgress

c.db.SetHistoryStatus(r.ID, history.StatusSeeding)
if len(episodeIds) > 0 {
Expand Down Expand Up @@ -285,6 +286,7 @@ func (c *Client) CheckDownloadedSeriesFiles(m *ent.Media) error {
type Task struct {
//Processing bool
pkg.Torrent
UploadProgresser func() float64
}

func (c *Client) DownloadSeriesAllEpisodes(id int) []string {
Expand Down
2 changes: 1 addition & 1 deletion server/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s *Server) AddStorage(c *gin.Context) (interface{}, error) {
log.Infof("file name: %v", f.Name())
}
} else if in.Implementation == "alist" {
cfg := in.ToWebDavSetting()
cfg := in.ToAlistSetting()
_, err := storage.NewAlist(&alist.Config{URL: cfg.URL, Username: cfg.User, Password: cfg.Password}, in.TvPath)
if err != nil {
return nil, errors.Wrap(err, "alist")
Expand Down
7 changes: 5 additions & 2 deletions ui/lib/providers/activity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Activity {
required this.saved,
required this.progress,
required this.size,
required this.seedRatio});
required this.seedRatio, required this.uploadProgress});

final int? id;
final int? mediaId;
Expand All @@ -86,6 +86,7 @@ class Activity {
final int? progress;
final int? size;
final double seedRatio;
final double uploadProgress;

factory Activity.fromJson(Map<String, dynamic> json) {
return Activity(
Expand All @@ -99,6 +100,8 @@ class Activity {
saved: json["saved"],
progress: json["progress"],
seedRatio: json["seed_ratio"],
size: json["size"]);
size: json["size"],
uploadProgress: json["upload_progress"]
);
}
}

0 comments on commit ba3f6de

Please sign in to comment.