Skip to content

Commit

Permalink
[+*]Use '' instead "" & Auto auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Muska-Ami committed Dec 19, 2023
1 parent 9590f90 commit 1a57e12
Show file tree
Hide file tree
Showing 29 changed files with 313 additions and 231 deletions.
44 changes: 0 additions & 44 deletions lib/cache/InfoCache.dart

This file was deleted.

2 changes: 1 addition & 1 deletion lib/controller/dpanel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:get/get.dart';
import 'package:nyalcf/dio/other/announcement.dart';

class DPanelController extends GetxController {
var announcement = "喵喵喵?正在请求捏".obs;
var announcement = '喵喵喵?正在请求捏'.obs;

load() async {
announcement.value = await AnnouncementDio().get();
Expand Down
8 changes: 4 additions & 4 deletions lib/controller/dsetting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';

class DSettingController extends GetxController {
var _frpc_version = "".obs;
var _frpc_version = ''.obs;
var frpc_version_widgets = <DropdownMenuItem>[].obs;
var frpc_version_value = 0.obs;

load() {
frpc_version_widgets.value = <DropdownMenuItem>[
DropdownMenuItem(
child: Text("0.51.3"),
child: Text('0.51.3'),
value: 0,
),
DropdownMenuItem(
child: Text("0.51.0"),
child: Text('0.51.0'),
value: 1,
),
DropdownMenuItem(
child: Text("0.48.1"),
child: Text('0.48.1'),
value: 2,
),
];
Expand Down
10 changes: 5 additions & 5 deletions lib/controller/frpc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ import 'package:nyalcf/util/FileIO.dart';
class FrpcController extends GetxController {
final _support_path = FileIO.support_path;
var exist = false.obs;
var version = "".obs;
var version = ''.obs;

load() async {
exist.value = await file().exists();
}

/// 获取Frpc文件对象
File file() {
String path = "";
String path = '';
_support_path.then((value) {
path = value + "/frpc/${version}/frpc";
path = value + '/frpc/${version}/frpc';
});
if (Platform.isWindows) path += ".exe";
if (Platform.isWindows) path += '.exe';
return File(path);
}

Future<String> getVersion() async {
String path = await _support_path + "/frpc/frpc_info.json";
String path = await _support_path + '/frpc/frpc_info.json';
return await File(path).readAsString();
}
}
38 changes: 19 additions & 19 deletions lib/controller/proxies.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class ProxiesController extends GetxController {
final FrpcController f_c = Get.find();
var proxiesListWidgets = <DataRow>[
DataRow(cells: <DataCell>[
DataCell(Text("加载中喵喵喵?")),
DataCell(Text("-")),
DataCell(Text("-")),
DataCell(Text("-")),
DataCell(Text("-")),
DataCell(Text("-")),
DataCell(Text("-")),
DataCell(Text('加载中喵喵喵?')),
DataCell(Text('-')),
DataCell(Text('-')),
DataCell(Text('-')),
DataCell(Text('-')),
DataCell(Text('-')),
DataCell(Text('-')),
])
].obs;

Expand All @@ -38,21 +38,21 @@ class ProxiesController extends GetxController {
DataCell(SelectableText(element.proxy_type)),
DataCell(SelectableText(element.local_ip)),
DataCell(
SelectableText("${element.local_port} -> ${element.remote_port}"),
SelectableText('${element.local_port} -> ${element.remote_port}'),
),
DataCell(
Row(
children: [
IconButton(
icon: Icon(Icons.play_circle),
onPressed: () {
Process.run("cmd.exe", ["start", "cmd.exe"]);
Process.run('cmd.exe', ['start', 'cmd.exe']);
},
),
IconButton(
icon: Icon(Icons.edit),
onPressed: () {
Get.snackbar("谁让你点了?", "还没写,爬去面板编辑喵喵喵!");
Get.snackbar('谁让你点了?', '还没写,爬去面板编辑喵喵喵!');
},
),
],
Expand All @@ -63,18 +63,18 @@ class ProxiesController extends GetxController {
} else {
proxiesListWidgets.value = <DataRow>[
DataRow(cells: <DataCell>[
DataCell(Text("获取失败,请尝试刷新一下~")),
DataCell(Text("-")),
DataCell(Text("-")),
DataCell(Text("-")),
DataCell(Text("-")),
DataCell(Text("-")),
DataCell(Text("-")),
DataCell(Text('获取失败,请尝试刷新一下~')),
DataCell(Text('-')),
DataCell(Text('-')),
DataCell(Text('-')),
DataCell(Text('-')),
DataCell(Text('-')),
DataCell(Text('-')),
])
];
Get.snackbar(
"发生错误",
"无法获取隧道列表信息: ${proxies}",
'发生错误',
'无法获取隧道列表信息: ${proxies}',
snackPosition: SnackPosition.BOTTOM,
animationDuration: Duration(milliseconds: 300),
);
Expand Down
10 changes: 6 additions & 4 deletions lib/controller/user.dart
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
import 'package:get/get.dart';
import 'package:nyalcf/cache/InfoCache.dart';
import 'package:nyalcf/model/User.dart';
import 'package:nyalcf/prefs/UserInfoPrefs.dart';

class UserController extends GetxController {
var user = "".obs;
var email = "".obs;
var user = ''.obs;
var email = ''.obs;
var token = ''.obs;
var avatar = 'https://cravatar.cn/avatar/'.obs;
var inbound = 0.obs;
var outbound = 0.obs;
var frp_token = ''.obs;
var traffic = 0.obs;

var welcomeText = '好'.obs;

load() async {
User userinfo = await InfoCache.getInfo();
User userinfo = await UserInfoPrefs.getInfo();
user.value = userinfo.user;
email.value = userinfo.email;
token.value = userinfo.token;
avatar.value = userinfo.avatar;
inbound.value = userinfo.inbound;
outbound.value = userinfo.outbound;
frp_token.value = userinfo.frp_token;
traffic.value = userinfo.traffic;

int hour = DateTime.now().hour;

Expand Down
24 changes: 24 additions & 0 deletions lib/dio/auth/check.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:dio/dio.dart';

import '../basicConfig.dart';

class CheckDio {
final dio = Dio();

Future<bool> checkToken(token) async {
try {
print('Check token if is valid');
Map<String, dynamic> params_map = Map();
params_map['token'] = token;

final res = await dio.get('${basicConfig.api_v2_url}/check/token',
queryParameters: params_map);
print(res.data);

return true;
} catch (e) {
print(e);
return false;
}
}
}
20 changes: 10 additions & 10 deletions lib/dio/auth/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ class LoginDio {
final dio = Dio();

Future<dynamic> requestLogin(user, password) async {
FormData data = FormData.fromMap({"username": user, "password": password});
FormData data = FormData.fromMap({'username': user, 'password': password});
try {
print("Post login: ${user} / ${password}");
print('Post login: ${user} / ${password}');
final response =
await dio.post("${basicConfig.api_v2_url}/users/login", data: data);
await dio.post('${basicConfig.api_v2_url}/users/login', data: data);
Map<String, dynamic> responseJson = response.data;
print(responseJson);
final resData = responseJson["data"];
if (responseJson["status"] == 200) {
final resData = responseJson['data'];
if (responseJson['status'] == 200) {
final userInfo = User(
user: resData["username"],
email: resData["email"],
token: resData["token"],
avatar: resData["avatar"],
user: resData['username'],
email: resData['email'],
token: resData['token'],
avatar: resData['avatar'],
inbound: resData['inbound'],
outbound: resData['outbound'],
frp_token: resData['frp_token'],
traffic: resData['traffic']);
return userInfo;
} else {
return resData["msg"] ?? responseJson["status"];
return resData['msg'] ?? responseJson['status'];
}
} catch (ex) {
print(ex);
Expand Down
8 changes: 4 additions & 4 deletions lib/dio/basicConfig.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class basicConfig {
static final api_v1_url = "https://api.locyanfrp.cn";
static final api_v2_url = "https://api-v2.locyanfrp.cn/api/v2";
static final github_api_url = "https://api.github.com";
static final frpc_release_repo = "LoCyan-Team/LoCyanFrpPureApp";
static final api_v1_url = 'https://api.locyanfrp.cn';
static final api_v2_url = 'https://api-v2.locyanfrp.cn/api/v2';
static final github_api_url = 'https://api.github.com';
static final frpc_release_repo = 'LoCyan-Team/LoCyanFrpPureApp';
}
6 changes: 3 additions & 3 deletions lib/dio/frpc/download.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class FrpcDownloadDio {
/*
Future<FrpcList> fetchVersion() async {
final response =
await dio.get("${basicConfig.github_api_url}/repos/${basicConfig.frpc_release_repo}/releases/latest");
await dio.get('${basicConfig.github_api_url}/repos/${basicConfig.frpc_release_repo}/releases/latest');
}
*/
Expand All @@ -19,8 +19,8 @@ class FrpcDownloadDio {
required CancelToken cancelToken}) async {
try {
return await dio.download(
"https://github.com/LoCyan-Team/LoCyanFrpPureApp/releases/download/v0.51.3/frp_LoCyanFrp-0.51.3_windows_amd64.zip",
"${FileIO.cache_path}/frpc.zip",
'https://github.com/LoCyan-Team/LoCyanFrpPureApp/releases/download/v0.51.3/frp_LoCyanFrp-0.51.3_windows_amd64.zip',
'${FileIO.cache_path}/frpc.zip',
cancelToken: cancelToken,
onReceiveProgress: progressCallback);
} on DioException {
Expand Down
6 changes: 3 additions & 3 deletions lib/dio/other/announcement.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ class AnnouncementDio {

Future<String> get() async {
try {
print("Get announcement");
print('Get announcement');
final response =
await dio.get("${basicConfig.api_v1_url}/App/GetBroadCast");
await dio.get('${basicConfig.api_v1_url}/App/GetBroadCast');
print(response);
final Map<String, dynamic> resData = response.data;
return resData['broadcast'];
} catch (ex) {
print(ex);
return "获取失败了啊呜,可能是猫猫把网线偷走了~";
return '获取失败了啊呜,可能是猫猫把网线偷走了~';
}
}
}
8 changes: 4 additions & 4 deletions lib/dio/other/donateList.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ class DonateList {

Future<dynamic> random() async {
try {
print("Get donate list");
print('Get donate list');
final response =
await dio.get("${basicConfig.api_v1_url}/Donate/GetDonateList");
await dio.get('${basicConfig.api_v1_url}/Donate/GetDonateList');
List<Map<String, dynamic>> responseJson = response.data;
print(responseJson);
final Map<String, dynamic> resData =
responseJson[Random().nextInt(responseJson.length - 1)];
final donateInfo = DonateRandom(
username: resData["username"], message: resData["message"]);
username: resData['username'], message: resData['message']);
return donateInfo;
} catch (ex) {
print(ex);
return DonateRandom(username: "N", message: "A");
return DonateRandom(username: 'N', message: 'A');
}
}
}
2 changes: 1 addition & 1 deletion lib/dio/proxies/get.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ProxiesGetDio {
//print(options.headers?.keys);

var response = await dio.get(
"${basicConfig.api_v2_url}/proxies/getlist",
'${basicConfig.api_v2_url}/proxies/getlist',
queryParameters: params_map,
options: options,
);
Expand Down
14 changes: 9 additions & 5 deletions lib/io/userInfoStorage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@ class UserInfoStorage {
*/
static Future<void> save(User data) async {
final String write_data = jsonEncode(data);
await File("${await path}/session.json")
await File('${await path}/session.json')
.writeAsString(write_data, encoding: utf8);
}

/**
* 读取数据
*/
static Future<User> read() async {
final String result =
await File("${await path}/session.json").readAsString(encoding: utf8);
return User.fromJson(jsonDecode(result));
static Future<User?> read() async {
try {
final String result =
await File('${await path}/session.json').readAsString(encoding: utf8);
return User.fromJson(jsonDecode(result));
} catch (e) {
return null;
}
}
}
Loading

0 comments on commit 1a57e12

Please sign in to comment.