- Added chat history persistence for active rooms with auto-cleanup on stream end. - Overhauled Settings page with user profile, theme color picker, and password change. - Added backend API for user password updates. - Integrated flutter_launcher_icons and updated app icon to 'H' logo. - Fixed 'Duplicate keys' bug in danmaku by using UniqueKey and filtering historical messages. - Updated version to 1.0.0-beta3.5 and author info.
54 lines
1.5 KiB
Dart
54 lines
1.5 KiB
Dart
import 'dart:convert';
|
|
import 'package:http/http.dart' as http;
|
|
import '../providers/settings_provider.dart';
|
|
|
|
class ApiService {
|
|
final SettingsProvider settings;
|
|
final String? token;
|
|
|
|
ApiService(this.settings, this.token);
|
|
|
|
Map<String, String> get _headers => {
|
|
'Content-Type': 'application/json',
|
|
if (token != null) 'Authorization': 'Bearer $token',
|
|
};
|
|
|
|
Future<http.Response> register(String username, String password) async {
|
|
return await http.post(
|
|
Uri.parse("${settings.baseUrl}/api/register"),
|
|
headers: _headers,
|
|
body: jsonEncode({"username": username, "password": password}),
|
|
);
|
|
}
|
|
|
|
Future<http.Response> login(String username, String password) async {
|
|
return await http.post(
|
|
Uri.parse("${settings.baseUrl}/api/login"),
|
|
headers: _headers,
|
|
body: jsonEncode({"username": username, "password": password}),
|
|
);
|
|
}
|
|
|
|
Future<http.Response> getMyRoom() async {
|
|
return await http.get(
|
|
Uri.parse("${settings.baseUrl}/api/room/my"),
|
|
headers: _headers,
|
|
);
|
|
}
|
|
|
|
Future<http.Response> getActiveRooms() async {
|
|
return await http.get(
|
|
Uri.parse("${settings.baseUrl}/api/rooms/active"),
|
|
headers: _headers,
|
|
);
|
|
}
|
|
|
|
Future<http.Response> changePassword(String oldPassword, String newPassword) async {
|
|
return await http.post(
|
|
Uri.parse("${settings.baseUrl}/api/user/change-password"),
|
|
headers: _headers,
|
|
body: jsonEncode({"old_password": oldPassword, "new_password": newPassword}),
|
|
);
|
|
}
|
|
}
|