fix secure storage and release pipeline
All checks were successful
Release / meta (push) Successful in 19s
Release / android-build (push) Successful in 5m53s
Release / linux-build (push) Successful in 8m3s
Release / release-master (push) Successful in 2s
Release / release-dev (push) Successful in 32s

This commit is contained in:
2025-12-14 08:39:22 +00:00
parent 4d483495fc
commit 8116cfe7b1
3 changed files with 18 additions and 4 deletions

View File

@@ -107,7 +107,7 @@ jobs:
SUDO=""
fi
$SUDO apt-get update
$SUDO apt-get install -y unzip xz-utils zip libstdc++6 libglu1-mesa clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev curl jq
$SUDO apt-get install -y unzip xz-utils zip libstdc++6 libglu1-mesa clang cmake ninja-build pkg-config libgtk-3-dev libsecret-1-dev liblzma-dev curl jq
- name: Setup Flutter
uses: subosito/flutter-action@v2

View File

@@ -37,6 +37,7 @@ void main() {
ProxyProvider<AuthService, void>(
update: (_, auth, __) {
api.setTokenProvider(() => auth.token);
api.setUnauthorizedHandler(() => auth.handleTokenExpired());
},
),
ChangeNotifierProxyProvider<ApiService, DataService>(

View File

@@ -2,10 +2,12 @@ import 'dart:convert';
import 'package:http/http.dart' as http;
typedef TokenProvider = String? Function();
typedef UnauthorizedHandler = Future<void> Function();
class ApiService {
final String baseUrl;
TokenProvider? _getToken;
UnauthorizedHandler? _onUnauthorized;
ApiService({required this.baseUrl});
@@ -13,6 +15,10 @@ class ApiService {
_getToken = provider;
}
void setUnauthorizedHandler(UnauthorizedHandler handler) {
_onUnauthorized = handler;
}
Map<String, String> _buildHeaders(Map<String, String>? extra) {
final token = _getToken?.call();
final headers = {'accept': 'application/json', ...?extra};
@@ -85,12 +91,19 @@ class ApiService {
return {'Content-Type': 'application/json', if (extra != null) ...extra};
}
dynamic _processResponse(http.Response res) {
Future<dynamic> _processResponse(http.Response res) async {
final body = res.body.isNotEmpty ? jsonDecode(res.body) : null;
if (res.statusCode >= 200 && res.statusCode < 300) {
return body;
} else {
throw Exception('API error ${res.statusCode}: $body');
}
if (res.statusCode == 401 &&
body is Map<String, dynamic> &&
body['detail'] == 'Not authenticated' &&
_onUnauthorized != null) {
await _onUnauthorized!();
}
throw Exception('API error ${res.statusCode}: $body');
}
}