Remove unused clash api
This commit is contained in:
@@ -1,145 +0,0 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import 'package:hiddify/domain/clash/clash.dart';
|
||||
import 'package:hiddify/domain/constants.dart';
|
||||
import 'package:hiddify/utils/utils.dart';
|
||||
import 'package:web_socket_channel/web_socket_channel.dart';
|
||||
|
||||
class ClashApi with InfraLogger {
|
||||
ClashApi(int port) : address = "${Constants.localHost}:$port";
|
||||
|
||||
final String address;
|
||||
|
||||
late final _clashDio = Dio(
|
||||
BaseOptions(
|
||||
baseUrl: "http://$address",
|
||||
connectTimeout: const Duration(seconds: 3),
|
||||
receiveTimeout: const Duration(seconds: 10),
|
||||
sendTimeout: const Duration(seconds: 3),
|
||||
),
|
||||
);
|
||||
|
||||
TaskEither<String, List<ClashProxy>> getProxies() {
|
||||
return TaskEither(
|
||||
() async {
|
||||
final response = await _clashDio.get("/proxies");
|
||||
if (response.statusCode != 200 || response.data == null) {
|
||||
return left(response.statusMessage ?? "");
|
||||
}
|
||||
final proxies = ((jsonDecode(response.data! as String)
|
||||
as Map<String, dynamic>)["proxies"] as Map<String, dynamic>)
|
||||
.entries
|
||||
.map(
|
||||
(e) {
|
||||
final proxyMap = (e.value as Map<String, dynamic>)
|
||||
..putIfAbsent('name', () => e.key);
|
||||
return ClashProxy.fromJson(proxyMap);
|
||||
},
|
||||
);
|
||||
return right(proxies.toList());
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
TaskEither<String, Unit> changeProxy(String selectorName, String proxyName) {
|
||||
return TaskEither(
|
||||
() async {
|
||||
final response = await _clashDio.put(
|
||||
"/proxies/$selectorName",
|
||||
data: {"name": proxyName},
|
||||
);
|
||||
if (response.statusCode != HttpStatus.noContent) {
|
||||
return left(response.statusMessage ?? "");
|
||||
}
|
||||
return right(unit);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
TaskEither<String, int> getProxyDelay(
|
||||
String name,
|
||||
String url, {
|
||||
Duration timeout = const Duration(seconds: 10),
|
||||
}) {
|
||||
return TaskEither(
|
||||
() async {
|
||||
final response = await _clashDio.get<Map>(
|
||||
"/proxies/$name/delay",
|
||||
queryParameters: {
|
||||
"timeout": timeout.inMilliseconds,
|
||||
"url": url,
|
||||
},
|
||||
);
|
||||
if (response.statusCode != 200 || response.data == null) {
|
||||
return left(response.statusMessage ?? "");
|
||||
}
|
||||
return right(response.data!["delay"] as int);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
TaskEither<String, ClashConfig> getConfigs() {
|
||||
return TaskEither(
|
||||
() async {
|
||||
final response = await _clashDio.get("/configs");
|
||||
if (response.statusCode != 200 || response.data == null) {
|
||||
return left(response.statusMessage ?? "");
|
||||
}
|
||||
final config =
|
||||
ClashConfig.fromJson(response.data as Map<String, dynamic>);
|
||||
return right(config);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
TaskEither<String, Unit> updateConfigs(String path) {
|
||||
return TaskEither.of(unit);
|
||||
}
|
||||
|
||||
TaskEither<String, Unit> patchConfigs(ClashConfig config) {
|
||||
return TaskEither(
|
||||
() async {
|
||||
final response = await _clashDio.patch(
|
||||
"/configs",
|
||||
data: config.toJson(),
|
||||
);
|
||||
if (response.statusCode != HttpStatus.noContent) {
|
||||
return left(response.statusMessage ?? "");
|
||||
}
|
||||
return right(unit);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Stream<ClashLog> watchLogs(LogLevel level) {
|
||||
return const Stream.empty();
|
||||
}
|
||||
|
||||
Stream<ClashTraffic> watchTraffic() {
|
||||
final channel = WebSocketChannel.connect(
|
||||
Uri.parse("ws://$address/traffic"),
|
||||
);
|
||||
return channel.stream.map(
|
||||
(event) {
|
||||
return ClashTraffic.fromJson(
|
||||
jsonDecode(event as String) as Map<String, dynamic>,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
TaskEither<String, ClashTraffic> getTraffic() {
|
||||
return TaskEither(
|
||||
() async {
|
||||
final response = await _clashDio.get<Map<String, dynamic>>("/traffic");
|
||||
if (response.statusCode != 200 || response.data == null) {
|
||||
return left(response.statusMessage ?? "");
|
||||
}
|
||||
return right(ClashTraffic.fromJson(response.data!));
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,11 @@ import 'dart:io';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:hiddify/core/core_providers.dart';
|
||||
import 'package:hiddify/core/prefs/general_prefs.dart';
|
||||
import 'package:hiddify/data/api/clash_api.dart';
|
||||
import 'package:hiddify/data/local/database.dart';
|
||||
import 'package:hiddify/data/repository/app_repository_impl.dart';
|
||||
import 'package:hiddify/data/repository/config_options_store.dart';
|
||||
import 'package:hiddify/data/repository/repository.dart';
|
||||
import 'package:hiddify/domain/app/app.dart';
|
||||
import 'package:hiddify/domain/constants.dart';
|
||||
import 'package:hiddify/domain/core_facade.dart';
|
||||
import 'package:hiddify/domain/singbox/singbox.dart';
|
||||
import 'package:hiddify/features/geo_asset/data/geo_asset_data_providers.dart';
|
||||
@@ -51,9 +49,6 @@ Dio dio(DioRef ref) {
|
||||
AppRepository appRepository(AppRepositoryRef ref) =>
|
||||
AppRepositoryImpl(ref.watch(dioProvider));
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
ClashApi clashApi(ClashApiRef ref) => ClashApi(Defaults.clashApiPort);
|
||||
|
||||
@riverpod
|
||||
Future<ConfigOptions> configOptions(ConfigOptionsRef ref) async {
|
||||
final geoAssets = await ref
|
||||
@@ -86,7 +81,6 @@ CoreFacade coreFacade(CoreFacadeRef ref) => CoreFacadeImpl(
|
||||
ref.watch(geoAssetPathResolverProvider),
|
||||
ref.watch(profilePathResolverProvider),
|
||||
ref.watch(platformServicesProvider),
|
||||
ref.watch(clashApiProvider),
|
||||
ref.read(debugModeNotifierProvider),
|
||||
() => ref.read(configOptionsProvider.future),
|
||||
);
|
||||
|
||||
@@ -2,11 +2,8 @@ import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import 'package:hiddify/data/api/clash_api.dart';
|
||||
import 'package:hiddify/data/repository/exception_handlers.dart';
|
||||
import 'package:hiddify/domain/clash/clash.dart';
|
||||
import 'package:hiddify/domain/connectivity/connection_status.dart';
|
||||
import 'package:hiddify/domain/constants.dart';
|
||||
import 'package:hiddify/domain/core_facade.dart';
|
||||
import 'package:hiddify/domain/core_service_failure.dart';
|
||||
import 'package:hiddify/domain/singbox/singbox.dart';
|
||||
@@ -24,7 +21,6 @@ class CoreFacadeImpl with ExceptionHandler, InfraLogger implements CoreFacade {
|
||||
this.geoAssetPathResolver,
|
||||
this.profilePathResolver,
|
||||
this.platformServices,
|
||||
this.clash,
|
||||
this.debug,
|
||||
this.configOptions,
|
||||
);
|
||||
@@ -34,7 +30,6 @@ class CoreFacadeImpl with ExceptionHandler, InfraLogger implements CoreFacade {
|
||||
final GeoAssetPathResolver geoAssetPathResolver;
|
||||
final ProfilePathResolver profilePathResolver;
|
||||
final PlatformServices platformServices;
|
||||
final ClashApi clash;
|
||||
final bool debug;
|
||||
final Future<ConfigOptions> Function() configOptions;
|
||||
|
||||
@@ -263,67 +258,6 @@ class CoreFacadeImpl with ExceptionHandler, InfraLogger implements CoreFacade {
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
TaskEither<CoreServiceFailure, ClashConfig> getConfigs() {
|
||||
return exceptionHandler(
|
||||
() async => clash.getConfigs().mapLeft(CoreServiceFailure.other).run(),
|
||||
CoreServiceFailure.unexpected,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
TaskEither<CoreServiceFailure, Unit> patchOverrides(ClashConfig overrides) {
|
||||
return exceptionHandler(
|
||||
() async =>
|
||||
clash.patchConfigs(overrides).mapLeft(CoreServiceFailure.other).run(),
|
||||
CoreServiceFailure.unexpected,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
TaskEither<CoreServiceFailure, List<ClashProxy>> getProxies() {
|
||||
return exceptionHandler(
|
||||
() async => clash.getProxies().mapLeft(CoreServiceFailure.other).run(),
|
||||
CoreServiceFailure.unexpected,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
TaskEither<CoreServiceFailure, Unit> changeProxy(
|
||||
String selectorName,
|
||||
String proxyName,
|
||||
) {
|
||||
return exceptionHandler(
|
||||
() async => clash
|
||||
.changeProxy(selectorName, proxyName)
|
||||
.mapLeft(CoreServiceFailure.other)
|
||||
.run(),
|
||||
CoreServiceFailure.unexpected,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<Either<CoreServiceFailure, ClashTraffic>> watchTraffic() {
|
||||
return clash.watchTraffic().handleExceptions(CoreServiceFailure.unexpected);
|
||||
}
|
||||
|
||||
@override
|
||||
TaskEither<CoreServiceFailure, int> testDelay(
|
||||
String proxyName, {
|
||||
String testUrl = Defaults.connectionTestUrl,
|
||||
}) {
|
||||
return exceptionHandler(
|
||||
() async {
|
||||
final result = clash
|
||||
.getProxyDelay(proxyName, testUrl)
|
||||
.mapLeft(CoreServiceFailure.other)
|
||||
.run();
|
||||
return result;
|
||||
},
|
||||
CoreServiceFailure.unexpected,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<ConnectionStatus> watchConnectionStatus() =>
|
||||
singbox.watchConnectionStatus();
|
||||
|
||||
Reference in New Issue
Block a user