mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-18 07:44:26 +01:00
@@ -1,4 +1,5 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:server_box/core/utils/proxy_command_executor.dart' show ProxyCommandException;
|
||||
|
||||
part 'proxy_command_config.freezed.dart';
|
||||
part 'proxy_command_config.g.dart';
|
||||
@@ -65,6 +66,12 @@ const Map<String, ProxyCommandConfig> proxyCommandPresets = {
|
||||
extension ProxyCommandConfigExtension on ProxyCommandConfig {
|
||||
/// Get the final command with placeholders replaced
|
||||
String getFinalCommand({required String hostname, required int port, required String user}) {
|
||||
if (!command.contains('%h') && !command.contains('%p') && !command.contains('%r')) {
|
||||
throw ProxyCommandException(
|
||||
message: 'Proxy command "$command" must include at least one placeholder (%h, %p, %r)',
|
||||
);
|
||||
}
|
||||
|
||||
var finalCommand = command;
|
||||
finalCommand = finalCommand.replaceAll('%h', hostname);
|
||||
finalCommand = finalCommand.replaceAll('%p', port.toString());
|
||||
|
||||
@@ -22,7 +22,7 @@ part 'server_private_info.g.dart';
|
||||
abstract class Spi with _$Spi {
|
||||
const Spi._();
|
||||
|
||||
@JsonSerializable(includeIfNull: false)
|
||||
@JsonSerializable(includeIfNull: false, explicitToJson: true)
|
||||
const factory Spi({
|
||||
required String name,
|
||||
required String ip,
|
||||
|
||||
@@ -237,7 +237,7 @@ return $default(_that.name,_that.ip,_that.port,_that.user,_that.pwd,_that.keyId,
|
||||
|
||||
/// @nodoc
|
||||
|
||||
@JsonSerializable(includeIfNull: false)
|
||||
@JsonSerializable(includeIfNull: false, explicitToJson: true)
|
||||
class _Spi extends Spi {
|
||||
const _Spi({required this.name, required this.ip, required this.port, required this.user, this.pwd, @JsonKey(name: 'pubKeyId') this.keyId, final List<String>? tags, this.alterUrl, this.autoConnect = true, this.jumpId, this.custom, this.wolCfg, final Map<String, String>? envs, @JsonKey(fromJson: Spi.parseId) this.id = '', this.customSystemType, final List<String>? disabledCmdTypes, this.proxyCommand}): _tags = tags,_envs = envs,_disabledCmdTypes = disabledCmdTypes,super._();
|
||||
factory _Spi.fromJson(Map<String, dynamic> json) => _$SpiFromJson(json);
|
||||
|
||||
@@ -52,13 +52,13 @@ Map<String, dynamic> _$SpiToJson(_Spi instance) => <String, dynamic>{
|
||||
'alterUrl': ?instance.alterUrl,
|
||||
'autoConnect': instance.autoConnect,
|
||||
'jumpId': ?instance.jumpId,
|
||||
'custom': ?instance.custom,
|
||||
'wolCfg': ?instance.wolCfg,
|
||||
'custom': ?instance.custom?.toJson(),
|
||||
'wolCfg': ?instance.wolCfg?.toJson(),
|
||||
'envs': ?instance.envs,
|
||||
'id': instance.id,
|
||||
'customSystemType': ?_$SystemTypeEnumMap[instance.customSystemType],
|
||||
'disabledCmdTypes': ?instance.disabledCmdTypes,
|
||||
'proxyCommand': ?instance.proxyCommand,
|
||||
'proxyCommand': ?instance.proxyCommand?.toJson(),
|
||||
};
|
||||
|
||||
const _$SystemTypeEnumMap = {
|
||||
|
||||
Reference in New Issue
Block a user