Skip to content

Commit

Permalink
feat: support creating tasks using gopeed scheme (#876)
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyWie authored Jan 16, 2025
1 parent 987580d commit 83febe0
Show file tree
Hide file tree
Showing 14 changed files with 222 additions and 52 deletions.
2 changes: 2 additions & 0 deletions ui/flutter/lib/api/model/downloader_config.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions ui/flutter/lib/api/model/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class Options {
Object? extra;

Options({
required this.name,
required this.path,
this.name = '',
this.path = '',
this.selectFiles = const [],
this.extra,
});
Expand All @@ -24,12 +24,16 @@ class Options {

@JsonSerializable()
class OptsExtraHttp {
int connections = 0;
bool autoTorrent = false;
int connections;
bool autoTorrent;

OptsExtraHttp();
OptsExtraHttp({
this.connections = 0,
this.autoTorrent = false,
});

factory OptsExtraHttp.fromJson(Map<String, dynamic> json) =>
_$OptsExtraHttpFromJson(json);

Map<String, dynamic> toJson() => _$OptsExtraHttpToJson(this);
}
13 changes: 7 additions & 6 deletions ui/flutter/lib/api/model/options.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 29 additions & 16 deletions ui/flutter/lib/api/model/request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ part 'request.g.dart';
class Request {
String url;
Object? extra;
Map<String, String>? labels = {};
Map<String, String>? labels;
RequestProxy? proxy;
bool skipVerifyCert = false;
bool skipVerifyCert;

Request({
required this.url,
Expand All @@ -26,11 +26,15 @@ class Request {

@JsonSerializable()
class ReqExtraHttp {
String method = 'GET';
Map<String, String> header = {};
String body = '';

ReqExtraHttp();
String method;
Map<String, String> header;
String body;

ReqExtraHttp({
this.method = 'GET',
this.header = const {},
this.body = '',
});

factory ReqExtraHttp.fromJson(Map<String, dynamic> json) =>
_$ReqExtraHttpFromJson(json);
Expand All @@ -40,9 +44,11 @@ class ReqExtraHttp {

@JsonSerializable()
class ReqExtraBt {
List<String> trackers = [];
List<String> trackers;

ReqExtraBt();
ReqExtraBt({
this.trackers = const [],
});

factory ReqExtraBt.fromJson(Map<String, dynamic> json) =>
_$ReqExtraBtFromJson(json);
Expand All @@ -58,15 +64,22 @@ enum RequestProxyMode {

@JsonSerializable()
class RequestProxy {
RequestProxyMode mode = RequestProxyMode.follow;
String scheme = 'http';
String host = '';
String usr = '';
String pwd = '';

RequestProxy();
RequestProxyMode mode;
String scheme;
String host;
String usr;
String pwd;

RequestProxy({
this.mode = RequestProxyMode.follow,
this.scheme = 'http',
this.host = '',
this.usr = '',
this.pwd = '',
});

factory RequestProxy.fromJson(Map<String, dynamic> json) =>
_$RequestProxyFromJson(json);

Map<String, dynamic> toJson() => _$RequestProxyToJson(this);
}
35 changes: 22 additions & 13 deletions ui/flutter/lib/api/model/request.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ui/flutter/lib/api/model/result.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 18 additions & 2 deletions ui/flutter/lib/app/modules/app/controllers/app_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:window_manager/window_manager.dart';

import '../../../../api/api.dart';
import '../../../../api/model/downloader_config.dart';
import '../../../../api/model/request.dart';
import '../../../../core/common/start_config.dart';
import '../../../../core/libgopeed_boot.dart';
import '../../../../database/database.dart';
Expand All @@ -27,6 +28,8 @@ import '../../../../util/log_util.dart';
import '../../../../util/package_info.dart';
import '../../../../util/util.dart';
import '../../../routes/app_pages.dart';
import '../../create/controllers/create_controller.dart';
import '../../create/dto/create_router_params.dart';
import '../../redirect/views/redirect_view.dart';

const unixSocketPath = 'gopeed.sock';
Expand Down Expand Up @@ -305,8 +308,20 @@ class AppController extends GetxController with WindowListener, TrayListener {
}

Future<void> _handleDeepLink(Uri uri) async {
// Wake up application only
if (uri.scheme == "gopeed") {
if (uri.path == "/create") {
final params = uri.queryParameters["params"];
if (params?.isNotEmpty == true) {
final paramsJson = String.fromCharCodes(base64Decode(params!));
Get.rootDelegate.offAndToNamed(Routes.REDIRECT,
arguments: RedirectArgs(Routes.CREATE,
arguments:
CreateRouterParams.fromJson(jsonDecode(paramsJson))));
return;
}
Get.rootDelegate.offAndToNamed(Routes.CREATE);
return;
}
Get.rootDelegate.offAndToNamed(Routes.HOME);
return;
}
Expand All @@ -322,7 +337,8 @@ class AppController extends GetxController with WindowListener, TrayListener {
path = (await toFile(uri.toString())).path;
}
Get.rootDelegate.offAndToNamed(Routes.REDIRECT,
arguments: RedirectArgs(Routes.CREATE, arguments: path));
arguments: RedirectArgs(Routes.CREATE,
arguments: CreateRouterParams(req: Request(url: path))));
}

String runningAddress() {
Expand Down
24 changes: 24 additions & 0 deletions ui/flutter/lib/app/modules/create/dto/create_router_params.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:json_annotation/json_annotation.dart';

import '../../../../api/model/options.dart';
import '../../../../api/model/request.dart';

part 'create_router_params.g.dart';

@JsonSerializable(explicitToJson: true)
class CreateRouterParams {
Request? req;
Options? opt;

CreateRouterParams({
this.req,
this.opt,
});

factory CreateRouterParams.fromJson(
Map<String, dynamic> json,
) =>
_$CreateRouterParamsFromJson(json);

Map<String, dynamic> toJson() => _$CreateRouterParamsToJson(this);
}
31 changes: 31 additions & 0 deletions ui/flutter/lib/app/modules/create/dto/create_router_params.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 83febe0

Please sign in to comment.