Compare commits

...
8 Commits
17 changed files with 824 additions and 148 deletions

No files matched your search

+2 -8
View File
@@ -258,19 +258,14 @@ jobs:
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:
matrix: matrix:
os: [ubuntu-22.04, ubuntu-22.04-arm] os: [ubuntu-24.04, ubuntu-24.04-arm]
needs: [get-release] needs: [get-release]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: actions/setup-go@v4 - uses: actions/setup-go@v4
with: with:
go-version: ${{ env.GO_VERSION }} go-version: ${{ env.GO_VERSION }}
- if: matrix.os == 'ubuntu-22.04' - uses: subosito/flutter-action@v2
uses: subosito/flutter-action@v2
with:
flutter-version: ${{ env.FLUTTER_VERSION }}
- if: matrix.os == 'ubuntu-22.04-arm'
uses: subosito/flutter-action@v2
with: with:
flutter-version: ${{ env.FLUTTER_VERSION }} flutter-version: ${{ env.FLUTTER_VERSION }}
channel: master channel: master
@@ -282,7 +277,6 @@ jobs:
sudo apt install -y libfuse2 locate sudo apt install -y libfuse2 locate
arch=$(uname -m) arch=$(uname -m)
wget -O appimagetool "https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-${arch}.AppImage" wget -O appimagetool "https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-${arch}.AppImage"
wget -O appimagetool "https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-${arch}.AppImage"
chmod +x appimagetool chmod +x appimagetool
sudo mv appimagetool /usr/local/bin/ sudo mv appimagetool /usr/local/bin/
- name: Build - name: Build
+1 -1
View File
@@ -69,7 +69,7 @@ jobs:
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:
matrix: matrix:
os: [windows-latest, macos-latest, ubuntu-22.04, ubuntu-22.04-arm] os: [windows-latest, macos-latest, ubuntu-24.04, ubuntu-24.04-arm]
needs: [test] needs: [test]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
+30 -34
View File
@@ -34,17 +34,17 @@ func parse() *args {
loadEnvVars(cfg) loadEnvVars(cfg)
// override with non-default command line arguments // override with non-default command line arguments
overrideWithCliArgs(cfg, cliConfig) overrideWithCliArgs(cfg, cliConfig)
// set default values for any unset fields // set default values
setDefaults(cfg) setDefaults(cfg, cliConfig)
return cfg return cfg
} }
// loadCliArgs parses command line arguments and returns initial config // loadCliArgs parses command line arguments and returns initial config
func loadCliArgs() *args { func loadCliArgs() *args {
cfg := &args{} cfg := &args{}
cfg.Address = flag.String("A", "", "Bind Address") cfg.Address = flag.String("A", "0.0.0.0", "Bind Address")
cfg.Port = flag.Int("P", 0, "Bind Port") cfg.Port = flag.Int("P", 9999, "Bind Port")
cfg.Username = flag.String("u", "", "Web Authentication Username") cfg.Username = flag.String("u", "gopeed", "Web Authentication Username")
cfg.Password = flag.String("p", "", "Web Authentication Password, if no password is set, web authentication will not be enabled") cfg.Password = flag.String("p", "", "Web Authentication Password, if no password is set, web authentication will not be enabled")
cfg.ApiToken = flag.String("T", "", "API token, it must be configured when using HTTP API in the case of enabling web authentication") cfg.ApiToken = flag.String("T", "", "API token, it must be configured when using HTTP API in the case of enabling web authentication")
cfg.StorageDir = flag.String("d", "", "Storage directory") cfg.StorageDir = flag.String("d", "", "Storage directory")
@@ -66,51 +66,47 @@ func loadCliArgs() *args {
// overrideWithCliArgs overrides config with non-empty command line arguments // overrideWithCliArgs overrides config with non-empty command line arguments
func overrideWithCliArgs(cfg *args, cliConfig *args) { func overrideWithCliArgs(cfg *args, cliConfig *args) {
// Only override if the cli value is not empty/zero flag.Visit(func(f *flag.Flag) {
if cliConfig.Address != nil && *cliConfig.Address != "" { switch f.Name {
case "A":
cfg.Address = cliConfig.Address cfg.Address = cliConfig.Address
} case "P":
if cliConfig.Port != nil && *cliConfig.Port != 0 {
cfg.Port = cliConfig.Port cfg.Port = cliConfig.Port
} case "u":
if cliConfig.Username != nil && *cliConfig.Username != "" {
cfg.Username = cliConfig.Username cfg.Username = cliConfig.Username
} case "p":
if cliConfig.Password != nil && *cliConfig.Password != "" {
cfg.Password = cliConfig.Password cfg.Password = cliConfig.Password
} case "T":
if cliConfig.ApiToken != nil && *cliConfig.ApiToken != "" {
cfg.ApiToken = cliConfig.ApiToken cfg.ApiToken = cliConfig.ApiToken
} case "d":
if cliConfig.StorageDir != nil && *cliConfig.StorageDir != "" {
cfg.StorageDir = cliConfig.StorageDir cfg.StorageDir = cliConfig.StorageDir
} case "w":
if cliConfig.WhiteDownloadDirs != nil {
cfg.WhiteDownloadDirs = cliConfig.WhiteDownloadDirs cfg.WhiteDownloadDirs = cliConfig.WhiteDownloadDirs
case "c":
cfg.configPath = cliConfig.configPath
} }
})
} }
// setDefaults sets default values for any unset configuration fields // setDefaults sets default values for any unset configuration fields
func setDefaults(cfg *args) { func setDefaults(cfg *args, cliConfig *args) {
if cfg.Address == nil { if cfg.Address == nil {
address := "0.0.0.0" cfg.Address = cliConfig.Address
cfg.Address = &address
} }
if cfg.Port == nil { if cfg.Port == nil {
port := 9999 cfg.Port = cliConfig.Port
cfg.Port = &port
} }
if cfg.Username == nil { if cfg.Username == nil {
username := "gopeed" cfg.Username = cliConfig.Username
cfg.Username = &username }
if cfg.Password == nil {
cfg.Password = cliConfig.Password
}
if cfg.ApiToken == nil {
cfg.ApiToken = cliConfig.ApiToken
}
if cfg.StorageDir == nil {
cfg.StorageDir = cliConfig.StorageDir
} }
} }
+708 -92
View File
File diff suppressed because it is too large. Load diff
+1 -1
View File
@@ -34,7 +34,7 @@ func newFileOpts(opts newFileClientOpts) storage.ClientImplCloser {
if opts.FilePathMaker == nil { if opts.FilePathMaker == nil {
opts.FilePathMaker = func(opts storage.FilePathMakerOpts) string { opts.FilePathMaker = func(opts storage.FilePathMakerOpts) string {
var parts []string var parts []string
if opts.Info.Name != metainfo.NoName { if opts.Info.Length == 0 {
parts = append(parts, opts.Info.Name) parts = append(parts, opts.Info.Name)
} }
return filepath.Join(append(parts, opts.File.Path...)...) return filepath.Join(append(parts, opts.File.Path...)...)
+3 -2
View File
@@ -23,6 +23,7 @@ import (
"github.com/GopeedLab/gopeed/internal/fetcher" "github.com/GopeedLab/gopeed/internal/fetcher"
"github.com/GopeedLab/gopeed/pkg/base" "github.com/GopeedLab/gopeed/pkg/base"
fhttp "github.com/GopeedLab/gopeed/pkg/protocol/http" fhttp "github.com/GopeedLab/gopeed/pkg/protocol/http"
"github.com/GopeedLab/gopeed/pkg/util"
"github.com/xiaoqidun/setft" "github.com/xiaoqidun/setft"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
) )
@@ -172,13 +173,13 @@ func (f *Fetcher) Resolve(req *base.Request) error {
filename = strings.Replace(filename, "UTF8", "UTF-8", 1) filename = strings.Replace(filename, "UTF8", "UTF-8", 1)
file.Name, _ = decoder.Decode(filename) file.Name, _ = decoder.Decode(filename)
} else { } else {
file.Name = filename file.Name = util.TryUrlQueryUnescape(filename)
} }
} else { } else {
substr := "attachment; filename=" substr := "attachment; filename="
index := strings.Index(contentDisposition, substr) index := strings.Index(contentDisposition, substr)
if index != -1 { if index != -1 {
file.Name = contentDisposition[index+len(substr):] file.Name = util.TryUrlQueryUnescape(contentDisposition[index+len(substr):])
} }
} }
} }
+4 -2
View File
@@ -65,7 +65,9 @@ func Stop() {
}() }()
if srv != nil { if srv != nil {
if err := srv.Shutdown(context.TODO()); err != nil { shutdownCtx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
if err := srv.Shutdown(shutdownCtx); err != nil {
Downloader.Logger.Warn().Err(err).Msg("shutdown server failed") Downloader.Logger.Warn().Err(err).Msg("shutdown server failed")
} }
} }
@@ -191,7 +193,7 @@ func BuildServer(startCfg *model.StartConfig) (*http.Server, net.Listener, error
} }
if enableBasicAuth { if enableBasicAuth {
if r.URL.Path == "/api/web/login" { if !strings.HasPrefix(r.URL.Path, "/api/") || r.URL.Path == "/api/web/login" {
h.ServeHTTP(w, r) h.ServeHTTP(w, r)
return return
} }
+10
View File
@@ -56,3 +56,13 @@ func ProxyUrlToHandler(proxyUrl *url.URL) func(*http.Request) (*url.URL, error)
} }
return http.ProxyURL(proxyUrl) return http.ProxyURL(proxyUrl)
} }
// TryUrlQueryUnescape tries to unescape a URL-encoded string.
//
// If unescaping fails, it returns the original string.
func TryUrlQueryUnescape(s string) string {
if decoded, err := url.QueryUnescape(s); err == nil {
return decoded
}
return s
}
+21
View File
@@ -128,3 +128,24 @@ func TestParseDataUri(t *testing.T) {
}) })
} }
} }
func TestTryURLDecode(t *testing.T) {
tests := []struct {
input string
expected string
}{
{"normal.txt", "normal.txt"},
{"%E7%8F%80%E5%B0%94%E8%AF%BA.zip", "珀尔诺.zip"},
{"hello%20world.txt", "hello world.txt"},
{"bad%2-text", "bad%2-text"},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
got := TryUrlQueryUnescape(tt.input)
if got != tt.expected {
t.Errorf("TryUrlQueryUnescape(%q) = %q, want %q", tt.input, got, tt.expected)
}
})
}
}
@@ -81,6 +81,7 @@ class ExtraConfig {
bool lastDeleteTaskKeep; bool lastDeleteTaskKeep;
bool defaultDirectDownload; bool defaultDirectDownload;
bool defaultBtClient; bool defaultBtClient;
bool notifyWhenNewVersion;
ExtraConfigBt bt = ExtraConfigBt(); ExtraConfigBt bt = ExtraConfigBt();
@@ -90,6 +91,7 @@ class ExtraConfig {
this.lastDeleteTaskKeep = false, this.lastDeleteTaskKeep = false,
this.defaultDirectDownload = false, this.defaultDirectDownload = false,
this.defaultBtClient = true, this.defaultBtClient = true,
this.notifyWhenNewVersion = true,
}); });
factory ExtraConfig.fromJson(Map<String, dynamic>? json) => factory ExtraConfig.fromJson(Map<String, dynamic>? json) =>
@@ -74,6 +74,7 @@ ExtraConfig _$ExtraConfigFromJson(Map<String, dynamic> json) => ExtraConfig(
lastDeleteTaskKeep: json['lastDeleteTaskKeep'] as bool? ?? false, lastDeleteTaskKeep: json['lastDeleteTaskKeep'] as bool? ?? false,
defaultDirectDownload: json['defaultDirectDownload'] as bool? ?? false, defaultDirectDownload: json['defaultDirectDownload'] as bool? ?? false,
defaultBtClient: json['defaultBtClient'] as bool? ?? true, defaultBtClient: json['defaultBtClient'] as bool? ?? true,
notifyWhenNewVersion: json['notifyWhenNewVersion'] as bool? ?? true,
)..bt = ExtraConfigBt.fromJson(json['bt'] as Map<String, dynamic>); )..bt = ExtraConfigBt.fromJson(json['bt'] as Map<String, dynamic>);
Map<String, dynamic> _$ExtraConfigToJson(ExtraConfig instance) => Map<String, dynamic> _$ExtraConfigToJson(ExtraConfig instance) =>
@@ -83,6 +84,7 @@ Map<String, dynamic> _$ExtraConfigToJson(ExtraConfig instance) =>
'lastDeleteTaskKeep': instance.lastDeleteTaskKeep, 'lastDeleteTaskKeep': instance.lastDeleteTaskKeep,
'defaultDirectDownload': instance.defaultDirectDownload, 'defaultDirectDownload': instance.defaultDirectDownload,
'defaultBtClient': instance.defaultBtClient, 'defaultBtClient': instance.defaultBtClient,
'notifyWhenNewVersion': instance.notifyWhenNewVersion,
'bt': instance.bt.toJson(), 'bt': instance.bt.toJson(),
}; };
@@ -119,7 +119,7 @@ class AppController extends GetxController with WindowListener, TrayListener {
@override @override
void onTrayIconRightMouseDown() { void onTrayIconRightMouseDown() {
trayManager.popUpContextMenu(); trayManager.popUpContextMenu(bringAppToFront: true);
} }
@override @override
@@ -506,6 +506,11 @@ class AppController extends GetxController with WindowListener, TrayListener {
} }
Future<void> _initCheckUpdate() async { Future<void> _initCheckUpdate() async {
// Check if auto check update is enabled
if (!downloaderConfig.value.extra.notifyWhenNewVersion) {
return;
}
final versionInfo = await checkUpdate(); final versionInfo = await checkUpdate();
if (versionInfo != null) { if (versionInfo != null) {
await showUpdateDialog(Get.context!, versionInfo); await showUpdateDialog(Get.context!, versionInfo);
@@ -531,6 +531,25 @@ class SettingView extends GetView<SettingController> {
); );
} }
final buildAutoCheckUpdate = _buildConfigItem(
'notifyWhenNewVersion',
() =>
downloaderCfg.value.extra.notifyWhenNewVersion ? 'on'.tr : 'off'.tr,
(Key key) {
return Container(
alignment: Alignment.centerLeft,
child: Switch(
value: downloaderCfg.value.extra.notifyWhenNewVersion,
onChanged: (bool value) async {
downloaderCfg.update((val) {
val!.extra.notifyWhenNewVersion = value;
});
await debounceSave();
},
),
);
});
buildThanks() { buildThanks() {
const thankPage = const thankPage =
'https://github.com/GopeedLab/gopeed/graphs/contributors'; 'https://github.com/GopeedLab/gopeed/graphs/contributors';
@@ -957,6 +976,7 @@ class SettingView extends GetView<SettingController> {
children: _addDivider([ children: _addDivider([
buildHomepage(), buildHomepage(),
buildVersion(), buildVersion(),
buildAutoCheckUpdate(),
buildThanks(), buildThanks(),
]), ]),
)), )),
+1
View File
@@ -52,6 +52,7 @@ const enUS = {
'themeLight': 'Light', 'themeLight': 'Light',
'themeDark': 'Dark', 'themeDark': 'Dark',
'locale': 'Language', 'locale': 'Language',
'notifyWhenNewVersion': 'Notify for updates',
'about': 'About', 'about': 'About',
'homepage': 'Homepage', 'homepage': 'Homepage',
'version': 'Version', 'version': 'Version',
+1
View File
@@ -51,6 +51,7 @@ const zhCN = {
'themeLight': '明亮主题', 'themeLight': '明亮主题',
'themeDark': '暗黑主题', 'themeDark': '暗黑主题',
'locale': '语言', 'locale': '语言',
'notifyWhenNewVersion': '有新版本时提醒',
'about': '关于', 'about': '关于',
'homepage': '主页', 'homepage': '主页',
'version': '版本', 'version': '版本',
+6 -5
View File
@@ -1252,11 +1252,12 @@ packages:
tray_manager: tray_manager:
dependency: "direct main" dependency: "direct main"
description: description:
name: tray_manager path: "packages/tray_manager"
sha256: bdc3ac6c36f3d12d871459e4a9822705ce5a1165a17fa837103bc842719bf3f7 ref: main
url: "https://pub.dev" resolved-ref: "91cdbdc12517d0d832aca715542b9d0329739d5d"
source: hosted url: "https://github.com/monkeyWie/tray_manager.git"
version: "0.2.4" source: git
version: "0.5.1"
typed_data: typed_data:
dependency: transitive dependency: transitive
description: description:
+6 -2
View File
@@ -15,7 +15,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at # Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.8.0+1 version: 1.8.1+1
environment: environment:
sdk: ">=3.0.0 <4.0.0" sdk: ">=3.0.0 <4.0.0"
@@ -58,7 +58,11 @@ dependencies:
form_builder_validators: ^11.0.0 form_builder_validators: ^11.0.0
flutter_foreground_task: ^8.2.0 flutter_foreground_task: ^8.2.0
open_filex: ^4.5.0 open_filex: ^4.5.0
tray_manager: ^0.2.4 tray_manager:
git:
url: https://github.com/monkeyWie/tray_manager.git
ref: main
path: packages/tray_manager
lecle_downloads_path_provider: ^0.0.2+8 lecle_downloads_path_provider: ^0.0.2+8
hive: ^2.2.3 hive: ^2.2.3
launch_at_startup: ^0.3.1 launch_at_startup: ^0.3.1