Skip to content

Commit

Permalink
Frpc download mirror selector, request API to cancel token now when l…
Browse files Browse the repository at this point in the history
…ogout
  • Loading branch information
Muska-Ami committed Aug 19, 2024
1 parent 72247d1 commit c0e4079
Show file tree
Hide file tree
Showing 50 changed files with 402 additions and 254 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ The next generation of LoCyanFrp launcher.
#### 安装依赖

```shell
bash install-dependecy.sh
bash install-dependency.sh
```

### 感谢我们的开发者!是他们使NyaLCF变的更好!
Expand Down
File renamed without changes.
5 changes: 2 additions & 3 deletions nyalcf_cli/bin/nyalcf_cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import 'package:nyalcf/commands/config.dart';
import 'package:nyalcf/commands/download.dart';
import 'package:nyalcf/commands/login.dart';
import 'package:nyalcf/arguments.dart';
import 'package:nyalcf/commands/logout.dart';
import 'package:nyalcf/commands/start.dart';
import 'package:nyalcf/utils/path_provider.dart';
import 'package:nyalcf/utils/state.dart';
import 'package:nyalcf_core/storages/configurations/launcher_configuration_storage.dart';
import 'package:nyalcf_core/storages/injector.dart';
import 'package:nyalcf_core/storages/stores/user_info_storage.dart';
import 'package:nyalcf_core/utils/logger.dart';
import 'package:nyalcf_inject/nyalcf_inject.dart';

Expand Down Expand Up @@ -57,8 +57,7 @@ void main(List<String> arguments) async {
await Login().main(results.rest);
}
if (results.wasParsed('logout')) {
await UserInfoStorage.sigo();
Logger.info('Session data removed.');
await Logout().main(results.rest);
}

// 启动 Frpc
Expand Down
1 change: 0 additions & 1 deletion nyalcf_cli/lib/commands/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,4 @@ class Config implements CommandImplement {
return null;
}
}

}
6 changes: 3 additions & 3 deletions nyalcf_cli/lib/commands/download.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:io';

import 'package:dio/dio.dart';

import 'package:nyalcf/utils/state.dart';
import 'package:nyalcf/templates/command_implement.dart';
import 'package:nyalcf_core/network/dio/frpc/download_frpc.dart';
import 'package:nyalcf_core/utils/cpu_arch.dart';
Expand Down Expand Up @@ -57,7 +56,7 @@ class Download implements CommandImplement {
_cancelToken = CancelToken();
Logger.info('Starting frpc download...');

await DownloadFrpc().download(
await DownloadFrpc.download(
arch: _selectedArch,
platform: platform,
version: '0.51.3-3',
Expand All @@ -67,7 +66,8 @@ class Download implements CommandImplement {
useMirror: false,
);
stdout.write('\rPlease wait, extracting frpc...\n');
await FrpcArchive.unarchive(platform: platform, arch: _selectedArch, version: '0.51.3-3');
await FrpcArchive.unarchive(
platform: platform, arch: _selectedArch, version: '0.51.3-3');
} else {
Logger.error(
'Unsupported system! If you believe this is wrong, please provide arch manually in command.');
Expand Down
7 changes: 3 additions & 4 deletions nyalcf_cli/lib/commands/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import 'package:nyalcf_core/storages/stores/user_info_storage.dart';
import 'package:nyalcf_core/utils/logger.dart';

class Login implements CommandImplement {

@override
Future<void> main(List<String> args) async {
if (args.length == 2) {
final res = await LoginAuth().requestLogin(args[0], args[1]);
final res = await LoginAuth.requestLogin(args[0], args[1]);
if (res.status) {
final UserInfoModel userInfo = res.data['user_info'];
Logger.info('Login successfully.');
Expand All @@ -19,7 +18,8 @@ class Login implements CommandImplement {
Logger.info('- email: ${userInfo.email}');
Logger.info('- login token: ${TextEncrypt.obscure(userInfo.token)}');
Logger.info('- frp token: ${TextEncrypt.obscure(userInfo.frpToken)}');
Logger.info('- speed limit: ${userInfo.inbound / 1024 * 8}Mbps/${userInfo.outbound / 1024 * 8}Mbps');
Logger.info(
'- speed limit: ${userInfo.inbound / 1024 * 8}Mbps/${userInfo.outbound / 1024 * 8}Mbps');
Logger.info('- traffic left: ${userInfo.traffic / 1024}GiB');
await UserInfoStorage.save(userInfo);
Logger.info('Session saved.');
Expand All @@ -28,5 +28,4 @@ class Login implements CommandImplement {
Logger.error('No valid arguments provided.');
}
}

}
14 changes: 14 additions & 0 deletions nyalcf_cli/lib/commands/logout.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'package:nyalcf/templates/command_implement.dart';
import 'package:nyalcf_core/storages/stores/user_info_storage.dart';
import 'package:nyalcf_core/utils/logger.dart';

class Logout implements CommandImplement {
@override
Future<void> main(List<String> args) async {
final userInfo = await UserInfoStorage.read();
await UserInfoStorage.sigo(userInfo?.user, userInfo?.token);

Logger.info('Session data removed.');
}

}
4 changes: 2 additions & 2 deletions nyalcf_cli/lib/commands/start.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Start implements CommandImplement {
final runPath = await FrpcStorage().getRunPath();

if (frpcPath != null) {
final process =await ProcessManager.newProcess(
final process = await ProcessManager.newProcess(
frpcPath: frpcPath,
runPath: runPath,
frpToken: user.frpToken,
Expand All @@ -39,7 +39,7 @@ class Start implements CommandImplement {

if (n == 2) {
for (var process in ProcessManager.processList) {
process.process.kill();
process.process.kill();
}
exit(0);
}
Expand Down
2 changes: 1 addition & 1 deletion nyalcf_cli/lib/templates/command_implement.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
abstract class CommandImplement {
/// 入口函数
void main(List<String> args);
}
}
5 changes: 3 additions & 2 deletions nyalcf_cli/lib/utils/path_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import 'dart:io';
import 'package:nyalcf_inject/nyalcf_inject.dart';

class PathProvider {
static final basicPath = '${Directory(Platform.resolvedExecutable).parent.path}/.nyalcf';
static final basicPath =
'${Directory(Platform.resolvedExecutable).parent.path}/.nyalcf';

static Future<void> loadPath() async {
final cachePath = '$basicPath/cache';
Expand All @@ -20,4 +21,4 @@ class PathProvider {
setAppCachePath(cachePath);
setAppSupportPath(supportPath);
}
}
}
4 changes: 2 additions & 2 deletions nyalcf_cli/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,14 @@ packages:
path: "../nyalcf_core"
relative: true
source: path
version: "1.0.3"
version: "1.0.6"
nyalcf_inject:
dependency: "direct main"
description:
path: "../nyalcf_inject"
relative: true
source: path
version: "0.1.3"
version: "0.1.5"
package_config:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion nyalcf_core/lib/models/process_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ class ProcessModel {
String toString() {
return '[$proxyId] PID: ${process.pid}';
}
}
}
4 changes: 2 additions & 2 deletions nyalcf_core/lib/models/user_info_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class UserInfoModel {
inbound = json['inbound'],
outbound = json['outbound'],
frpToken = json['frp_token'],
traffic = json['traffic'];
traffic = num.parse(json['traffic']);

Map<String, dynamic> toJson() => {
'username': user,
Expand All @@ -37,6 +37,6 @@ class UserInfoModel {
'inbound': inbound,
'outbound': outbound,
'frp_token': frpToken,
'traffic': traffic
'traffic': traffic.toString()
};
}
1 change: 1 addition & 0 deletions nyalcf_core/lib/network/dio/auth/auth.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
library auth;

export 'login_auth.dart';
export 'logout_auth.dart';
export 'register_auth.dart';
export 'user_auth.dart';
4 changes: 2 additions & 2 deletions nyalcf_core/lib/network/dio/auth/login_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import 'package:nyalcf_core/network/dio/basic_config.dart';
import 'package:nyalcf_core/network/response_type.dart';

class LoginAuth {
final instance = dio.Dio(options);
static final instance = dio.Dio(options);

Future<Response> requestLogin(user, password) async {
static Future<Response> requestLogin(user, password) async {
dio.FormData data =
dio.FormData.fromMap({'username': user, 'password': password});
try {
Expand Down
54 changes: 54 additions & 0 deletions nyalcf_core/lib/network/dio/auth/logout_auth.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import 'package:dio/dio.dart' as dio;

import 'package:nyalcf_core/network/dio/basic_config.dart';
import 'package:nyalcf_core/network/response_type.dart';
import 'package:nyalcf_core/utils/logger.dart';

class LogoutAuth {
static final instance = dio.Dio(options);

static Future<Response> requestLogout(user, token) async {
Map<String, dynamic> paramsMap = {};
paramsMap['username'] = user;

Map<String, dynamic> optionsMap = {};
optionsMap['Content-Type'] =
'application/x-www-form-urlencoded;charset=UTF-8';
optionsMap['Authorization'] = 'Bearer $token';
options = options.copyWith(headers: optionsMap);

try {
Logger.debug('Logout: $user / $token');
final response = await instance.delete('$apiV2Url/users/reset/token/single', queryParameters: paramsMap);
Map<String, dynamic> responseJson = response.data;
Logger.debug(responseJson);
final resData = responseJson['data'];
if (responseJson['status'] == 200) {
return Response(
status: true,
message: 'OK',
data: {
'origin_response': resData,
},
);
} else {
return Response(
status: false,
message: resData['msg'] ?? responseJson['status'],
data: {
'origin_response': resData,
},
);
}
} catch (ex, st) {
Logger.error(ex, t: st);
return Response(
status: false,
message: ex.toString(),
data: {
'error': ex,
},
);
}
}
}
4 changes: 2 additions & 2 deletions nyalcf_core/lib/network/dio/auth/register_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import 'package:nyalcf_core/network/dio/basic_config.dart';
import 'package:nyalcf_core/network/response_type.dart';

class RegisterAuth {
final instance = dio.Dio(options);
static final instance = dio.Dio(options);

Future<Response> requestRegister(
static Future<Response> requestRegister(
user, password, confirmPassword, email, verify, qq) async {
dio.FormData data = dio.FormData.fromMap({
'username': user,
Expand Down
4 changes: 2 additions & 2 deletions nyalcf_core/lib/network/dio/auth/user_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import 'package:nyalcf_core/network/dio/basic_config.dart';
import 'package:nyalcf_core/network/response_type.dart';

class UserAuth {
final instance = dio.Dio(options);
static final instance = dio.Dio(options);

Future<Response> checkToken(token) async {
static Future<Response> checkToken(token) async {
try {
Logger.info('Check token if is valid');
Map<String, dynamic> paramsMap = {};
Expand Down
8 changes: 4 additions & 4 deletions nyalcf_core/lib/network/dio/basic_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const apiV2Url = 'https://api-v2.locyanfrp.cn/api/v2';
const frpcConfigUrl = 'https://lcf-frps-api.locyanfrp.cn/api';
const githubApiUrl = 'https://api-gh.1l1.icu';
const githubMainUrl = 'https://github.com';
const githubMirrorsUrl = 'https://proxy-gh.1l1.icu/https://github.com';
const locyanMirrorsFrpcFormat = 'https://mirrors.locyan.cn/github-releases/' +
'{owner}/{repo}/{release_name}/frp_LoCyanFrp-{version_pure}_{platform}' +
'_{architecture}.{suffix}';
// const githubMirrorsUrl = 'https://proxy-gh.1l1.icu/https://github.com';
// const locyanMirrorsFrpcFormat = 'https://mirrors.locyan.cn/github-releases/' +
// '{owner}/{repo}/{release_name}/frp_LoCyanFrp-{version_pure}_{platform}' +
// '_{architecture}.{suffix}';
Loading

0 comments on commit c0e4079

Please sign in to comment.