Skip to content

Commit

Permalink
feat: add thanks item for contributors (GopeedLab#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyWie authored and dcguo committed Jan 17, 2024
1 parent 4987009 commit 1fd9d42
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 23 deletions.
4 changes: 2 additions & 2 deletions internal/fetcher/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Fetcher interface {
Close() error

// Stats refreshes health statistics and returns the latest information
Stats() *base.Stats
Stats() any
// Meta returns the meta information of the download.
Meta() *FetcherMeta
// Progress returns the progress of the download.
Expand All @@ -36,7 +36,7 @@ type FetcherMeta struct {
Req *base.Request `json:"req"`
Res *base.Resource `json:"res"`
Opts *base.Options `json:"opts"`
Stats *base.Stats `json:"stats"`
Stats any `json:"stats"`
}

// FolderPath return the folder path of the meta info.
Expand Down
18 changes: 13 additions & 5 deletions internal/protocol/bt/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (f *Fetcher) Meta() *fetcher.FetcherMeta {
return f.meta
}

func (f *Fetcher) Stats() *base.Stats {
func (f *Fetcher) Stats() any {
f.refreshStats()
return f.meta.Stats
}
Expand All @@ -200,11 +200,19 @@ func (f *Fetcher) Stats() *base.Stats {
func (f *Fetcher) refreshStats() {
stats := f.torrent.Stats()
if f.meta.Stats == nil {
f.meta.Stats = &base.Stats{}
baseStats := &bt.Stats{
TotalPeers: stats.TotalPeers,
ActivePeers: stats.ActivePeers,
ConnectedSeeders: stats.ConnectedSeeders,
}
f.meta.Stats = baseStats
} else {
if baseStats, ok := f.meta.Stats.(*bt.Stats); ok {
baseStats.TotalPeers = stats.TotalPeers
baseStats.ActivePeers = stats.ActivePeers
baseStats.ConnectedSeeders = stats.ConnectedSeeders
}
}
f.meta.Stats.TotalPeers = stats.TotalPeers
f.meta.Stats.ActivePeers = stats.ActivePeers
f.meta.Stats.ConnectedSeeders = stats.ConnectedSeeders
}

func (f *Fetcher) Progress() fetcher.Progress {
Expand Down
4 changes: 2 additions & 2 deletions internal/protocol/http/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (f *Fetcher) Meta() *fetcher.FetcherMeta {
return f.meta
}

func (f *Fetcher) Stats() *base.Stats {
func (f *Fetcher) Stats() any {
f.refreshStats()
// todo http download health
return f.meta.Stats
Expand All @@ -228,7 +228,7 @@ func (f *Fetcher) Stats() *base.Stats {
// refreshStats update http/https health metrics
func (f *Fetcher) refreshStats() {
if f.meta.Stats == nil {
f.meta.Stats = &base.Stats{}
f.meta.Stats = &fhttp.Stats{}
}
}

Expand Down
11 changes: 0 additions & 11 deletions pkg/base/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,6 @@ type Options struct {
Extra any `json:"extra"`
}

// Stats for download
type Stats struct {
// http stats
// TODO
// bt stats
// health indicators of torrents, from large to small, ConnectedSeeders are also the key to the health of seed resources
TotalPeers int `json:"totalPeers"`
ActivePeers int `json:"activePeers"`
ConnectedSeeders int `json:"connectedSeeders"`
}

func (o *Options) InitSelectFiles(fileSize int) {
// if selectFiles is empty, select all files
if len(o.SelectFiles) == 0 {
Expand Down
4 changes: 1 addition & 3 deletions pkg/download/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@ func (d *Downloader) Setup() error {
return
}

if task.Meta.Res.Hash != "" {
task.fetcher.Meta()
}
task.fetcher.Stats()
}()
}
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/protocol/bt/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@ package bt
type ReqExtra struct {
Trackers []string `json:"trackers"`
}

// Stats for download
type Stats struct {
// bt stats
// health indicators of torrents, from large to small, ConnectedSeeders are also the key to the health of seed resources
TotalPeers int `json:"totalPeers"`
ActivePeers int `json:"activePeers"`
ConnectedSeeders int `json:"connectedSeeders"`
}
6 changes: 6 additions & 0 deletions pkg/protocol/http/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ type ReqExtra struct {
type OptsExtra struct {
Connections int `json:"connections"`
}

// Stats for download
type Stats struct {
// http stats
// health indicators of http
}
13 changes: 13 additions & 0 deletions ui/flutter/lib/app/modules/setting/views/setting_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,18 @@ class SettingView extends GetView<SettingController> {
);
}

buildThanks() {
const thankPage =
'https://github.com/GopeedLab/gopeed/graphs/contributors';
return ListTile(
title: Text('thanks'.tr),
subtitle: Text('thanksDesc'.tr),
onTap: () {
launchUrl(Uri.parse(thankPage), mode: LaunchMode.externalApplication);
},
);
}

// advanced config proxy items start
final buildProxy = _buildConfigItem(
'proxy',
Expand Down Expand Up @@ -702,6 +714,7 @@ class SettingView extends GetView<SettingController> {
children: _addDivider([
buildHomepage(),
buildVersion(),
buildThanks(),
]),
)),
]),
Expand Down
3 changes: 3 additions & 0 deletions ui/flutter/lib/i18n/langs/en_us.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,8 @@ const enUS = {
'proxy': 'Proxy',
'username': 'Username',
'password': 'Password',
'thanks': 'Thanks',
'thanksDesc':
'Thanks to all the contributors who have helped build and develop the Gopeed community!',
},
};
3 changes: 3 additions & 0 deletions ui/flutter/lib/i18n/langs/fa_ir.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,8 @@ const faIR = {
'newVersionTitle': '@version عنوان: کشف نسخه جدید',
'newVersionUpdate': 'بروزرسانی',
'newVersionLater': 'بعداً',
'thanks': 'تشکر',
'thanksDesc':
'از تمامی افرادی که در ساخت و توسعه‌ی جامعه‌ی Gopeed مشارکت کرده‌اند، سپاسگزاری می‌کنیم!',
}
};
2 changes: 2 additions & 0 deletions ui/flutter/lib/i18n/langs/ja_jp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,7 @@ const jaJP = {
'newVersionTitle': '新しいバージョン @version を発見する',
'newVersionUpdate': 'アップデート',
'newVersionLater': '後で',
'thanks': '感謝',
'thanksDesc': 'Gopeedコミュニティの建設に協力してくださったすべての貢献者の方々に感謝します!',
}
};
3 changes: 3 additions & 0 deletions ui/flutter/lib/i18n/langs/ru_ru.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,8 @@ const ruRU = {
'history': 'История',
'clearHistory': 'Очистить историю',
'noHistoryFound': 'История не найдена',
'thanks': 'Благодарности',
'thanksDesc':
'Благодарим всех участников за их вклад в строительство и развитие сообщества Gopeed!',
}
};
2 changes: 2 additions & 0 deletions ui/flutter/lib/i18n/langs/zh_cn.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,7 @@ const zhCN = {
'proxy': '代理',
'username': '用户名',
'password': '密码',
'thanks': '鸣谢',
'thanksDesc': '感谢所有为 Gopeed 社区建设添砖加瓦的贡献者们!',
}
};
2 changes: 2 additions & 0 deletions ui/flutter/lib/i18n/langs/zh_tw.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,7 @@ const zhTW = {
'proxy': '代理',
'username': '名稱',
'password': '密碼',
'thanks': '鳴謝',
'thanksDesc': '感謝所有為 Gopeed 社群建設添磚加瓦的貢獻者們!'
}
};

0 comments on commit 1fd9d42

Please sign in to comment.