- fixed: duplicates on the frontpage - new: search by tag
This commit is contained in:
@ -4,8 +4,9 @@ import 'package:http/http.dart' as http;
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
|
||||
import 'package:f0ckapp/models/mediaitem_model.dart';
|
||||
import 'package:f0ckapp/models/suggestion_model.dart';
|
||||
|
||||
final storage = FlutterSecureStorage();
|
||||
final FlutterSecureStorage storage = FlutterSecureStorage();
|
||||
|
||||
Future<List<MediaItem>> fetchMedia({
|
||||
int? older,
|
||||
@ -48,6 +49,36 @@ Future<MediaItem> fetchMediaDetail(int itemId) async {
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<Suggestion>> fetchSuggestions(String query) async {
|
||||
final Uri uri = Uri.parse(
|
||||
'https://f0ck.me/api/v2/admin/tags/suggest?q=$query',
|
||||
); // wip: new route in pyapi
|
||||
final response = await http.get(uri);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final Map<String, dynamic> decoded = jsonDecode(response.body);
|
||||
if (decoded['success'] == true && decoded.containsKey('suggestions')) {
|
||||
final List<dynamic> suggestionsList = decoded['suggestions'];
|
||||
return suggestionsList
|
||||
.map(
|
||||
(dynamic jsonItem) =>
|
||||
Suggestion.fromJson(jsonItem as Map<String, dynamic>),
|
||||
)
|
||||
.toList()
|
||||
..sort(
|
||||
(Suggestion a, Suggestion b) =>
|
||||
(b.score * b.tagged).compareTo(a.score * a.tagged),
|
||||
);
|
||||
} else {
|
||||
throw Exception('Nichts gefunden.');
|
||||
}
|
||||
} else {
|
||||
throw Exception(
|
||||
'Fehler beim Abrufen der Vorschläge: ${response.statusCode}',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> login(String username, String password) async {
|
||||
final Uri url = Uri.parse('https://api.f0ck.me/login');
|
||||
|
||||
@ -57,8 +88,8 @@ Future<bool> login(String username, String password) async {
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final data = jsonDecode(response.body);
|
||||
final token = data['token'];
|
||||
final dynamic data = jsonDecode(response.body);
|
||||
final dynamic token = data['token'];
|
||||
|
||||
await storage.write(key: "token", value: token);
|
||||
|
||||
|
Reference in New Issue
Block a user