mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-08 01:20:27 +00:00
feat: extension support (#78)
This commit is contained in:
118 files changed
+6971
-780
No files matched your search
@@ -9,12 +9,12 @@ part 'create_task.g.dart';
|
||||
class CreateTask {
|
||||
String? rid;
|
||||
Request? req;
|
||||
Options? opts;
|
||||
Options? opt;
|
||||
|
||||
CreateTask({
|
||||
this.rid,
|
||||
this.req,
|
||||
this.opts,
|
||||
this.opt,
|
||||
});
|
||||
|
||||
factory CreateTask.fromJson(
|
||||
|
||||
@@ -11,9 +11,9 @@ CreateTask _$CreateTaskFromJson(Map<String, dynamic> json) => CreateTask(
|
||||
req: json['req'] == null
|
||||
? null
|
||||
: Request.fromJson(json['req'] as Map<String, dynamic>),
|
||||
opts: json['opts'] == null
|
||||
opt: json['opt'] == null
|
||||
? null
|
||||
: Options.fromJson(json['opts'] as Map<String, dynamic>),
|
||||
: Options.fromJson(json['opt'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$CreateTaskToJson(CreateTask instance) {
|
||||
@@ -27,6 +27,6 @@ Map<String, dynamic> _$CreateTaskToJson(CreateTask instance) {
|
||||
|
||||
writeNotNull('rid', instance.rid);
|
||||
writeNotNull('req', instance.req?.toJson());
|
||||
writeNotNull('opts', instance.opts?.toJson());
|
||||
writeNotNull('opt', instance.opt?.toJson());
|
||||
return val;
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
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;
|
||||
|
||||
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,
|
||||
});
|
||||
|
||||
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,109 @@
|
||||
// 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,
|
||||
)..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;
|
||||
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,
|
||||
};
|
||||
@@ -8,12 +8,11 @@ part 'meta.g.dart';
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class Meta {
|
||||
Request req;
|
||||
Resource res;
|
||||
Resource? res;
|
||||
Options opts;
|
||||
|
||||
Meta({
|
||||
required this.req,
|
||||
required this.res,
|
||||
required this.opts,
|
||||
});
|
||||
|
||||
|
||||
@@ -8,12 +8,23 @@ part of 'meta.dart';
|
||||
|
||||
Meta _$MetaFromJson(Map<String, dynamic> json) => Meta(
|
||||
req: Request.fromJson(json['req'] as Map<String, dynamic>),
|
||||
res: Resource.fromJson(json['res'] 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) => <String, dynamic>{
|
||||
'req': instance.req.toJson(),
|
||||
'res': instance.res.toJson(),
|
||||
'opts': instance.opts.toJson(),
|
||||
};
|
||||
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;
|
||||
}
|
||||
@@ -10,7 +10,7 @@ class ResolveResult {
|
||||
Resource res;
|
||||
|
||||
ResolveResult({
|
||||
required this.id,
|
||||
this.id = "",
|
||||
required this.res,
|
||||
});
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ part of 'resolve_result.dart';
|
||||
|
||||
ResolveResult _$ResolveResultFromJson(Map<String, dynamic> json) =>
|
||||
ResolveResult(
|
||||
id: json['id'] as String,
|
||||
id: json['id'] as String? ?? "",
|
||||
res: Resource.fromJson(json['res'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:gopeed/api/model/request.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'resource.g.dart';
|
||||
@@ -7,17 +8,15 @@ class Resource {
|
||||
String name;
|
||||
int size;
|
||||
bool range;
|
||||
String rootDir;
|
||||
List<FileInfo> files;
|
||||
String hash;
|
||||
|
||||
Resource(
|
||||
{required this.name,
|
||||
required this.size,
|
||||
required this.range,
|
||||
required this.rootDir,
|
||||
{this.name = "",
|
||||
this.size = 0,
|
||||
this.range = false,
|
||||
required this.files,
|
||||
required this.hash});
|
||||
this.hash = ""});
|
||||
|
||||
factory Resource.fromJson(Map<String, dynamic> json) =>
|
||||
_$ResourceFromJson(json);
|
||||
@@ -25,18 +24,18 @@ class Resource {
|
||||
Map<String, dynamic> toJson() => _$ResourceToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class FileInfo {
|
||||
// String rootDir;
|
||||
String path;
|
||||
String name;
|
||||
int size;
|
||||
Request? req;
|
||||
|
||||
FileInfo({
|
||||
// required this.rootDir,
|
||||
required this.path,
|
||||
this.path = "",
|
||||
required this.name,
|
||||
required this.size,
|
||||
this.size = 0,
|
||||
this.req,
|
||||
});
|
||||
|
||||
factory FileInfo.fromJson(Map<String, dynamic> json) =>
|
||||
|
||||
@@ -7,33 +7,45 @@ part of 'resource.dart';
|
||||
// **************************************************************************
|
||||
|
||||
Resource _$ResourceFromJson(Map<String, dynamic> json) => Resource(
|
||||
name: json['name'] as String,
|
||||
size: json['size'] as int,
|
||||
range: json['range'] as bool,
|
||||
rootDir: json['rootDir'] as String,
|
||||
name: json['name'] as String? ?? "",
|
||||
size: json['size'] as int? ?? 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,
|
||||
hash: json['hash'] as String? ?? "",
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ResourceToJson(Resource instance) => <String, dynamic>{
|
||||
'name': instance.name,
|
||||
'size': instance.size,
|
||||
'range': instance.range,
|
||||
'rootDir': instance.rootDir,
|
||||
'files': instance.files.map((e) => e.toJson()).toList(),
|
||||
'hash': instance.hash,
|
||||
};
|
||||
|
||||
FileInfo _$FileInfoFromJson(Map<String, dynamic> json) => FileInfo(
|
||||
path: json['path'] as String,
|
||||
path: json['path'] as String? ?? "",
|
||||
name: json['name'] as String,
|
||||
size: json['size'] as int,
|
||||
size: json['size'] as int? ?? 0,
|
||||
req: json['req'] == null
|
||||
? null
|
||||
: Request.fromJson(json['req'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$FileInfoToJson(FileInfo instance) => <String, dynamic>{
|
||||
'path': instance.path,
|
||||
'name': instance.name,
|
||||
'size': instance.size,
|
||||
};
|
||||
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,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,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