Skip to content

Commit

Permalink
feat(getAlistAdmin): Add password parsing
Browse files Browse the repository at this point in the history
The code listens to 'stderr' data and looks for the string "password:". If found, it splits the text and returns the password. The parsed password is then added to the output using the 'addOutput()' method.

#2
  • Loading branch information
Xmarmalade committed May 6, 2023
1 parent 19425da commit e8ef08c
Showing 1 changed file with 34 additions and 29 deletions.
63 changes: 34 additions & 29 deletions lib/provider/alist_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ class AlistNotifier extends StateNotifier<AlistState> {
var process = await Process.start('$workingDirectory\\alist.exe', alistArgs,
workingDirectory: workingDirectory);
process.stdout.listen((data) {
String text = TextUtils.stdDecode(data,false);
String text = TextUtils.stdDecode(data, false);
addOutput(text);
});
process.stderr.listen((data) {
String text = TextUtils.stdDecode(data,false);
String text = TextUtils.stdDecode(data, false);
addOutput(text);
});
}
Expand All @@ -57,7 +57,7 @@ class AlistNotifier extends StateNotifier<AlistState> {
state = state.copyWith(isRunning: false);
var process = await Process.start('taskkill', ['/f', '/im', 'alist.exe']);
process.stdout.listen((data) {
String text = TextUtils.stdDecode(data,true);
String text = TextUtils.stdDecode(data, true);
addOutput(text);
});
}
Expand All @@ -72,8 +72,10 @@ class AlistNotifier extends StateNotifier<AlistState> {
'$workingDirectory\\alist.exe', ['admin'],
workingDirectory: workingDirectory);
alistAdmin.stderr.listen((data) {
String text = TextUtils.stdDecode(data,false);
String text = TextUtils.stdDecode(data, false);
String password = text.split('password:')[1].trim();
addOutput(text);
addOutput(password);
});
}

Expand All @@ -83,7 +85,7 @@ class AlistNotifier extends StateNotifier<AlistState> {
'$workingDirectory\\alist.exe', ['version'],
workingDirectory: workingDirectory);
alistVersion.stdout.listen((data) {
String text = TextUtils.stdDecode(data,false);
String text = TextUtils.stdDecode(data, false);
if (text.contains('Version')) {
String versionInfo = text
.split('Go Version:')[1]
Expand All @@ -100,12 +102,12 @@ class AlistNotifier extends StateNotifier<AlistState> {
}

Future<void> fetchLatestVersion() async {
final response = await http.get(Uri.parse(
'https://api.github.com/repos/alist-org/alist/releases/latest'));
final json = jsonDecode(response.body) as Map<String, dynamic>;
final latest = json['tag_name'] as String;
state = state.copyWith(latestVersion: latest);
//print('Latest release: $latest');
final response = await http.get(Uri.parse(
'https://api.github.com/repos/alist-org/alist/releases/latest'));
final json = jsonDecode(response.body) as Map<String, dynamic>;
final latest = json['tag_name'] as String;
state = state.copyWith(latestVersion: latest);
//print('Latest release: $latest');
}

Future<void> isAlistRunning() async {
Expand All @@ -127,24 +129,27 @@ class AlistState {
final String currentVersion;
final String latestVersion;

AlistState(
{this.isRunning = false,
this.output = const [],
this.url = 'http://localhost:5244',
this.currentVersion = 'v1.0.0',
this.latestVersion = 'v1.0.0'});

AlistState copyWith(
{bool? isRunning,
List<String>? output,
String? url,
String? currentVersion,
String? latestVersion}) {
AlistState({
this.isRunning = false,
this.output = const [],
this.url = 'http://localhost:5244',
this.currentVersion = 'v1.0.0',
this.latestVersion = 'v1.0.0',
});

AlistState copyWith({
bool? isRunning,
List<String>? output,
String? url,
String? currentVersion,
String? latestVersion,
}) {
return AlistState(
isRunning: isRunning ?? this.isRunning,
output: output ?? this.output,
url: url ?? this.url,
currentVersion: currentVersion ?? this.currentVersion,
latestVersion: latestVersion ?? this.latestVersion);
isRunning: isRunning ?? this.isRunning,
output: output ?? this.output,
url: url ?? this.url,
currentVersion: currentVersion ?? this.currentVersion,
latestVersion: latestVersion ?? this.latestVersion,
);
}
}

0 comments on commit e8ef08c

Please # to comment.