diff --git a/RELEASE_CHANGELOG.md b/RELEASE_CHANGELOG.md index 21e7bc4..82a7756 100644 --- a/RELEASE_CHANGELOG.md +++ b/RELEASE_CHANGELOG.md @@ -4,13 +4,24 @@ ### GUI -- 修复无法读取本地数据自动查询授权的问题 +- 使用随机可用端口进行授权 +- 修复了 Task 潜在的异常问题 +- 修复一个错误的日志输出 + +### CLI + +- 使用随机可用端口进行授权 + +### NyaLCF Core + +- 使用随机端口分配启动鉴权回调服务 ## 版本信息 - nyalcf_gui: 1.0.0 - nyalcf_cli: 1.0.0 - nyalcf_env: 2.0.0 -- nyalcf_core,nyalcf_inject: 2.0.0 +- nyalcf_core: 2.0.1 +- nyalcf_inject: 2.0.0 diff --git a/nyalcf_cli/lib/commands/authorize.dart b/nyalcf_cli/lib/commands/authorize.dart index 35f108e..03b6dfd 100644 --- a/nyalcf_cli/lib/commands/authorize.dart +++ b/nyalcf_cli/lib/commands/authorize.dart @@ -29,14 +29,14 @@ class Authorize implements Command { Future main(List args) async { final ApiClient api = ApiClient(); - await startHttpServer(); + final port = await startHttpServer(); Logger.info( 'Please open this link to authorize: ' 'http://dashboard.locyanfrp.cn/auth/oauth/authorize' '?app_id=1' '&scopes=User,Proxy,Sign' '&redirect_url=' - 'https%3A%2F%2Fdashboard.locyanfrp.cn%2Fcallback%2Fauth%2Foauth%2Flocalhost%3Fport%3D21131%26ssl%3Dfalse%26path%3D%2Foauth%2Fcallback', + 'https%3A%2F%2Fdashboard.locyanfrp.cn%2Fcallback%2Fauth%2Foauth%2Flocalhost%3Fport%3D$port%26ssl%3Dfalse%26path%3D%2Foauth%2Fcallback', ); Logger.write('Waiting callback...'); Future.doWhile(() async { @@ -77,12 +77,12 @@ class Authorize implements Command { _tokenStorage.setFrpToken(frpToken); } - Future startHttpServer() async { + Future startHttpServer() async { OAuth.initRoute( response: OAuthResponseBody(success: '授权成功', error: '授权失败'), callback: callback, ); - await OAuth.start(); + return await OAuth.start(); } void callback({String? refreshToken, String? error}) { diff --git a/nyalcf_cli/nyalcf_core_extend/pubspec.yaml b/nyalcf_cli/nyalcf_core_extend/pubspec.yaml index 2fa4ff5..dcc2246 100644 --- a/nyalcf_cli/nyalcf_core_extend/pubspec.yaml +++ b/nyalcf_cli/nyalcf_core_extend/pubspec.yaml @@ -1,6 +1,6 @@ name: nyalcf_core_extend description: "Nya LoCyanFrp! core extend module." -version: 2.0.0 +version: 2.0.1 homepage: https://nyalcf.1l1.icu publish_to: none diff --git a/nyalcf_cli/pubspec.yaml b/nyalcf_cli/pubspec.yaml index a0d4efe..01aa065 100644 --- a/nyalcf_cli/pubspec.yaml +++ b/nyalcf_cli/pubspec.yaml @@ -1,6 +1,6 @@ name: nyalcf description: "[CLI]The next generation of LoCyanFrp launcher." -version: 1.0.0+2 +version: 1.0.0+4 homepage: https://nyalcf.1l1.icu publish_to: none # repository: https://github.com/my_org/my_repo diff --git a/nyalcf_core/lib/network/server/oauth.dart b/nyalcf_core/lib/network/server/oauth.dart index cd85f7f..3faa263 100644 --- a/nyalcf_core/lib/network/server/oauth.dart +++ b/nyalcf_core/lib/network/server/oauth.dart @@ -20,7 +20,8 @@ class OAuth { }) { app.get('/oauth/callback', (Request request) { String? error = request.requestedUri.queryParameters['error']; - String? refreshToken = request.requestedUri.queryParameters['refresh_token']; + String? refreshToken = + request.requestedUri.queryParameters['refresh_token']; if (error != null) { callback(error: error); @@ -40,8 +41,9 @@ class OAuth { }); } - static start() async { - _server = await io.serve(app.call, 'localhost', 21131); + static Future start() async { + _server = await io.serve(app.call, 'localhost', 0); + return _server!.port; } static close() { diff --git a/nyalcf_core/lib/storages/stores/user_info_storage.dart b/nyalcf_core/lib/storages/stores/user_info_storage.dart index b5b79a0..5d0c029 100644 --- a/nyalcf_core/lib/storages/stores/user_info_storage.dart +++ b/nyalcf_core/lib/storages/stores/user_info_storage.dart @@ -22,8 +22,9 @@ class UserInfoStorage { /// 读取用户数据 static Future read() async { try { - final String result = - await File('$_path/session.json').readAsString(encoding: utf8); + final file = File('$_path/session.json'); + if (!await file.exists()) return null; + final String result = await file.readAsString(encoding: utf8); return UserInfoModel.fromJson(jsonDecode(result)); } catch (e, t) { Logger.error(e, t: t); diff --git a/nyalcf_core/pubspec.yaml b/nyalcf_core/pubspec.yaml index 6162979..9033b38 100644 --- a/nyalcf_core/pubspec.yaml +++ b/nyalcf_core/pubspec.yaml @@ -1,6 +1,6 @@ name: nyalcf_core description: 'Nya LoCyanFrp! core module.' -version: 2.0.0 +version: 2.0.1 homepage: https://nyalcf.1l1.icu publish_to: none # repository: https://github.com/my_org/my_repo diff --git a/nyalcf_gui/nyalcf_core_extend/lib/tasks/basic.dart b/nyalcf_gui/nyalcf_core_extend/lib/tasks/basic.dart index a05a81c..ffe6737 100644 --- a/nyalcf_gui/nyalcf_core_extend/lib/tasks/basic.dart +++ b/nyalcf_gui/nyalcf_core_extend/lib/tasks/basic.dart @@ -1,4 +1,4 @@ abstract class TaskBasic { - late Function? callback; + Function? callback; startUp({Function? callback}); } diff --git a/nyalcf_gui/nyalcf_core_extend/lib/tasks/update_proxies_list.dart b/nyalcf_gui/nyalcf_core_extend/lib/tasks/update_proxies_list.dart index f72ae8e..0303d61 100644 --- a/nyalcf_gui/nyalcf_core_extend/lib/tasks/update_proxies_list.dart +++ b/nyalcf_gui/nyalcf_core_extend/lib/tasks/update_proxies_list.dart @@ -32,7 +32,7 @@ class TaskUpdateProxiesList extends TaskBasic { return; } if (rs.statusCode == 200) { - final List> list = rs.data['data']['list']; + final List list = rs.data['data']['list']; final List proxies = []; for (Map proxy in list) { diff --git a/nyalcf_gui/nyalcf_core_extend/pubspec.yaml b/nyalcf_gui/nyalcf_core_extend/pubspec.yaml index ea31a38..cea663c 100644 --- a/nyalcf_gui/nyalcf_core_extend/pubspec.yaml +++ b/nyalcf_gui/nyalcf_core_extend/pubspec.yaml @@ -1,6 +1,6 @@ name: nyalcf_core_extend description: "Nya LoCyanFrp! core extend module." -version: 2.0.0 +version: 2.0.1 homepage: https://nyalcf.1l1.icu publish_to: none diff --git a/nyalcf_gui/nyalcf_ui/lib/views/auth/authorize.dart b/nyalcf_gui/nyalcf_ui/lib/views/auth/authorize.dart index d2302e5..9850436 100644 --- a/nyalcf_gui/nyalcf_ui/lib/views/auth/authorize.dart +++ b/nyalcf_gui/nyalcf_ui/lib/views/auth/authorize.dart @@ -108,18 +108,19 @@ class _AuthorizeState extends State { @override void initState() { - const url = 'https://dashboard.locyanfrp.cn/auth/oauth/authorize' - '?app_id=1' - '&scopes=User,Proxy,Sign' - '&redirect_url=' - 'https%3A%2F%2Fdashboard.locyanfrp.cn%2Fcallback%2Fauth%2Foauth%2Flocalhost%3Fport%3D21131%26ssl%3Dfalse%26path%3D%2Foauth%2Fcallback'; - launchUrl(Uri.parse(url)); OAuth.initRoute( response: OAuthResponseBody(success: '授权成功', error: '授权失败'), callback: ctr.callback, ); OAuth.close(); - OAuth.start(); + OAuth.start().then((port) { + final url = 'https://dashboard.locyanfrp.cn/auth/oauth/authorize' + '?app_id=1' + '&scopes=User,Proxy,Sign' + '&redirect_url=' + 'https%3A%2F%2Fdashboard.locyanfrp.cn%2Fcallback%2Fauth%2Foauth%2Flocalhost%3Fport%3D$port%26ssl%3Dfalse%26path%3D%2Foauth%2Fcallback'; + launchUrl(Uri.parse(url)); + }); super.initState(); } @@ -142,6 +143,7 @@ class _Controller extends GetxController { if (error != null) { this.error.value = error; } else { + OAuth.close(); ApiClient api = ApiClient(); message.value = '已取得返回数据,正在获取访问令牌,请稍后...'; final rs = await api diff --git a/nyalcf_gui/pubspec.yaml b/nyalcf_gui/pubspec.yaml index 1a8d90c..598cd60 100644 --- a/nyalcf_gui/pubspec.yaml +++ b/nyalcf_gui/pubspec.yaml @@ -1,6 +1,6 @@ name: nyalcf description: "[GUI]The next generation of LoCyanFrp launcher." -version: 1.0.0+3 +version: 1.0.0+4 homepage: https://nyalcf.1l1.icu publish_to: 'none'