Skip to content

Commit

Permalink
Merge pull request #224 from Muska-Ami/dev
Browse files Browse the repository at this point in the history
Ver. 1.0.0+4
  • Loading branch information
Muska-Ami authored Jan 6, 2025
2 parents 3c06d77 + 05daefa commit f29f69a
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 25 deletions.
15 changes: 13 additions & 2 deletions RELEASE_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<!-- Some change log here -->
8 changes: 4 additions & 4 deletions nyalcf_cli/lib/commands/authorize.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ class Authorize implements Command {
Future<void> main(List<String> 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 {
Expand Down Expand Up @@ -77,12 +77,12 @@ class Authorize implements Command {
_tokenStorage.setFrpToken(frpToken);
}

Future<void> startHttpServer() async {
Future<int> startHttpServer() async {
OAuth.initRoute(
response: OAuthResponseBody(success: '授权成功', error: '授权失败'),
callback: callback,
);
await OAuth.start();
return await OAuth.start();
}

void callback({String? refreshToken, String? error}) {
Expand Down
2 changes: 1 addition & 1 deletion nyalcf_cli/nyalcf_core_extend/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion nyalcf_cli/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 5 additions & 3 deletions nyalcf_core/lib/network/server/oauth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -40,8 +41,9 @@ class OAuth {
});
}

static start() async {
_server = await io.serve(app.call, 'localhost', 21131);
static Future<int> start() async {
_server = await io.serve(app.call, 'localhost', 0);
return _server!.port;
}

static close() {
Expand Down
5 changes: 3 additions & 2 deletions nyalcf_core/lib/storages/stores/user_info_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ class UserInfoStorage {
/// 读取用户数据
static Future<UserInfoModel?> 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);
Expand Down
2 changes: 1 addition & 1 deletion nyalcf_core/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion nyalcf_gui/nyalcf_core_extend/lib/tasks/basic.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
abstract class TaskBasic {
late Function? callback;
Function? callback;
startUp({Function? callback});
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class TaskUpdateProxiesList extends TaskBasic {
return;
}
if (rs.statusCode == 200) {
final List<Map<String, dynamic>> list = rs.data['data']['list'];
final List<dynamic> list = rs.data['data']['list'];

final List<ProxyInfoModel> proxies = [];
for (Map<String, dynamic> proxy in list) {
Expand Down
2 changes: 1 addition & 1 deletion nyalcf_gui/nyalcf_core_extend/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand Down
16 changes: 9 additions & 7 deletions nyalcf_gui/nyalcf_ui/lib/views/auth/authorize.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,19 @@ class _AuthorizeState extends State<AuthorizeUI> {

@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();
}

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion nyalcf_gui/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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'

Expand Down

0 comments on commit f29f69a

Please sign in to comment.