mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-18 14:23:42 +00:00
feat: new ui (#1455)
This commit is contained in:
742 files changed
+59951
-5934
No files matched your search
@@ -0,0 +1,310 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:dio/io.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:get/get.dart' as getx;
|
||||
|
||||
import '../app/routes/app_pages.dart';
|
||||
import '../database/database.dart';
|
||||
import '../util/util.dart';
|
||||
import 'model/create_task.dart';
|
||||
import 'model/create_task_batch.dart';
|
||||
import 'model/downloader_config.dart';
|
||||
import 'model/extension.dart';
|
||||
import 'model/install_extension.dart';
|
||||
import 'model/login.dart';
|
||||
import 'model/resolve_result.dart';
|
||||
import 'model/resolve_task.dart';
|
||||
import 'model/result.dart';
|
||||
import 'model/switch_extension.dart';
|
||||
import 'model/task.dart';
|
||||
import 'model/update_check_extension_resp.dart';
|
||||
import 'model/update_extension_settings.dart';
|
||||
|
||||
class _Client {
|
||||
static _Client? _instance;
|
||||
|
||||
late Dio dio;
|
||||
|
||||
_Client._internal();
|
||||
|
||||
factory _Client(String network, String address, String apiToken) {
|
||||
if (_instance == null) {
|
||||
_instance = _Client._internal();
|
||||
var dio = Dio();
|
||||
final isUnixSocket = network == 'unix';
|
||||
var baseUrl = 'http://127.0.0.1/';
|
||||
if (!isUnixSocket) {
|
||||
if (Util.isWeb()) {
|
||||
baseUrl = kDebugMode ? 'http://127.0.0.1:9999/' : '';
|
||||
} else {
|
||||
baseUrl = 'http://$address/';
|
||||
}
|
||||
}
|
||||
dio.options.baseUrl = baseUrl;
|
||||
dio.options.contentType = Headers.jsonContentType;
|
||||
dio.options.sendTimeout = const Duration(seconds: 5);
|
||||
dio.options.connectTimeout = const Duration(seconds: 5);
|
||||
dio.options.receiveTimeout = const Duration(seconds: 120);
|
||||
dio.interceptors.add(InterceptorsWrapper(
|
||||
onRequest: (options, handler) {
|
||||
if (apiToken.isNotEmpty) {
|
||||
options.headers['X-Api-Token'] = apiToken;
|
||||
}
|
||||
if (Util.isWeb()) {
|
||||
final token = Database.instance.getWebToken();
|
||||
if (token != null) {
|
||||
options.headers['Authorization'] = 'Bearer $token';
|
||||
}
|
||||
}
|
||||
handler.next(options);
|
||||
},
|
||||
onError: (error, handler) {
|
||||
// Only web version has a login page
|
||||
if (Util.isWeb() && error.response?.statusCode == 401) {
|
||||
getx.Get.rootDelegate.offAndToNamed(Routes.LOGIN);
|
||||
}
|
||||
handler.next(error);
|
||||
},
|
||||
));
|
||||
|
||||
_instance!.dio = dio;
|
||||
if (isUnixSocket) {
|
||||
(_instance!.dio.httpClientAdapter as IOHttpClientAdapter)
|
||||
.createHttpClient = () {
|
||||
final client = HttpClient();
|
||||
client.connectionFactory =
|
||||
(Uri uri, String? proxyHost, int? proxyPort) {
|
||||
return Socket.startConnect(
|
||||
InternetAddress(address, type: InternetAddressType.unix), 0);
|
||||
};
|
||||
return client;
|
||||
};
|
||||
}
|
||||
}
|
||||
return _instance!;
|
||||
}
|
||||
}
|
||||
|
||||
class TimeoutException implements Exception {
|
||||
final String message;
|
||||
|
||||
TimeoutException(this.message);
|
||||
}
|
||||
|
||||
late _Client _client;
|
||||
|
||||
void init(String network, String address, String apiToken) {
|
||||
_client = _Client(network, address, apiToken);
|
||||
}
|
||||
|
||||
/// Used by LocationKeepAliveCoordinator to reconcile keep-alive
|
||||
void Function()? _onTaskChanged;
|
||||
|
||||
void setTaskChangedListener(void Function() listener) {
|
||||
_onTaskChanged = listener;
|
||||
}
|
||||
|
||||
void _notifyTaskChanged() {
|
||||
_onTaskChanged?.call();
|
||||
}
|
||||
|
||||
Future<T> _parse<T>(
|
||||
Future<Response> Function() fetch,
|
||||
T Function(dynamic json)? fromJsonT,
|
||||
) async {
|
||||
try {
|
||||
var resp = await fetch();
|
||||
fromJsonT ??= (json) => null as T;
|
||||
final result = Result<T>.fromJson(resp.data, fromJsonT);
|
||||
if (result.code == 0) {
|
||||
return result.data as T;
|
||||
} else {
|
||||
throw Exception(result);
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
if (e.type == DioExceptionType.sendTimeout ||
|
||||
e.type == DioExceptionType.receiveTimeout ||
|
||||
e.type == DioExceptionType.connectionTimeout ||
|
||||
e.type == DioExceptionType.connectionError) {
|
||||
throw TimeoutException("request timeout");
|
||||
}
|
||||
throw Exception(Result(code: 1000, msg: e.message));
|
||||
}
|
||||
}
|
||||
|
||||
Future<ResolveResult> resolve(ResolveTask resolveTask) async {
|
||||
return _parse<ResolveResult>(
|
||||
() => _client.dio.post("api/v1/resolve", data: resolveTask),
|
||||
(data) => ResolveResult.fromJson(data));
|
||||
}
|
||||
|
||||
Future<String> createTask(CreateTask createTask) async {
|
||||
final result = await _parse<String>(
|
||||
() => _client.dio.post("api/v1/tasks", data: createTask),
|
||||
(data) => data as String);
|
||||
_notifyTaskChanged();
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<List<String>> createTaskBatch(CreateTaskBatch createTaskBatch) async {
|
||||
final result = await _parse<List<String>>(
|
||||
() => _client.dio.post("api/v1/tasks/batch", data: createTaskBatch),
|
||||
(data) => (data as List).map((e) => e as String).toList());
|
||||
_notifyTaskChanged();
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<void> patchTask(String id, ResolveTask patchTask) async {
|
||||
return _parse(
|
||||
() => _client.dio.patch("api/v1/tasks/$id", data: patchTask), null);
|
||||
}
|
||||
|
||||
Future<List<Task>> getTasks(List<Status> statuses) async {
|
||||
return _parse<List<Task>>(
|
||||
() => _client.dio.get(
|
||||
"/api/v1/tasks?${statuses.map((e) => "status=${e.name}").join("&")}"),
|
||||
(data) => (data as List).map((e) => Task.fromJson(e)).toList());
|
||||
}
|
||||
|
||||
Future<void> pauseTask(String id) async {
|
||||
await _parse(() => _client.dio.put("api/v1/tasks/$id/pause"), null);
|
||||
_notifyTaskChanged();
|
||||
}
|
||||
|
||||
Future<void> continueTask(String id) async {
|
||||
await _parse(() => _client.dio.put("api/v1/tasks/$id/continue"), null);
|
||||
_notifyTaskChanged();
|
||||
}
|
||||
|
||||
Future<void> pauseAllTasks(List<String>? ids) async {
|
||||
await _parse(
|
||||
() => _client.dio.put("api/v1/tasks/pause", queryParameters: {
|
||||
"id": ids,
|
||||
}),
|
||||
null);
|
||||
_notifyTaskChanged();
|
||||
}
|
||||
|
||||
Future<void> continueAllTasks(List<String>? ids) async {
|
||||
await _parse(
|
||||
() => _client.dio.put("api/v1/tasks/continue", queryParameters: {
|
||||
"id": ids,
|
||||
}),
|
||||
null);
|
||||
_notifyTaskChanged();
|
||||
}
|
||||
|
||||
Future<void> deleteTask(String id, bool force) async {
|
||||
await _parse(
|
||||
() => _client.dio.delete("api/v1/tasks/$id?force=$force"), null);
|
||||
_notifyTaskChanged();
|
||||
}
|
||||
|
||||
Future<void> deleteTasks(List<String>? ids, bool force) async {
|
||||
await _parse(
|
||||
() => _client.dio.delete("api/v1/tasks", queryParameters: {
|
||||
"id": ids,
|
||||
"force": force,
|
||||
}),
|
||||
null);
|
||||
_notifyTaskChanged();
|
||||
}
|
||||
|
||||
Future<DownloaderConfig> getConfig() async {
|
||||
return _parse(() => _client.dio.get("api/v1/config"),
|
||||
(data) => DownloaderConfig.fromJson(data));
|
||||
}
|
||||
|
||||
Future<void> putConfig(DownloaderConfig config) async {
|
||||
return _parse(() => _client.dio.put("api/v1/config", data: config), null);
|
||||
}
|
||||
|
||||
Future<String> installExtension(InstallExtension installExtension) async {
|
||||
return _parse<String>(
|
||||
() => _client.dio.post("api/v1/extensions", data: installExtension),
|
||||
(data) => data as String);
|
||||
}
|
||||
|
||||
Future<List<Extension>> getExtensions() async {
|
||||
return _parse<List<Extension>>(() => _client.dio.get("api/v1/extensions"),
|
||||
(data) => (data as List).map((e) => Extension.fromJson(e)).toList());
|
||||
}
|
||||
|
||||
Future<void> updateExtensionSettings(
|
||||
String identity, UpdateExtensionSettings updateExtensionSettings) async {
|
||||
return _parse(
|
||||
() => _client.dio.put("api/v1/extensions/$identity/settings",
|
||||
data: updateExtensionSettings),
|
||||
null);
|
||||
}
|
||||
|
||||
Future<void> switchExtension(
|
||||
String identity, SwitchExtension switchExtension) async {
|
||||
return _parse(
|
||||
() => _client.dio
|
||||
.put("api/v1/extensions/$identity/switch", data: switchExtension),
|
||||
null);
|
||||
}
|
||||
|
||||
Future<void> deleteExtension(String identity) async {
|
||||
return _parse(() => _client.dio.delete("api/v1/extensions/$identity"), null);
|
||||
}
|
||||
|
||||
Future<UpdateCheckExtensionResp> upgradeCheckExtension(String identity) async {
|
||||
return _parse(() => _client.dio.get("api/v1/extensions/$identity/update"),
|
||||
(data) => UpdateCheckExtensionResp.fromJson(data));
|
||||
}
|
||||
|
||||
Future<void> updateExtension(String identity) async {
|
||||
return _parse(
|
||||
() => _client.dio.post("api/v1/extensions/$identity/update"), null);
|
||||
}
|
||||
|
||||
Future<void> testWebhook(String url) async {
|
||||
return _parse(
|
||||
() => _client.dio.post("api/v1/webhook/test", data: {"url": url}), null);
|
||||
}
|
||||
|
||||
Future<String> login(LoginReq loginReq) async {
|
||||
return _parse(() => _client.dio.post("api/web/login", data: loginReq),
|
||||
(data) => data as String);
|
||||
}
|
||||
|
||||
Future<Response<String>> proxyRequest<T>(String uri,
|
||||
{data, Options? options}) async {
|
||||
options ??= Options();
|
||||
options.headers ??= {};
|
||||
options.headers!["X-Target-Uri"] = uri;
|
||||
|
||||
// add timestamp to avoid cache
|
||||
return _client.dio.request(
|
||||
"/api/v1/proxy?t=${DateTime.now().millisecondsSinceEpoch}",
|
||||
data: data,
|
||||
options: options);
|
||||
}
|
||||
|
||||
String join(String path) {
|
||||
final baseUrl = _client.dio.options.baseUrl;
|
||||
final cleanBaseUrl = baseUrl.endsWith('/')
|
||||
? baseUrl.substring(0, baseUrl.length - 1)
|
||||
: baseUrl;
|
||||
return "$cleanBaseUrl/${Util.cleanPath(path)}";
|
||||
}
|
||||
|
||||
/// Generic request method for API proxy
|
||||
/// Directly forwards requests to gopeed REST API
|
||||
Future<Response> forward(
|
||||
String path, {
|
||||
String method = 'GET',
|
||||
dynamic data,
|
||||
Map<String, dynamic>? queryParameters,
|
||||
}) async {
|
||||
return _client.dio.request(
|
||||
path,
|
||||
data: data,
|
||||
queryParameters: queryParameters,
|
||||
options: Options(method: method),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import 'api.dart';
|
||||
import 'model/store_extension.dart';
|
||||
|
||||
class GopeedSiteApi {
|
||||
GopeedSiteApi._();
|
||||
|
||||
static final instance = GopeedSiteApi._();
|
||||
|
||||
static const _host = 'gopeed.com';
|
||||
|
||||
Future<Map<String, dynamic>> getRelease() async {
|
||||
final json = await _getJson('/api/release');
|
||||
return json as Map<String, dynamic>;
|
||||
}
|
||||
|
||||
Future<StoreExtensionPage> getExtensions({
|
||||
int page = 1,
|
||||
int limit = 20,
|
||||
StoreExtensionSort sort = StoreExtensionSort.stars,
|
||||
StoreSortOrder order = StoreSortOrder.desc,
|
||||
String? query,
|
||||
}) async {
|
||||
final json = await _getJson('/api/extensions', queryParameters: {
|
||||
'page': page.toString(),
|
||||
'limit': limit.clamp(1, 100).toString(),
|
||||
'sort': sort.name,
|
||||
'order': order.name,
|
||||
if (query != null && query.trim().isNotEmpty) 'q': query.trim(),
|
||||
});
|
||||
return StoreExtensionPage.fromJson(json as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
Future<void> reportExtensionInstall(String id) async {
|
||||
final uri = Uri.https(_host, '/api/extensions/install');
|
||||
await proxyRequest(
|
||||
uri.toString(),
|
||||
data: {'id': id},
|
||||
options: Options(method: 'POST', contentType: Headers.jsonContentType),
|
||||
);
|
||||
}
|
||||
|
||||
Future<dynamic> _getJson(String path,
|
||||
{Map<String, String>? queryParameters}) async {
|
||||
final uri = Uri.https(_host, path, queryParameters);
|
||||
final Response<String> response = await proxyRequest(uri.toString());
|
||||
if (response.data == null || response.data!.isEmpty) {
|
||||
throw Exception('Empty response from $uri');
|
||||
}
|
||||
return jsonDecode(response.data!);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'options.dart';
|
||||
import 'request.dart';
|
||||
|
||||
part 'create_task.g.dart';
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class CreateTask {
|
||||
String? rid;
|
||||
Request? req;
|
||||
Options? opts;
|
||||
|
||||
CreateTask({
|
||||
this.rid,
|
||||
this.req,
|
||||
this.opts,
|
||||
});
|
||||
|
||||
factory CreateTask.fromJson(
|
||||
Map<String, dynamic> json,
|
||||
) =>
|
||||
_$CreateTaskFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$CreateTaskToJson(this);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'create_task.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
CreateTask _$CreateTaskFromJson(Map<String, dynamic> json) => CreateTask(
|
||||
rid: json['rid'] as String?,
|
||||
req: json['req'] == null
|
||||
? null
|
||||
: Request.fromJson(json['req'] as Map<String, dynamic>),
|
||||
opts: json['opts'] == null
|
||||
? null
|
||||
: Options.fromJson(json['opts'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$CreateTaskToJson(CreateTask instance) {
|
||||
final val = <String, dynamic>{};
|
||||
|
||||
void writeNotNull(String key, dynamic value) {
|
||||
if (value != null) {
|
||||
val[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
writeNotNull('rid', instance.rid);
|
||||
writeNotNull('req', instance.req?.toJson());
|
||||
writeNotNull('opts', instance.opts?.toJson());
|
||||
return val;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'options.dart';
|
||||
import 'request.dart';
|
||||
|
||||
part 'create_task_batch.g.dart';
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class CreateTaskBatch {
|
||||
List<CreateTaskBatchItem>? reqs;
|
||||
Options? opts;
|
||||
|
||||
CreateTaskBatch({
|
||||
this.reqs,
|
||||
this.opts,
|
||||
});
|
||||
|
||||
factory CreateTaskBatch.fromJson(
|
||||
Map<String, dynamic> json,
|
||||
) =>
|
||||
_$CreateTaskBatchFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$CreateTaskBatchToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class CreateTaskBatchItem {
|
||||
Request? req;
|
||||
Options? opts;
|
||||
|
||||
CreateTaskBatchItem({
|
||||
this.req,
|
||||
this.opts,
|
||||
});
|
||||
|
||||
factory CreateTaskBatchItem.fromJson(Map<String, dynamic> json) =>
|
||||
_$CreateTaskBatchItemFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$CreateTaskBatchItemToJson(this);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'create_task_batch.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
CreateTaskBatch _$CreateTaskBatchFromJson(Map<String, dynamic> json) =>
|
||||
CreateTaskBatch(
|
||||
reqs: (json['reqs'] as List<dynamic>?)
|
||||
?.map((e) => CreateTaskBatchItem.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
opts: json['opts'] == null
|
||||
? null
|
||||
: Options.fromJson(json['opts'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$CreateTaskBatchToJson(CreateTaskBatch instance) {
|
||||
final val = <String, dynamic>{};
|
||||
|
||||
void writeNotNull(String key, dynamic value) {
|
||||
if (value != null) {
|
||||
val[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
writeNotNull('reqs', instance.reqs?.map((e) => e.toJson()).toList());
|
||||
writeNotNull('opts', instance.opts?.toJson());
|
||||
return val;
|
||||
}
|
||||
|
||||
CreateTaskBatchItem _$CreateTaskBatchItemFromJson(Map<String, dynamic> json) =>
|
||||
CreateTaskBatchItem(
|
||||
req: json['req'] == null
|
||||
? null
|
||||
: Request.fromJson(json['req'] as Map<String, dynamic>),
|
||||
opts: json['opts'] == null
|
||||
? null
|
||||
: Options.fromJson(json['opts'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$CreateTaskBatchItemToJson(CreateTaskBatchItem instance) {
|
||||
final val = <String, dynamic>{};
|
||||
|
||||
void writeNotNull(String key, dynamic value) {
|
||||
if (value != null) {
|
||||
val[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
writeNotNull('req', instance.req?.toJson());
|
||||
writeNotNull('opts', instance.opts?.toJson());
|
||||
return val;
|
||||
}
|
||||
@@ -0,0 +1,310 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'downloader_config.g.dart';
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class DownloaderConfig {
|
||||
String downloadDir;
|
||||
int maxRunning;
|
||||
ProtocolConfig protocolConfig = ProtocolConfig();
|
||||
ExtraConfig extra = ExtraConfig();
|
||||
ProxyConfig proxy = ProxyConfig();
|
||||
WebhookConfig webhook = WebhookConfig();
|
||||
ScriptConfig script = ScriptConfig();
|
||||
AutoTorrentConfig autoTorrent = AutoTorrentConfig();
|
||||
ArchiveConfig archive = ArchiveConfig();
|
||||
bool autoStartTasks;
|
||||
bool autoDeleteMissingFileTasks;
|
||||
|
||||
DownloaderConfig({
|
||||
this.downloadDir = '',
|
||||
this.maxRunning = 0,
|
||||
this.autoStartTasks = false,
|
||||
this.autoDeleteMissingFileTasks = false,
|
||||
});
|
||||
|
||||
factory DownloaderConfig.fromJson(Map<String, dynamic> json) =>
|
||||
_$DownloaderConfigFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$DownloaderConfigToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class ProtocolConfig {
|
||||
HttpConfig http = HttpConfig();
|
||||
BtConfig bt = BtConfig();
|
||||
Ed2kConfig ed2k = Ed2kConfig();
|
||||
|
||||
ProtocolConfig();
|
||||
|
||||
factory ProtocolConfig.fromJson(Map<String, dynamic>? json) =>
|
||||
json == null ? ProtocolConfig() : _$ProtocolConfigFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$ProtocolConfigToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class HttpConfig {
|
||||
String userAgent;
|
||||
int connections;
|
||||
bool useServerCtime;
|
||||
|
||||
HttpConfig({
|
||||
this.userAgent = '',
|
||||
this.connections = 0,
|
||||
this.useServerCtime = false,
|
||||
});
|
||||
|
||||
factory HttpConfig.fromJson(Map<String, dynamic> json) =>
|
||||
_$HttpConfigFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$HttpConfigToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class BtConfig {
|
||||
int listenPort;
|
||||
List<String> trackers;
|
||||
bool seedKeep;
|
||||
double seedRatio;
|
||||
int seedTime;
|
||||
|
||||
BtConfig({
|
||||
this.listenPort = 0,
|
||||
this.trackers = const [],
|
||||
this.seedKeep = false,
|
||||
this.seedRatio = 0,
|
||||
this.seedTime = 0,
|
||||
});
|
||||
|
||||
factory BtConfig.fromJson(Map<String, dynamic> json) =>
|
||||
_$BtConfigFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$BtConfigToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class Ed2kConfig {
|
||||
int listenPort;
|
||||
int udpPort;
|
||||
String serverAddr;
|
||||
String serverMet;
|
||||
String nodesDat;
|
||||
|
||||
Ed2kConfig({
|
||||
this.listenPort = 0,
|
||||
this.udpPort = 0,
|
||||
this.serverAddr = '',
|
||||
this.serverMet = '',
|
||||
this.nodesDat = '',
|
||||
});
|
||||
|
||||
factory Ed2kConfig.fromJson(Map<String, dynamic> json) =>
|
||||
_$Ed2kConfigFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$Ed2kConfigToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class ExtraConfig {
|
||||
String themeMode;
|
||||
String locale;
|
||||
bool lastDeleteTaskKeep;
|
||||
bool defaultDirectDownload;
|
||||
bool defaultBtClient;
|
||||
bool notifyWhenNewVersion;
|
||||
bool desktopNotification;
|
||||
bool backgroundLocationKeepAlive;
|
||||
List<DownloadCategory> downloadCategories;
|
||||
|
||||
ExtraConfigBt bt = ExtraConfigBt();
|
||||
ExtraConfigGithubMirror githubMirror = ExtraConfigGithubMirror();
|
||||
|
||||
ExtraConfig({
|
||||
this.themeMode = '',
|
||||
this.locale = '',
|
||||
this.lastDeleteTaskKeep = false,
|
||||
this.defaultDirectDownload = false,
|
||||
this.defaultBtClient = true,
|
||||
this.notifyWhenNewVersion = true,
|
||||
this.desktopNotification = true,
|
||||
this.backgroundLocationKeepAlive = false,
|
||||
this.downloadCategories = const [],
|
||||
});
|
||||
|
||||
factory ExtraConfig.fromJson(Map<String, dynamic>? json) =>
|
||||
json == null ? ExtraConfig() : _$ExtraConfigFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$ExtraConfigToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class DownloadCategory {
|
||||
String name;
|
||||
String path;
|
||||
bool isBuiltIn;
|
||||
String? nameKey; // i18n key for built-in categories (e.g., 'categoryMusic')
|
||||
bool
|
||||
isDeleted; // Mark built-in categories as deleted instead of removing them
|
||||
|
||||
DownloadCategory({
|
||||
required this.name,
|
||||
required this.path,
|
||||
this.isBuiltIn = false,
|
||||
this.nameKey,
|
||||
this.isDeleted = false,
|
||||
});
|
||||
|
||||
factory DownloadCategory.fromJson(Map<String, dynamic> json) =>
|
||||
_$DownloadCategoryFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$DownloadCategoryToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class WebhookConfig {
|
||||
bool enable;
|
||||
List<String> urls;
|
||||
|
||||
WebhookConfig({
|
||||
this.enable = false,
|
||||
this.urls = const [],
|
||||
});
|
||||
|
||||
factory WebhookConfig.fromJson(Map<String, dynamic>? json) =>
|
||||
json == null ? WebhookConfig() : _$WebhookConfigFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$WebhookConfigToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class ScriptConfig {
|
||||
bool enable;
|
||||
List<String> paths;
|
||||
|
||||
ScriptConfig({
|
||||
this.enable = false,
|
||||
this.paths = const [],
|
||||
});
|
||||
|
||||
factory ScriptConfig.fromJson(Map<String, dynamic>? json) =>
|
||||
json == null ? ScriptConfig() : _$ScriptConfigFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$ScriptConfigToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class ProxyConfig {
|
||||
bool enable;
|
||||
bool system;
|
||||
String scheme;
|
||||
String host;
|
||||
String usr;
|
||||
String pwd;
|
||||
|
||||
ProxyConfig({
|
||||
this.enable = false,
|
||||
this.system = false,
|
||||
this.scheme = '',
|
||||
this.host = '',
|
||||
this.usr = '',
|
||||
this.pwd = '',
|
||||
});
|
||||
|
||||
factory ProxyConfig.fromJson(Map<String, dynamic> json) =>
|
||||
_$ProxyConfigFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$ProxyConfigToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class ExtraConfigBt {
|
||||
List<String> trackerSubscribeUrls = [];
|
||||
List<String> subscribeTrackers = [];
|
||||
bool autoUpdateTrackers = true;
|
||||
DateTime? lastTrackerUpdateTime;
|
||||
|
||||
List<String> customTrackers = [];
|
||||
|
||||
ExtraConfigBt();
|
||||
|
||||
factory ExtraConfigBt.fromJson(Map<String, dynamic> json) =>
|
||||
_$ExtraConfigBtFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$ExtraConfigBtToJson(this);
|
||||
}
|
||||
|
||||
enum GithubMirrorType {
|
||||
jsdelivr,
|
||||
ghProxy,
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class GithubMirror {
|
||||
GithubMirrorType type;
|
||||
String url;
|
||||
bool isBuiltIn;
|
||||
bool isDeleted;
|
||||
|
||||
GithubMirror({
|
||||
required this.type,
|
||||
required this.url,
|
||||
this.isBuiltIn = false,
|
||||
this.isDeleted = false,
|
||||
});
|
||||
|
||||
factory GithubMirror.fromJson(Map<String, dynamic> json) =>
|
||||
_$GithubMirrorFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$GithubMirrorToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class ExtraConfigGithubMirror {
|
||||
bool enabled;
|
||||
List<GithubMirror> mirrors;
|
||||
|
||||
ExtraConfigGithubMirror({
|
||||
this.enabled = true,
|
||||
this.mirrors = const [],
|
||||
});
|
||||
|
||||
factory ExtraConfigGithubMirror.fromJson(Map<String, dynamic>? json) =>
|
||||
json == null
|
||||
? ExtraConfigGithubMirror()
|
||||
: _$ExtraConfigGithubMirrorFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$ExtraConfigGithubMirrorToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class AutoTorrentConfig {
|
||||
bool enable;
|
||||
bool deleteAfterDownload;
|
||||
|
||||
AutoTorrentConfig({
|
||||
this.enable = false,
|
||||
this.deleteAfterDownload = false,
|
||||
});
|
||||
|
||||
factory AutoTorrentConfig.fromJson(Map<String, dynamic>? json) =>
|
||||
json == null ? AutoTorrentConfig() : _$AutoTorrentConfigFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$AutoTorrentConfigToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class ArchiveConfig {
|
||||
bool autoExtract;
|
||||
bool deleteAfterExtract;
|
||||
|
||||
ArchiveConfig({
|
||||
this.autoExtract = true,
|
||||
this.deleteAfterExtract = true,
|
||||
});
|
||||
|
||||
factory ArchiveConfig.fromJson(Map<String, dynamic>? json) =>
|
||||
json == null ? ArchiveConfig() : _$ArchiveConfigFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$ArchiveConfigToJson(this);
|
||||
}
|
||||
@@ -0,0 +1,309 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'downloader_config.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
DownloaderConfig _$DownloaderConfigFromJson(Map<String, dynamic> json) =>
|
||||
DownloaderConfig(
|
||||
downloadDir: json['downloadDir'] as String? ?? '',
|
||||
maxRunning: (json['maxRunning'] as num?)?.toInt() ?? 0,
|
||||
autoStartTasks: json['autoStartTasks'] as bool? ?? false,
|
||||
autoDeleteMissingFileTasks:
|
||||
json['autoDeleteMissingFileTasks'] as bool? ?? false,
|
||||
)
|
||||
..protocolConfig = ProtocolConfig.fromJson(
|
||||
json['protocolConfig'] as Map<String, dynamic>?)
|
||||
..extra = ExtraConfig.fromJson(json['extra'] as Map<String, dynamic>?)
|
||||
..proxy = ProxyConfig.fromJson(json['proxy'] as Map<String, dynamic>)
|
||||
..webhook =
|
||||
WebhookConfig.fromJson(json['webhook'] as Map<String, dynamic>?)
|
||||
..script = ScriptConfig.fromJson(json['script'] as Map<String, dynamic>?)
|
||||
..autoTorrent = AutoTorrentConfig.fromJson(
|
||||
json['autoTorrent'] as Map<String, dynamic>?)
|
||||
..archive =
|
||||
ArchiveConfig.fromJson(json['archive'] as Map<String, dynamic>?);
|
||||
|
||||
Map<String, dynamic> _$DownloaderConfigToJson(DownloaderConfig instance) =>
|
||||
<String, dynamic>{
|
||||
'downloadDir': instance.downloadDir,
|
||||
'maxRunning': instance.maxRunning,
|
||||
'protocolConfig': instance.protocolConfig.toJson(),
|
||||
'extra': instance.extra.toJson(),
|
||||
'proxy': instance.proxy.toJson(),
|
||||
'webhook': instance.webhook.toJson(),
|
||||
'script': instance.script.toJson(),
|
||||
'autoTorrent': instance.autoTorrent.toJson(),
|
||||
'archive': instance.archive.toJson(),
|
||||
'autoStartTasks': instance.autoStartTasks,
|
||||
'autoDeleteMissingFileTasks': instance.autoDeleteMissingFileTasks,
|
||||
};
|
||||
|
||||
ProtocolConfig _$ProtocolConfigFromJson(Map<String, dynamic> json) =>
|
||||
ProtocolConfig()
|
||||
..http = HttpConfig.fromJson(json['http'] as Map<String, dynamic>)
|
||||
..bt = BtConfig.fromJson(json['bt'] as Map<String, dynamic>)
|
||||
..ed2k = Ed2kConfig.fromJson(
|
||||
json['ed2k'] as Map<String, dynamic>? ?? <String, dynamic>{});
|
||||
|
||||
Map<String, dynamic> _$ProtocolConfigToJson(ProtocolConfig instance) =>
|
||||
<String, dynamic>{
|
||||
'http': instance.http.toJson(),
|
||||
'bt': instance.bt.toJson(),
|
||||
'ed2k': instance.ed2k.toJson(),
|
||||
};
|
||||
|
||||
HttpConfig _$HttpConfigFromJson(Map<String, dynamic> json) => HttpConfig(
|
||||
userAgent: json['userAgent'] as String? ?? '',
|
||||
connections: (json['connections'] as num?)?.toInt() ?? 0,
|
||||
useServerCtime: json['useServerCtime'] as bool? ?? false,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$HttpConfigToJson(HttpConfig instance) =>
|
||||
<String, dynamic>{
|
||||
'userAgent': instance.userAgent,
|
||||
'connections': instance.connections,
|
||||
'useServerCtime': instance.useServerCtime,
|
||||
};
|
||||
|
||||
BtConfig _$BtConfigFromJson(Map<String, dynamic> json) => BtConfig(
|
||||
listenPort: (json['listenPort'] as num?)?.toInt() ?? 0,
|
||||
trackers: (json['trackers'] as List<dynamic>?)
|
||||
?.map((e) => e as String)
|
||||
.toList() ??
|
||||
const [],
|
||||
seedKeep: json['seedKeep'] as bool? ?? false,
|
||||
seedRatio: (json['seedRatio'] as num?)?.toDouble() ?? 0,
|
||||
seedTime: (json['seedTime'] as num?)?.toInt() ?? 0,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$BtConfigToJson(BtConfig instance) => <String, dynamic>{
|
||||
'listenPort': instance.listenPort,
|
||||
'trackers': instance.trackers,
|
||||
'seedKeep': instance.seedKeep,
|
||||
'seedRatio': instance.seedRatio,
|
||||
'seedTime': instance.seedTime,
|
||||
};
|
||||
|
||||
Ed2kConfig _$Ed2kConfigFromJson(Map<String, dynamic> json) => Ed2kConfig(
|
||||
listenPort: (json['listenPort'] as num?)?.toInt() ?? 0,
|
||||
udpPort: (json['udpPort'] as num?)?.toInt() ?? 0,
|
||||
serverAddr: json['serverAddr'] as String? ?? '',
|
||||
serverMet: json['serverMet'] as String? ?? '',
|
||||
nodesDat: json['nodesDat'] as String? ?? '',
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$Ed2kConfigToJson(Ed2kConfig instance) =>
|
||||
<String, dynamic>{
|
||||
'listenPort': instance.listenPort,
|
||||
'udpPort': instance.udpPort,
|
||||
'serverAddr': instance.serverAddr,
|
||||
'serverMet': instance.serverMet,
|
||||
'nodesDat': instance.nodesDat,
|
||||
};
|
||||
|
||||
ExtraConfig _$ExtraConfigFromJson(Map<String, dynamic> json) => ExtraConfig(
|
||||
themeMode: json['themeMode'] as String? ?? '',
|
||||
locale: json['locale'] as String? ?? '',
|
||||
lastDeleteTaskKeep: json['lastDeleteTaskKeep'] as bool? ?? false,
|
||||
defaultDirectDownload: json['defaultDirectDownload'] as bool? ?? false,
|
||||
defaultBtClient: json['defaultBtClient'] as bool? ?? true,
|
||||
notifyWhenNewVersion: json['notifyWhenNewVersion'] as bool? ?? true,
|
||||
desktopNotification: json['desktopNotification'] as bool? ?? true,
|
||||
backgroundLocationKeepAlive:
|
||||
json['backgroundLocationKeepAlive'] as bool? ?? false,
|
||||
downloadCategories: (json['downloadCategories'] as List<dynamic>?)
|
||||
?.map((e) => DownloadCategory.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
const [],
|
||||
)
|
||||
..bt = ExtraConfigBt.fromJson(json['bt'] as Map<String, dynamic>)
|
||||
..githubMirror = ExtraConfigGithubMirror.fromJson(
|
||||
json['githubMirror'] as Map<String, dynamic>?);
|
||||
|
||||
Map<String, dynamic> _$ExtraConfigToJson(ExtraConfig instance) =>
|
||||
<String, dynamic>{
|
||||
'themeMode': instance.themeMode,
|
||||
'locale': instance.locale,
|
||||
'lastDeleteTaskKeep': instance.lastDeleteTaskKeep,
|
||||
'defaultDirectDownload': instance.defaultDirectDownload,
|
||||
'defaultBtClient': instance.defaultBtClient,
|
||||
'notifyWhenNewVersion': instance.notifyWhenNewVersion,
|
||||
'desktopNotification': instance.desktopNotification,
|
||||
'backgroundLocationKeepAlive': instance.backgroundLocationKeepAlive,
|
||||
'downloadCategories':
|
||||
instance.downloadCategories.map((e) => e.toJson()).toList(),
|
||||
'bt': instance.bt.toJson(),
|
||||
'githubMirror': instance.githubMirror.toJson(),
|
||||
};
|
||||
|
||||
DownloadCategory _$DownloadCategoryFromJson(Map<String, dynamic> json) =>
|
||||
DownloadCategory(
|
||||
name: json['name'] as String,
|
||||
path: json['path'] as String,
|
||||
isBuiltIn: json['isBuiltIn'] as bool? ?? false,
|
||||
nameKey: json['nameKey'] as String?,
|
||||
isDeleted: json['isDeleted'] as bool? ?? false,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$DownloadCategoryToJson(DownloadCategory instance) {
|
||||
final val = <String, dynamic>{
|
||||
'name': instance.name,
|
||||
'path': instance.path,
|
||||
'isBuiltIn': instance.isBuiltIn,
|
||||
};
|
||||
|
||||
void writeNotNull(String key, dynamic value) {
|
||||
if (value != null) {
|
||||
val[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
writeNotNull('nameKey', instance.nameKey);
|
||||
val['isDeleted'] = instance.isDeleted;
|
||||
return val;
|
||||
}
|
||||
|
||||
WebhookConfig _$WebhookConfigFromJson(Map<String, dynamic> json) =>
|
||||
WebhookConfig(
|
||||
enable: json['enable'] as bool? ?? false,
|
||||
urls:
|
||||
(json['urls'] as List<dynamic>?)?.map((e) => e as String).toList() ??
|
||||
const [],
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$WebhookConfigToJson(WebhookConfig instance) =>
|
||||
<String, dynamic>{
|
||||
'enable': instance.enable,
|
||||
'urls': instance.urls,
|
||||
};
|
||||
|
||||
ScriptConfig _$ScriptConfigFromJson(Map<String, dynamic> json) => ScriptConfig(
|
||||
enable: json['enable'] as bool? ?? false,
|
||||
paths:
|
||||
(json['paths'] as List<dynamic>?)?.map((e) => e as String).toList() ??
|
||||
const [],
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ScriptConfigToJson(ScriptConfig instance) =>
|
||||
<String, dynamic>{
|
||||
'enable': instance.enable,
|
||||
'paths': instance.paths,
|
||||
};
|
||||
|
||||
ProxyConfig _$ProxyConfigFromJson(Map<String, dynamic> json) => ProxyConfig(
|
||||
enable: json['enable'] as bool? ?? false,
|
||||
system: json['system'] as bool? ?? false,
|
||||
scheme: json['scheme'] as String? ?? '',
|
||||
host: json['host'] as String? ?? '',
|
||||
usr: json['usr'] as String? ?? '',
|
||||
pwd: json['pwd'] as String? ?? '',
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ProxyConfigToJson(ProxyConfig instance) =>
|
||||
<String, dynamic>{
|
||||
'enable': instance.enable,
|
||||
'system': instance.system,
|
||||
'scheme': instance.scheme,
|
||||
'host': instance.host,
|
||||
'usr': instance.usr,
|
||||
'pwd': instance.pwd,
|
||||
};
|
||||
|
||||
ExtraConfigBt _$ExtraConfigBtFromJson(Map<String, dynamic> json) =>
|
||||
ExtraConfigBt()
|
||||
..trackerSubscribeUrls = (json['trackerSubscribeUrls'] as List<dynamic>)
|
||||
.map((e) => e as String)
|
||||
.toList()
|
||||
..subscribeTrackers = (json['subscribeTrackers'] as List<dynamic>)
|
||||
.map((e) => e as String)
|
||||
.toList()
|
||||
..autoUpdateTrackers = json['autoUpdateTrackers'] as bool
|
||||
..lastTrackerUpdateTime = json['lastTrackerUpdateTime'] == null
|
||||
? null
|
||||
: DateTime.parse(json['lastTrackerUpdateTime'] as String)
|
||||
..customTrackers = (json['customTrackers'] as List<dynamic>)
|
||||
.map((e) => e as String)
|
||||
.toList();
|
||||
|
||||
Map<String, dynamic> _$ExtraConfigBtToJson(ExtraConfigBt instance) {
|
||||
final val = <String, dynamic>{
|
||||
'trackerSubscribeUrls': instance.trackerSubscribeUrls,
|
||||
'subscribeTrackers': instance.subscribeTrackers,
|
||||
'autoUpdateTrackers': instance.autoUpdateTrackers,
|
||||
};
|
||||
|
||||
void writeNotNull(String key, dynamic value) {
|
||||
if (value != null) {
|
||||
val[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
writeNotNull('lastTrackerUpdateTime',
|
||||
instance.lastTrackerUpdateTime?.toIso8601String());
|
||||
val['customTrackers'] = instance.customTrackers;
|
||||
return val;
|
||||
}
|
||||
|
||||
GithubMirror _$GithubMirrorFromJson(Map<String, dynamic> json) => GithubMirror(
|
||||
type: $enumDecode(_$GithubMirrorTypeEnumMap, json['type']),
|
||||
url: json['url'] as String,
|
||||
isBuiltIn: json['isBuiltIn'] as bool? ?? false,
|
||||
isDeleted: json['isDeleted'] as bool? ?? false,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$GithubMirrorToJson(GithubMirror instance) =>
|
||||
<String, dynamic>{
|
||||
'type': _$GithubMirrorTypeEnumMap[instance.type]!,
|
||||
'url': instance.url,
|
||||
'isBuiltIn': instance.isBuiltIn,
|
||||
'isDeleted': instance.isDeleted,
|
||||
};
|
||||
|
||||
const _$GithubMirrorTypeEnumMap = {
|
||||
GithubMirrorType.jsdelivr: 'jsdelivr',
|
||||
GithubMirrorType.ghProxy: 'ghProxy',
|
||||
};
|
||||
|
||||
ExtraConfigGithubMirror _$ExtraConfigGithubMirrorFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
ExtraConfigGithubMirror(
|
||||
enabled: json['enabled'] as bool? ?? true,
|
||||
mirrors: (json['mirrors'] as List<dynamic>?)
|
||||
?.map((e) => GithubMirror.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
const [],
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ExtraConfigGithubMirrorToJson(
|
||||
ExtraConfigGithubMirror instance) =>
|
||||
<String, dynamic>{
|
||||
'enabled': instance.enabled,
|
||||
'mirrors': instance.mirrors.map((e) => e.toJson()).toList(),
|
||||
};
|
||||
|
||||
AutoTorrentConfig _$AutoTorrentConfigFromJson(Map<String, dynamic> json) =>
|
||||
AutoTorrentConfig(
|
||||
enable: json['enable'] as bool? ?? false,
|
||||
deleteAfterDownload: json['deleteAfterDownload'] as bool? ?? false,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$AutoTorrentConfigToJson(AutoTorrentConfig instance) =>
|
||||
<String, dynamic>{
|
||||
'enable': instance.enable,
|
||||
'deleteAfterDownload': instance.deleteAfterDownload,
|
||||
};
|
||||
|
||||
ArchiveConfig _$ArchiveConfigFromJson(Map<String, dynamic> json) =>
|
||||
ArchiveConfig(
|
||||
autoExtract: json['autoExtract'] as bool? ?? true,
|
||||
deleteAfterExtract: json['deleteAfterExtract'] as bool? ?? true,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ArchiveConfigToJson(ArchiveConfig instance) =>
|
||||
<String, dynamic>{
|
||||
'autoExtract': instance.autoExtract,
|
||||
'deleteAfterExtract': instance.deleteAfterExtract,
|
||||
};
|
||||
@@ -0,0 +1,97 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'extension.g.dart';
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class Extension {
|
||||
String identity;
|
||||
String name;
|
||||
String author;
|
||||
String title;
|
||||
String description;
|
||||
String icon;
|
||||
String version;
|
||||
String homepage;
|
||||
Repository? repository;
|
||||
List<Setting>? settings;
|
||||
bool disabled;
|
||||
bool devMode;
|
||||
String devPath;
|
||||
|
||||
Extension({
|
||||
required this.identity,
|
||||
required this.name,
|
||||
required this.author,
|
||||
required this.title,
|
||||
required this.description,
|
||||
required this.icon,
|
||||
required this.version,
|
||||
required this.homepage,
|
||||
required this.repository,
|
||||
required this.disabled,
|
||||
required this.devMode,
|
||||
required this.devPath,
|
||||
});
|
||||
|
||||
factory Extension.fromJson(Map<String, dynamic> json) =>
|
||||
_$ExtensionFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$ExtensionToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class Repository {
|
||||
String url;
|
||||
String directory;
|
||||
|
||||
Repository({
|
||||
required this.url,
|
||||
required this.directory,
|
||||
});
|
||||
|
||||
factory Repository.fromJson(Map<String, dynamic> json) =>
|
||||
_$RepositoryFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$RepositoryToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class Setting {
|
||||
String name;
|
||||
String title;
|
||||
String description;
|
||||
bool required;
|
||||
SettingType type;
|
||||
Object? value;
|
||||
List<Option>? options;
|
||||
|
||||
Setting({
|
||||
required this.name,
|
||||
required this.title,
|
||||
required this.description,
|
||||
required this.required,
|
||||
required this.type,
|
||||
});
|
||||
|
||||
factory Setting.fromJson(Map<String, dynamic> json) =>
|
||||
_$SettingFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$SettingToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class Option {
|
||||
String label;
|
||||
Object value;
|
||||
|
||||
Option({
|
||||
required this.label,
|
||||
required this.value,
|
||||
});
|
||||
|
||||
factory Option.fromJson(Map<String, dynamic> json) => _$OptionFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$OptionToJson(this);
|
||||
}
|
||||
|
||||
enum SettingType {
|
||||
string,
|
||||
number,
|
||||
boolean,
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'extension.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
Extension _$ExtensionFromJson(Map<String, dynamic> json) => Extension(
|
||||
identity: json['identity'] as String,
|
||||
name: json['name'] as String,
|
||||
author: json['author'] as String,
|
||||
title: json['title'] as String,
|
||||
description: json['description'] as String,
|
||||
icon: json['icon'] as String,
|
||||
version: json['version'] as String,
|
||||
homepage: json['homepage'] as String,
|
||||
repository: json['repository'] == null
|
||||
? null
|
||||
: Repository.fromJson(json['repository'] as Map<String, dynamic>),
|
||||
disabled: json['disabled'] as bool,
|
||||
devMode: json['devMode'] as bool,
|
||||
devPath: json['devPath'] as String,
|
||||
)..settings = (json['settings'] as List<dynamic>?)
|
||||
?.map((e) => Setting.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
|
||||
Map<String, dynamic> _$ExtensionToJson(Extension instance) {
|
||||
final val = <String, dynamic>{
|
||||
'identity': instance.identity,
|
||||
'name': instance.name,
|
||||
'author': instance.author,
|
||||
'title': instance.title,
|
||||
'description': instance.description,
|
||||
'icon': instance.icon,
|
||||
'version': instance.version,
|
||||
'homepage': instance.homepage,
|
||||
};
|
||||
|
||||
void writeNotNull(String key, dynamic value) {
|
||||
if (value != null) {
|
||||
val[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
writeNotNull('repository', instance.repository?.toJson());
|
||||
writeNotNull('settings', instance.settings?.map((e) => e.toJson()).toList());
|
||||
val['disabled'] = instance.disabled;
|
||||
val['devMode'] = instance.devMode;
|
||||
val['devPath'] = instance.devPath;
|
||||
return val;
|
||||
}
|
||||
|
||||
Repository _$RepositoryFromJson(Map<String, dynamic> json) => Repository(
|
||||
url: json['url'] as String,
|
||||
directory: json['directory'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$RepositoryToJson(Repository instance) =>
|
||||
<String, dynamic>{
|
||||
'url': instance.url,
|
||||
'directory': instance.directory,
|
||||
};
|
||||
|
||||
Setting _$SettingFromJson(Map<String, dynamic> json) => Setting(
|
||||
name: json['name'] as String,
|
||||
title: json['title'] as String,
|
||||
description: json['description'] as String,
|
||||
required: json['required'] as bool,
|
||||
type: $enumDecode(_$SettingTypeEnumMap, json['type']),
|
||||
)
|
||||
..value = json['value']
|
||||
..options = (json['options'] as List<dynamic>?)
|
||||
?.map((e) => Option.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
|
||||
Map<String, dynamic> _$SettingToJson(Setting instance) {
|
||||
final val = <String, dynamic>{
|
||||
'name': instance.name,
|
||||
'title': instance.title,
|
||||
'description': instance.description,
|
||||
'required': instance.required,
|
||||
'type': _$SettingTypeEnumMap[instance.type]!,
|
||||
};
|
||||
|
||||
void writeNotNull(String key, dynamic value) {
|
||||
if (value != null) {
|
||||
val[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
writeNotNull('value', instance.value);
|
||||
writeNotNull('options', instance.options);
|
||||
return val;
|
||||
}
|
||||
|
||||
const _$SettingTypeEnumMap = {
|
||||
SettingType.string: 'string',
|
||||
SettingType.number: 'number',
|
||||
SettingType.boolean: 'boolean',
|
||||
};
|
||||
|
||||
Option _$OptionFromJson(Map<String, dynamic> json) => Option(
|
||||
label: json['label'] as String,
|
||||
value: json['value'] as Object,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$OptionToJson(Option instance) => <String, dynamic>{
|
||||
'label': instance.label,
|
||||
'value': instance.value,
|
||||
};
|
||||
@@ -0,0 +1,18 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'install_extension.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class InstallExtension {
|
||||
bool devMode;
|
||||
String url;
|
||||
|
||||
InstallExtension({
|
||||
this.devMode = false,
|
||||
required this.url,
|
||||
});
|
||||
|
||||
factory InstallExtension.fromJson(Map<String, dynamic> json) =>
|
||||
_$InstallExtensionFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$InstallExtensionToJson(this);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'install_extension.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
InstallExtension _$InstallExtensionFromJson(Map<String, dynamic> json) =>
|
||||
InstallExtension(
|
||||
devMode: json['devMode'] as bool? ?? false,
|
||||
url: json['url'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$InstallExtensionToJson(InstallExtension instance) =>
|
||||
<String, dynamic>{
|
||||
'devMode': instance.devMode,
|
||||
'url': instance.url,
|
||||
};
|
||||
@@ -0,0 +1,18 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'login.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class LoginReq {
|
||||
String username;
|
||||
String password;
|
||||
|
||||
LoginReq({
|
||||
required this.username,
|
||||
required this.password,
|
||||
});
|
||||
|
||||
factory LoginReq.fromJson(Map<String, dynamic> json) =>
|
||||
_$LoginReqFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$LoginReqToJson(this);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'login.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
LoginReq _$LoginReqFromJson(Map<String, dynamic> json) => LoginReq(
|
||||
username: json['username'] as String,
|
||||
password: json['password'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$LoginReqToJson(LoginReq instance) => <String, dynamic>{
|
||||
'username': instance.username,
|
||||
'password': instance.password,
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
import 'options.dart';
|
||||
import 'request.dart';
|
||||
import 'resource.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'meta.g.dart';
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class Meta {
|
||||
Request req;
|
||||
Resource? res;
|
||||
Options opts;
|
||||
|
||||
Meta({
|
||||
required this.req,
|
||||
required this.opts,
|
||||
});
|
||||
|
||||
factory Meta.fromJson(Map<String, dynamic> json) => _$MetaFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$MetaToJson(this);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'meta.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
Meta _$MetaFromJson(Map<String, dynamic> json) => Meta(
|
||||
req: Request.fromJson(json['req'] as Map<String, dynamic>),
|
||||
opts: Options.fromJson(json['opts'] as Map<String, dynamic>),
|
||||
)..res = json['res'] == null
|
||||
? null
|
||||
: Resource.fromJson(json['res'] as Map<String, dynamic>);
|
||||
|
||||
Map<String, dynamic> _$MetaToJson(Meta instance) {
|
||||
final val = <String, dynamic>{
|
||||
'req': instance.req.toJson(),
|
||||
};
|
||||
|
||||
void writeNotNull(String key, dynamic value) {
|
||||
if (value != null) {
|
||||
val[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
writeNotNull('res', instance.res?.toJson());
|
||||
val['opts'] = instance.opts.toJson();
|
||||
return val;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'options.g.dart';
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class Options {
|
||||
String name;
|
||||
String path;
|
||||
List<int> selectFiles;
|
||||
Object? extra;
|
||||
|
||||
Options({
|
||||
this.name = '',
|
||||
this.path = '',
|
||||
this.selectFiles = const [],
|
||||
this.extra,
|
||||
});
|
||||
|
||||
factory Options.fromJson(Map<String, dynamic> json) =>
|
||||
_$OptionsFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$OptionsToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class OptsExtraHttp {
|
||||
int connections;
|
||||
bool? autoTorrent;
|
||||
bool? deleteTorrentAfterDownload;
|
||||
bool? autoExtract;
|
||||
String archivePassword;
|
||||
bool deleteAfterExtract;
|
||||
|
||||
OptsExtraHttp({
|
||||
this.connections = 0,
|
||||
this.autoTorrent,
|
||||
this.deleteTorrentAfterDownload,
|
||||
this.autoExtract,
|
||||
this.archivePassword = '',
|
||||
this.deleteAfterExtract = false,
|
||||
});
|
||||
|
||||
factory OptsExtraHttp.fromJson(Map<String, dynamic> json) =>
|
||||
_$OptsExtraHttpFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$OptsExtraHttpToJson(this);
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'options.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
Options _$OptionsFromJson(Map<String, dynamic> json) => Options(
|
||||
name: json['name'] as String? ?? '',
|
||||
path: json['path'] as String? ?? '',
|
||||
selectFiles: (json['selectFiles'] as List<dynamic>?)
|
||||
?.map((e) => (e as num).toInt())
|
||||
.toList() ??
|
||||
const [],
|
||||
extra: json['extra'],
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$OptionsToJson(Options instance) {
|
||||
final val = <String, dynamic>{
|
||||
'name': instance.name,
|
||||
'path': instance.path,
|
||||
'selectFiles': instance.selectFiles,
|
||||
};
|
||||
|
||||
void writeNotNull(String key, dynamic value) {
|
||||
if (value != null) {
|
||||
val[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
writeNotNull('extra', instance.extra);
|
||||
return val;
|
||||
}
|
||||
|
||||
OptsExtraHttp _$OptsExtraHttpFromJson(Map<String, dynamic> json) =>
|
||||
OptsExtraHttp(
|
||||
connections: (json['connections'] as num?)?.toInt() ?? 0,
|
||||
autoTorrent: json['autoTorrent'] as bool?,
|
||||
deleteTorrentAfterDownload: json['deleteTorrentAfterDownload'] as bool?,
|
||||
autoExtract: json['autoExtract'] as bool?,
|
||||
archivePassword: json['archivePassword'] as String? ?? '',
|
||||
deleteAfterExtract: json['deleteAfterExtract'] as bool? ?? false,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$OptsExtraHttpToJson(OptsExtraHttp instance) {
|
||||
final val = <String, dynamic>{
|
||||
'connections': instance.connections,
|
||||
};
|
||||
|
||||
void writeNotNull(String key, dynamic value) {
|
||||
if (value != null) {
|
||||
val[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
writeNotNull('autoTorrent', instance.autoTorrent);
|
||||
writeNotNull(
|
||||
'deleteTorrentAfterDownload', instance.deleteTorrentAfterDownload);
|
||||
writeNotNull('autoExtract', instance.autoExtract);
|
||||
val['archivePassword'] = instance.archivePassword;
|
||||
val['deleteAfterExtract'] = instance.deleteAfterExtract;
|
||||
return val;
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'request.g.dart';
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class Request {
|
||||
String? rawUrl;
|
||||
String url;
|
||||
Object? extra;
|
||||
Map<String, String>? labels;
|
||||
RequestProxy? proxy;
|
||||
bool skipVerifyCert;
|
||||
|
||||
Request({
|
||||
this.rawUrl,
|
||||
required this.url,
|
||||
this.extra,
|
||||
this.labels,
|
||||
this.proxy,
|
||||
this.skipVerifyCert = false,
|
||||
});
|
||||
|
||||
factory Request.fromJson(Map<String, dynamic> json) =>
|
||||
_$RequestFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$RequestToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class 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);
|
||||
|
||||
Map<String, dynamic> toJson() => _$ReqExtraHttpToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class ReqExtraBt {
|
||||
List<String> trackers;
|
||||
|
||||
ReqExtraBt({
|
||||
this.trackers = const [],
|
||||
});
|
||||
|
||||
factory ReqExtraBt.fromJson(Map<String, dynamic> json) =>
|
||||
_$ReqExtraBtFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$ReqExtraBtToJson(this);
|
||||
}
|
||||
|
||||
enum RequestProxyMode {
|
||||
follow,
|
||||
none,
|
||||
custom,
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class 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);
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'request.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
Request _$RequestFromJson(Map<String, dynamic> json) => Request(
|
||||
rawUrl: json['rawUrl'] as String?,
|
||||
url: json['url'] as String,
|
||||
extra: json['extra'],
|
||||
labels: (json['labels'] as Map<String, dynamic>?)?.map(
|
||||
(k, e) => MapEntry(k, e as String),
|
||||
),
|
||||
proxy: json['proxy'] == null
|
||||
? null
|
||||
: RequestProxy.fromJson(json['proxy'] as Map<String, dynamic>),
|
||||
skipVerifyCert: json['skipVerifyCert'] as bool? ?? false,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$RequestToJson(Request instance) {
|
||||
final val = <String, dynamic>{
|
||||
'rawUrl': instance.rawUrl,
|
||||
'url': instance.url,
|
||||
};
|
||||
|
||||
void writeNotNull(String key, dynamic value) {
|
||||
if (value != null) {
|
||||
val[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
writeNotNull('extra', instance.extra);
|
||||
writeNotNull('labels', instance.labels);
|
||||
writeNotNull('proxy', instance.proxy?.toJson());
|
||||
val['skipVerifyCert'] = instance.skipVerifyCert;
|
||||
return val;
|
||||
}
|
||||
|
||||
ReqExtraHttp _$ReqExtraHttpFromJson(Map<String, dynamic> json) => ReqExtraHttp(
|
||||
method: json['method'] as String? ?? 'GET',
|
||||
header: (json['header'] as Map<String, dynamic>?)?.map(
|
||||
(k, e) => MapEntry(k, e as String),
|
||||
) ??
|
||||
const {},
|
||||
body: json['body'] as String? ?? '',
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ReqExtraHttpToJson(ReqExtraHttp instance) =>
|
||||
<String, dynamic>{
|
||||
'method': instance.method,
|
||||
'header': instance.header,
|
||||
'body': instance.body,
|
||||
};
|
||||
|
||||
ReqExtraBt _$ReqExtraBtFromJson(Map<String, dynamic> json) => ReqExtraBt(
|
||||
trackers: (json['trackers'] as List<dynamic>?)
|
||||
?.map((e) => e as String)
|
||||
.toList() ??
|
||||
const [],
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ReqExtraBtToJson(ReqExtraBt instance) =>
|
||||
<String, dynamic>{
|
||||
'trackers': instance.trackers,
|
||||
};
|
||||
|
||||
RequestProxy _$RequestProxyFromJson(Map<String, dynamic> json) => RequestProxy(
|
||||
mode: $enumDecodeNullable(_$RequestProxyModeEnumMap, json['mode']) ??
|
||||
RequestProxyMode.follow,
|
||||
scheme: json['scheme'] as String? ?? 'http',
|
||||
host: json['host'] as String? ?? '',
|
||||
usr: json['usr'] as String? ?? '',
|
||||
pwd: json['pwd'] as String? ?? '',
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$RequestProxyToJson(RequestProxy instance) =>
|
||||
<String, dynamic>{
|
||||
'mode': _$RequestProxyModeEnumMap[instance.mode]!,
|
||||
'scheme': instance.scheme,
|
||||
'host': instance.host,
|
||||
'usr': instance.usr,
|
||||
'pwd': instance.pwd,
|
||||
};
|
||||
|
||||
const _$RequestProxyModeEnumMap = {
|
||||
RequestProxyMode.follow: 'follow',
|
||||
RequestProxyMode.none: 'none',
|
||||
RequestProxyMode.custom: 'custom',
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'resource.dart';
|
||||
|
||||
part 'resolve_result.g.dart';
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class ResolveResult {
|
||||
String id;
|
||||
Resource res;
|
||||
|
||||
ResolveResult({
|
||||
this.id = "",
|
||||
required this.res,
|
||||
});
|
||||
|
||||
factory ResolveResult.fromJson(Map<String, dynamic> json) =>
|
||||
_$ResolveResultFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$ResolveResultToJson(this);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'resolve_result.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
ResolveResult _$ResolveResultFromJson(Map<String, dynamic> json) =>
|
||||
ResolveResult(
|
||||
id: json['id'] as String? ?? "",
|
||||
res: Resource.fromJson(json['res'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ResolveResultToJson(ResolveResult instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'res': instance.res.toJson(),
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'options.dart';
|
||||
import 'request.dart';
|
||||
|
||||
part 'resolve_task.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class ResolveTask {
|
||||
Request? req;
|
||||
Options? opts;
|
||||
|
||||
ResolveTask({
|
||||
this.req,
|
||||
this.opts,
|
||||
});
|
||||
|
||||
factory ResolveTask.fromJson(Map<String, dynamic> json) =>
|
||||
_$ResolveTaskFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$ResolveTaskToJson(this);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'resolve_task.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
ResolveTask _$ResolveTaskFromJson(Map<String, dynamic> json) => ResolveTask(
|
||||
req: json['req'] == null
|
||||
? null
|
||||
: Request.fromJson(json['req'] as Map<String, dynamic>),
|
||||
opts: json['opts'] == null
|
||||
? null
|
||||
: Options.fromJson(json['opts'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ResolveTaskToJson(ResolveTask instance) {
|
||||
final val = <String, dynamic>{};
|
||||
|
||||
void writeNotNull(String key, dynamic value) {
|
||||
if (value != null) {
|
||||
val[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
writeNotNull('req', instance.req);
|
||||
writeNotNull('opts', instance.opts);
|
||||
return val;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import 'package:gopeed/api/model/request.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'resource.g.dart';
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class Resource {
|
||||
String name;
|
||||
int size;
|
||||
bool range;
|
||||
List<FileInfo> files;
|
||||
String hash;
|
||||
|
||||
Resource(
|
||||
{this.name = "",
|
||||
this.size = 0,
|
||||
this.range = false,
|
||||
required this.files,
|
||||
this.hash = ""});
|
||||
|
||||
factory Resource.fromJson(Map<String, dynamic> json) =>
|
||||
_$ResourceFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$ResourceToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class FileInfo {
|
||||
String path;
|
||||
String name;
|
||||
int size;
|
||||
Request? req;
|
||||
|
||||
FileInfo({
|
||||
this.path = "",
|
||||
required this.name,
|
||||
this.size = 0,
|
||||
this.req,
|
||||
});
|
||||
|
||||
factory FileInfo.fromJson(Map<String, dynamic> json) =>
|
||||
_$FileInfoFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$FileInfoToJson(this);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'resource.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
Resource _$ResourceFromJson(Map<String, dynamic> json) => Resource(
|
||||
name: json['name'] as String? ?? "",
|
||||
size: (json['size'] as num?)?.toInt() ?? 0,
|
||||
range: json['range'] as bool? ?? false,
|
||||
files: (json['files'] as List<dynamic>)
|
||||
.map((e) => FileInfo.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
hash: json['hash'] as String? ?? "",
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ResourceToJson(Resource instance) => <String, dynamic>{
|
||||
'name': instance.name,
|
||||
'size': instance.size,
|
||||
'range': instance.range,
|
||||
'files': instance.files.map((e) => e.toJson()).toList(),
|
||||
'hash': instance.hash,
|
||||
};
|
||||
|
||||
FileInfo _$FileInfoFromJson(Map<String, dynamic> json) => FileInfo(
|
||||
path: json['path'] as String? ?? "",
|
||||
name: json['name'] as String,
|
||||
size: (json['size'] as num?)?.toInt() ?? 0,
|
||||
req: json['req'] == null
|
||||
? null
|
||||
: Request.fromJson(json['req'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$FileInfoToJson(FileInfo instance) {
|
||||
final val = <String, dynamic>{
|
||||
'path': instance.path,
|
||||
'name': instance.name,
|
||||
'size': instance.size,
|
||||
};
|
||||
|
||||
void writeNotNull(String key, dynamic value) {
|
||||
if (value != null) {
|
||||
val[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
writeNotNull('req', instance.req?.toJson());
|
||||
return val;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'result.g.dart';
|
||||
|
||||
@JsonSerializable(genericArgumentFactories: true)
|
||||
class Result<T> {
|
||||
int code;
|
||||
String? msg;
|
||||
T? data;
|
||||
|
||||
Result({
|
||||
required this.code,
|
||||
this.msg,
|
||||
this.data,
|
||||
});
|
||||
|
||||
factory Result.fromJson(
|
||||
Map<String, dynamic> json,
|
||||
T Function(dynamic json) fromJsonT,
|
||||
) =>
|
||||
_$ResultFromJson(json, fromJsonT);
|
||||
Map<String, dynamic> toJson() => {
|
||||
'code': code,
|
||||
'msg': msg,
|
||||
'data': data is List
|
||||
? (data as dynamic)?.map((e) => e.toJson()).toList()
|
||||
: (data as dynamic)?.toJson(),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'result.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
Result<T> _$ResultFromJson<T>(
|
||||
Map<String, dynamic> json,
|
||||
T Function(Object? json) fromJsonT,
|
||||
) =>
|
||||
Result<T>(
|
||||
code: (json['code'] as num).toInt(),
|
||||
msg: json['msg'] as String?,
|
||||
data: _$nullableGenericFromJson(json['data'], fromJsonT),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ResultToJson<T>(
|
||||
Result<T> instance,
|
||||
Object? Function(T value) toJsonT,
|
||||
) {
|
||||
final val = <String, dynamic>{
|
||||
'code': instance.code,
|
||||
};
|
||||
|
||||
void writeNotNull(String key, dynamic value) {
|
||||
if (value != null) {
|
||||
val[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
writeNotNull('msg', instance.msg);
|
||||
writeNotNull('data', _$nullableGenericToJson(instance.data, toJsonT));
|
||||
return val;
|
||||
}
|
||||
|
||||
T? _$nullableGenericFromJson<T>(
|
||||
Object? input,
|
||||
T Function(Object? json) fromJson,
|
||||
) =>
|
||||
input == null ? null : fromJson(input);
|
||||
|
||||
Object? _$nullableGenericToJson<T>(
|
||||
T? input,
|
||||
Object? Function(T value) toJson,
|
||||
) =>
|
||||
input == null ? null : toJson(input);
|
||||
@@ -0,0 +1,149 @@
|
||||
import 'dart:convert';
|
||||
|
||||
class StoreExtensionPage {
|
||||
final List<StoreExtension> data;
|
||||
final StorePagination pagination;
|
||||
|
||||
StoreExtensionPage({required this.data, required this.pagination});
|
||||
|
||||
factory StoreExtensionPage.fromJson(Map<String, dynamic> json) {
|
||||
return StoreExtensionPage(
|
||||
data: (json['data'] as List<dynamic>? ?? [])
|
||||
.map((e) => StoreExtension.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
pagination: StorePagination.fromJson(
|
||||
json['pagination'] as Map<String, dynamic>? ?? {}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class StorePagination {
|
||||
final int page;
|
||||
final int limit;
|
||||
final int total;
|
||||
final int totalPages;
|
||||
final bool hasNext;
|
||||
final bool hasPrev;
|
||||
|
||||
StorePagination({
|
||||
required this.page,
|
||||
required this.limit,
|
||||
required this.total,
|
||||
required this.totalPages,
|
||||
required this.hasNext,
|
||||
required this.hasPrev,
|
||||
});
|
||||
|
||||
factory StorePagination.fromJson(Map<String, dynamic> json) {
|
||||
return StorePagination(
|
||||
page: (json['page'] as num?)?.toInt() ?? 1,
|
||||
limit: (json['limit'] as num?)?.toInt() ?? 20,
|
||||
total: (json['total'] as num?)?.toInt() ?? 0,
|
||||
totalPages: (json['totalPages'] as num?)?.toInt() ?? 1,
|
||||
hasNext: json['hasNext'] as bool? ?? false,
|
||||
hasPrev: json['hasPrev'] as bool? ?? false,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class StoreExtension {
|
||||
final String id;
|
||||
final String repoFullName;
|
||||
final String repoUrl;
|
||||
final String? directory;
|
||||
final String? commitSha;
|
||||
final String name;
|
||||
final String author;
|
||||
final String title;
|
||||
final String description;
|
||||
final String? icon;
|
||||
final String version;
|
||||
final String? homepage;
|
||||
final String? readme;
|
||||
final int installCount;
|
||||
final int stars;
|
||||
final List<String> topics;
|
||||
final DateTime? createdAt;
|
||||
final DateTime? updatedAt;
|
||||
|
||||
StoreExtension({
|
||||
required this.id,
|
||||
required this.repoFullName,
|
||||
required this.repoUrl,
|
||||
this.directory,
|
||||
this.commitSha,
|
||||
required this.name,
|
||||
required this.author,
|
||||
required this.title,
|
||||
required this.description,
|
||||
this.icon,
|
||||
required this.version,
|
||||
this.homepage,
|
||||
this.readme,
|
||||
required this.installCount,
|
||||
required this.stars,
|
||||
required this.topics,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
});
|
||||
|
||||
factory StoreExtension.fromJson(Map<String, dynamic> json) {
|
||||
return StoreExtension(
|
||||
id: json['id'] as String? ?? '',
|
||||
repoFullName: json['repoFullName'] as String? ?? '',
|
||||
repoUrl: json['repoUrl'] as String? ?? '',
|
||||
directory: json['directory'] as String?,
|
||||
commitSha: json['commitSha'] as String?,
|
||||
name: json['name'] as String? ?? '',
|
||||
author: json['author'] as String? ?? '',
|
||||
title: json['title'] as String? ?? '',
|
||||
description: json['description'] as String? ?? '',
|
||||
icon: json['icon'] as String?,
|
||||
version: json['version'] as String? ?? '0.0.0',
|
||||
homepage: json['homepage'] as String?,
|
||||
readme: json['readme'] as String?,
|
||||
installCount: (json['installCount'] as num?)?.toInt() ?? 0,
|
||||
stars: (json['stars'] as num?)?.toInt() ?? 0,
|
||||
topics: _parseTopics(json['topics']),
|
||||
createdAt: _parseDate(json['createdAt']),
|
||||
updatedAt: _parseDate(json['updatedAt']),
|
||||
);
|
||||
}
|
||||
|
||||
static List<String> _parseTopics(dynamic value) {
|
||||
if (value is List) {
|
||||
return value.map((e) => e.toString()).toList();
|
||||
}
|
||||
if (value is String && value.isNotEmpty) {
|
||||
try {
|
||||
final parsed = jsonDecode(value);
|
||||
if (parsed is List) {
|
||||
return parsed.map((e) => e.toString()).toList();
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
return const [];
|
||||
}
|
||||
|
||||
static DateTime? _parseDate(dynamic value) {
|
||||
if (value == null) return null;
|
||||
if (value is int) {
|
||||
return DateTime.fromMillisecondsSinceEpoch(value);
|
||||
}
|
||||
if (value is String && value.isNotEmpty) {
|
||||
return DateTime.tryParse(value);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
enum StoreExtensionSort {
|
||||
stars,
|
||||
installs,
|
||||
updated,
|
||||
}
|
||||
|
||||
enum StoreSortOrder {
|
||||
asc,
|
||||
desc,
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'switch_extension.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class SwitchExtension {
|
||||
bool status;
|
||||
|
||||
SwitchExtension({
|
||||
required this.status,
|
||||
});
|
||||
|
||||
factory SwitchExtension.fromJson(Map<String, dynamic> json) =>
|
||||
_$SwitchExtensionFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$SwitchExtensionToJson(this);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'switch_extension.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
SwitchExtension _$SwitchExtensionFromJson(Map<String, dynamic> json) =>
|
||||
SwitchExtension(
|
||||
status: json['status'] as bool,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$SwitchExtensionToJson(SwitchExtension instance) =>
|
||||
<String, dynamic>{
|
||||
'status': instance.status,
|
||||
};
|
||||
@@ -0,0 +1,77 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'meta.dart';
|
||||
|
||||
part 'task.g.dart';
|
||||
|
||||
enum Status { ready, running, pause, wait, error, done }
|
||||
|
||||
enum Protocol { http, bt, ed2k }
|
||||
|
||||
// ExtractStatus enum matching Go backend
|
||||
enum ExtractStatus {
|
||||
@JsonValue('')
|
||||
none,
|
||||
@JsonValue('extracting')
|
||||
extracting,
|
||||
@JsonValue('done')
|
||||
done,
|
||||
@JsonValue('error')
|
||||
error,
|
||||
@JsonValue('waitingParts')
|
||||
waitingParts
|
||||
}
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class Task {
|
||||
String id;
|
||||
String name;
|
||||
Protocol? protocol;
|
||||
Meta meta;
|
||||
Status status;
|
||||
bool uploading;
|
||||
Progress progress;
|
||||
DateTime createdAt;
|
||||
DateTime updatedAt;
|
||||
|
||||
Task({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.meta,
|
||||
required this.status,
|
||||
required this.uploading,
|
||||
required this.progress,
|
||||
required this.createdAt,
|
||||
required this.updatedAt,
|
||||
});
|
||||
|
||||
factory Task.fromJson(Map<String, dynamic> json) => _$TaskFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$TaskToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class Progress {
|
||||
int used;
|
||||
int speed;
|
||||
int downloaded;
|
||||
int uploadSpeed;
|
||||
int uploaded;
|
||||
ExtractStatus extractStatus;
|
||||
int extractProgress;
|
||||
|
||||
Progress({
|
||||
required this.used,
|
||||
required this.speed,
|
||||
required this.downloaded,
|
||||
required this.uploadSpeed,
|
||||
required this.uploaded,
|
||||
this.extractStatus = ExtractStatus.none,
|
||||
this.extractProgress = 0,
|
||||
});
|
||||
|
||||
factory Progress.fromJson(Map<String, dynamic> json) =>
|
||||
_$ProgressFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$ProgressToJson(this);
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'task.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
Task _$TaskFromJson(Map<String, dynamic> json) => Task(
|
||||
id: json['id'] as String,
|
||||
name: json['name'] as String,
|
||||
meta: Meta.fromJson(json['meta'] as Map<String, dynamic>),
|
||||
status: $enumDecode(_$StatusEnumMap, json['status']),
|
||||
uploading: json['uploading'] as bool,
|
||||
progress: Progress.fromJson(json['progress'] as Map<String, dynamic>),
|
||||
createdAt: DateTime.parse(json['createdAt'] as String),
|
||||
updatedAt: DateTime.parse(json['updatedAt'] as String),
|
||||
)..protocol = $enumDecodeNullable(_$ProtocolEnumMap, json['protocol']);
|
||||
|
||||
Map<String, dynamic> _$TaskToJson(Task instance) {
|
||||
final val = <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'name': instance.name,
|
||||
};
|
||||
|
||||
void writeNotNull(String key, dynamic value) {
|
||||
if (value != null) {
|
||||
val[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
writeNotNull('protocol', _$ProtocolEnumMap[instance.protocol]);
|
||||
val['meta'] = instance.meta.toJson();
|
||||
val['status'] = _$StatusEnumMap[instance.status]!;
|
||||
val['uploading'] = instance.uploading;
|
||||
val['progress'] = instance.progress.toJson();
|
||||
val['createdAt'] = instance.createdAt.toIso8601String();
|
||||
val['updatedAt'] = instance.updatedAt.toIso8601String();
|
||||
return val;
|
||||
}
|
||||
|
||||
const _$StatusEnumMap = {
|
||||
Status.ready: 'ready',
|
||||
Status.running: 'running',
|
||||
Status.pause: 'pause',
|
||||
Status.wait: 'wait',
|
||||
Status.error: 'error',
|
||||
Status.done: 'done',
|
||||
};
|
||||
|
||||
const _$ProtocolEnumMap = {
|
||||
Protocol.http: 'http',
|
||||
Protocol.bt: 'bt',
|
||||
Protocol.ed2k: 'ed2k',
|
||||
};
|
||||
|
||||
Progress _$ProgressFromJson(Map<String, dynamic> json) => Progress(
|
||||
used: (json['used'] as num).toInt(),
|
||||
speed: (json['speed'] as num).toInt(),
|
||||
downloaded: (json['downloaded'] as num).toInt(),
|
||||
uploadSpeed: (json['uploadSpeed'] as num).toInt(),
|
||||
uploaded: (json['uploaded'] as num).toInt(),
|
||||
extractStatus:
|
||||
$enumDecodeNullable(_$ExtractStatusEnumMap, json['extractStatus']) ??
|
||||
ExtractStatus.none,
|
||||
extractProgress: (json['extractProgress'] as num?)?.toInt() ?? 0,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ProgressToJson(Progress instance) => <String, dynamic>{
|
||||
'used': instance.used,
|
||||
'speed': instance.speed,
|
||||
'downloaded': instance.downloaded,
|
||||
'uploadSpeed': instance.uploadSpeed,
|
||||
'uploaded': instance.uploaded,
|
||||
'extractStatus': _$ExtractStatusEnumMap[instance.extractStatus]!,
|
||||
'extractProgress': instance.extractProgress,
|
||||
};
|
||||
|
||||
const _$ExtractStatusEnumMap = {
|
||||
ExtractStatus.none: '',
|
||||
ExtractStatus.extracting: 'extracting',
|
||||
ExtractStatus.done: 'done',
|
||||
ExtractStatus.error: 'error',
|
||||
ExtractStatus.waitingParts: 'waitingParts',
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'update_check_extension_resp.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class UpdateCheckExtensionResp {
|
||||
String newVersion;
|
||||
|
||||
UpdateCheckExtensionResp({
|
||||
required this.newVersion,
|
||||
});
|
||||
|
||||
factory UpdateCheckExtensionResp.fromJson(Map<String, dynamic> json) =>
|
||||
_$UpdateCheckExtensionRespFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$UpdateCheckExtensionRespToJson(this);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'update_check_extension_resp.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
UpdateCheckExtensionResp _$UpdateCheckExtensionRespFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
UpdateCheckExtensionResp(
|
||||
newVersion: json['newVersion'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$UpdateCheckExtensionRespToJson(
|
||||
UpdateCheckExtensionResp instance) =>
|
||||
<String, dynamic>{
|
||||
'newVersion': instance.newVersion,
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'update_extension_settings.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class UpdateExtensionSettings {
|
||||
Map<String, dynamic> settings;
|
||||
|
||||
UpdateExtensionSettings({
|
||||
required this.settings,
|
||||
});
|
||||
|
||||
factory UpdateExtensionSettings.fromJson(Map<String, dynamic> json) =>
|
||||
_$UpdateExtensionSettingsFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$UpdateExtensionSettingsToJson(this);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'update_extension_settings.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
UpdateExtensionSettings _$UpdateExtensionSettingsFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
UpdateExtensionSettings(
|
||||
settings: json['settings'] as Map<String, dynamic>,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$UpdateExtensionSettingsToJson(
|
||||
UpdateExtensionSettings instance) =>
|
||||
<String, dynamic>{
|
||||
'settings': instance.settings,
|
||||
};
|
||||
Reference in new issue
Block a user