v1.1.20+50
All checks were successful
Flutter Schmutter / build (push) Successful in 3m39s

This commit is contained in:
2025-06-11 18:56:55 +02:00
parent a4d50289c2
commit e38d2086b3
8 changed files with 373 additions and 280 deletions

View File

@ -13,16 +13,16 @@ final FlutterSecureStorage storage = const FlutterSecureStorage(
Future<List<MediaItem>> fetchMedia({
int? older,
String? type,
int? mode,
bool? random,
String type = 'image',
int mode = 0,
bool random = false,
String? tag,
}) async {
final Uri url = Uri.parse('https://api.f0ck.me/items/get').replace(
queryParameters: {
'type': type ?? 'image',
'mode': (mode ?? 0).toString(),
'random': (random! ? 1 : 0).toString(),
'type': type,
'mode': mode.toString(),
'random': (random ? 1 : 0).toString(),
if (tag != null) 'tag': tag,
if (older != null) 'older': older.toString(),
},
@ -61,14 +61,14 @@ Future<List<Suggestion>> fetchSuggestions(String query) async {
if (response.statusCode == 200) {
final dynamic decoded = jsonDecode(response.body);
if (decoded is List) {
return decoded
final suggestions = decoded
.map((item) => Suggestion.fromJson(item as Map<String, dynamic>))
.toList()
..sort((a, b) => b.score.compareTo(a.score));
.toList();
suggestions.sort((a, b) => b.score.compareTo(a.score));
return suggestions;
} else {
throw Exception('Unerwartetes Format: Erwartet wurde eine Liste.');
throw Exception('Unerwartetes Format: Es wurde eine Liste erwartet.');
}
} else if (response.statusCode == 400) {
final dynamic error = jsonDecode(response.body);
@ -84,7 +84,7 @@ Future<List<Suggestion>> fetchSuggestions(String query) async {
} on TimeoutException {
throw Exception('Anfrage an die API hat zu lange gedauert.');
} catch (e) {
throw Exception('Fehler beim Verarbeiten der Anfrage: $e');
throw Exception('Fehler bei der Verarbeitung der Anfrage: $e');
}
}
@ -98,12 +98,14 @@ Future<bool> login(String username, String password) async {
if (response.statusCode == 200) {
final dynamic data = jsonDecode(response.body);
final dynamic token = data['token'];
await storage.write(key: "token", value: token);
return true;
final token = data['token'];
if (token != null) {
await storage.write(key: "token", value: token);
return true;
} else {
throw Exception('Token nicht im Response enthalten.');
}
} else {
return false;
throw Exception('Login fehlgeschlagen: ${response.statusCode}');
}
}