Skip to content

Commit

Permalink
Bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Muska-Ami committed Dec 24, 2024
1 parent 5c898b7 commit 5596068
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 26 deletions.
6 changes: 1 addition & 5 deletions RELEASE_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@

### GUI

- 修改回调地址

### CLI

- 添加回调提示
- 修复无法读取本地数据自动查询授权的问题

## 版本信息

Expand Down
10 changes: 6 additions & 4 deletions nyalcf_cli/lib/commands/authorize.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ import 'dart:io';

// Package imports:
import 'package:crypto/crypto.dart';
// Project imports:
import 'package:nyalcf/templates/command.dart';
import 'package:nyalcf_core/models/user_info_model.dart';
import 'package:nyalcf_core/network/client/api/auth/oauth/access_token.dart';
import 'package:nyalcf_core/network/client/api/user/frp/token.dart'
as user_frp_token;
import 'package:nyalcf_core/network/client/api/user/info.dart' as user_info;
import 'package:nyalcf_core/network/client/api_client.dart';
import 'package:nyalcf_core/network/server/oauth.dart';
import 'package:nyalcf_core/storages/stores/user_info_storage.dart';
import 'package:nyalcf_core/utils/logger.dart';
import 'package:nyalcf_core_extend/storages/token_storage.dart';

// Project imports:
import 'package:nyalcf/templates/command.dart';

import 'package:nyalcf_core/network/client/api/user/frp/token.dart'
as user_frp_token;

class Authorize implements Command {
static final _tokenStorage = TokenStorage();

Expand Down
2 changes: 1 addition & 1 deletion nyalcf_core/lib/models/user_info_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class UserInfoModel {
avatar = json['avatar'],
inbound = json['inbound'],
outbound = json['outbound'],
traffic = num.parse(json['traffic']);
traffic = num.parse(json['traffic'].toString());

/// 转为 JSON 数据
Map<String, dynamic> toJson() => {
Expand Down
4 changes: 3 additions & 1 deletion nyalcf_core/lib/storages/stores/user_info_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:nyalcf_inject/nyalcf_inject.dart';

// Project imports:
import 'package:nyalcf_core/models/user_info_model.dart';
import 'package:nyalcf_core/utils/logger.dart';

class UserInfoStorage {
static final _path = appSupportPath;
Expand All @@ -24,7 +25,8 @@ class UserInfoStorage {
final String result =
await File('$_path/session.json').readAsString(encoding: utf8);
return UserInfoModel.fromJson(jsonDecode(result));
} catch (e) {
} catch (e, t) {
Logger.error(e, t: t);
return null;
}
}
Expand Down
8 changes: 5 additions & 3 deletions nyalcf_gui/nyalcf_ui/lib/views/auth/authorize.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Dart imports:
import 'dart:convert';

// Package imports:
import 'package:crypto/crypto.dart';
// Flutter imports:
import 'package:flutter/material.dart';

// Package imports:
import 'package:crypto/crypto.dart';
import 'package:get/get.dart';
import 'package:nyalcf_core/models/user_info_model.dart';
import 'package:nyalcf_core/network/client/api/auth/oauth/access_token.dart';
Expand All @@ -14,11 +15,12 @@ import 'package:nyalcf_core/network/client/api_client.dart';
import 'package:nyalcf_core/network/server/oauth.dart';
import 'package:nyalcf_core_extend/storages/prefs/token_info_prefs.dart';
import 'package:nyalcf_core_extend/storages/prefs/user_info_prefs.dart';
import 'package:url_launcher/url_launcher.dart';

// Project imports:
import 'package:nyalcf_ui/models/appbar_actions.dart';
import 'package:nyalcf_ui/widgets/nya_loading_circle.dart';
import 'package:nyalcf_ui/widgets/nya_scaffold.dart';
import 'package:url_launcher/url_launcher.dart';

class AuthorizeUI extends StatefulWidget {
const AuthorizeUI({super.key});
Expand Down
44 changes: 33 additions & 11 deletions nyalcf_gui/nyalcf_ui/lib/views/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
// Package imports:
import 'package:get/get.dart';
import 'package:nyalcf_core/models/user_info_model.dart';
import 'package:nyalcf_core/network/client/api/auth/oauth/access_token.dart';
import 'package:nyalcf_core/network/client/api/user/info.dart' as api_user;
import 'package:nyalcf_core/network/client/api_client.dart';
import 'package:nyalcf_core/storages/stores/user_info_storage.dart';
Expand Down Expand Up @@ -144,16 +145,30 @@ class HomeController extends GetxController {

// 加载控制器
load({bool force = false}) async {
authorizeFailed() {
UserInfoStorage.logout();
PrefsInstance.clear();
Get.snackbar(
'授权失效',
'请重新授权哦',
snackPosition: SnackPosition.BOTTOM,
animationDuration: const Duration(milliseconds: 300),
);
showAutoLoginWidget.value = false;
}

if (loaded && !force) return;
loaded = true;
// 读取用户信息
UserInfoModel? userInfo = await UserInfoStorage.read();
Logger.debug(userInfo);
if (userInfo != null) {
UserInfoPrefs.setInfo(userInfo);

showAutoLoginWidget.value = true;
// 刷新用户信息
final ApiClient api = ApiClient(accessToken: await TokenInfoPrefs.getAccessToken());
final ApiClient api =
ApiClient(accessToken: await TokenInfoPrefs.getAccessToken());

final rs = await api.get(api_user.GetInfo(userId: userInfo.id));
if (rs == null) {
Expand All @@ -171,18 +186,25 @@ class HomeController extends GetxController {
UserInfoPrefs.setTraffic(num.parse(rs.data['data']['traffic']));
UserInfoPrefs.setInbound(rs.data['data']['inbound']);
UserInfoPrefs.setOutbound(rs.data['data']['outbound']);
UserInfoPrefs.saveToFile();
break;
case 401:
UserInfoStorage.logout();
PrefsInstance.clear();
Get.snackbar(
'授权失效',
'请重新授权哦',
snackPosition: SnackPosition.BOTTOM,
animationDuration: const Duration(milliseconds: 300),
);
showAutoLoginWidget.value = false;
return;
final apix = ApiClient();
final refreshToken = await TokenInfoPrefs.getRefreshToken();
if (refreshToken != null) {
final rsAcc = await apix
.post(PostAccessToken(appId: 1, refreshToken: refreshToken));
if (rsAcc == null) {
authorizeFailed();
return;
}
TokenInfoPrefs.setAccessToken(rsAcc.data['data']['access_token']);
load(force: true);
return;
} else {
authorizeFailed();
return;
}
default:
Logger.warn(
'Check user token success but refresh user info failed.'
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+2
version: 1.0.0+3
homepage: https://nyalcf.1l1.icu
publish_to: 'none'

Expand Down

0 comments on commit 5596068

Please sign in to comment.