v2.38 — Issue #2: Dauerverbindung Cloud Server (persistenter http.Client)
- CloudService: static final http.Client _client als Instanzvariable - Alle http.get/post/put/delete/upload nutzen nun _client statt neuem Client - DownloadService: gleicher Fix für _retryHttpPost und _retryHttpGet Build: ✓ flutter analyze
This commit is contained in:
@@ -8,6 +8,8 @@ import '../services/melo_logger.dart';
|
||||
/// Cloud-Sync Service für Melo Registry (v3 — vollständiges Sync-System)
|
||||
/// Authentifizierung via Baka-Auth JWT-Token
|
||||
class CloudService {
|
||||
static final http.Client _client = http.Client();
|
||||
|
||||
static String get _base => AppConfig.cloudUrl;
|
||||
String _user = '';
|
||||
|
||||
@@ -15,7 +17,7 @@ class CloudService {
|
||||
Future<bool> login(String user) async {
|
||||
_user = user;
|
||||
try {
|
||||
final r = await http
|
||||
final r = await _client
|
||||
.get(Uri.parse('$_base/api/cloud/status'),
|
||||
headers: _authHeader)
|
||||
.timeout(const Duration(seconds: 5));
|
||||
@@ -63,7 +65,7 @@ class CloudService {
|
||||
req.files.add(
|
||||
await http.MultipartFile.fromPath('file', filepath,
|
||||
filename: filename));
|
||||
final resp = await req.send().timeout(const Duration(seconds: 120));
|
||||
final resp = await _client.send(req).timeout(const Duration(seconds: 120));
|
||||
final body = jsonDecode(await resp.stream.bytesToString());
|
||||
return body['song_id'] as String?;
|
||||
} catch (e) {
|
||||
@@ -74,7 +76,7 @@ class CloudService {
|
||||
|
||||
Future<bool> download(String songId, String destPath) async {
|
||||
try {
|
||||
final r = await http
|
||||
final r = await _client
|
||||
.get(Uri.parse('$_base/api/cloud/download/$songId'),
|
||||
headers: _authHeader)
|
||||
.timeout(const Duration(seconds: 120));
|
||||
@@ -91,7 +93,7 @@ class CloudService {
|
||||
|
||||
Future<bool> delete(String songId) async {
|
||||
try {
|
||||
final r = await http
|
||||
final r = await _client
|
||||
.post(Uri.parse('$_base/api/cloud/delete'),
|
||||
headers: _jsonHeader,
|
||||
body: jsonEncode({'song_id': songId}))
|
||||
@@ -105,7 +107,7 @@ class CloudService {
|
||||
/// Sync-Änderungen seit einem Zeitstempel abrufen
|
||||
Future<List<Map>> syncChanges(String since) async {
|
||||
try {
|
||||
final r = await http
|
||||
final r = await _client
|
||||
.post(Uri.parse('$_base/api/cloud/sync'),
|
||||
headers: _jsonHeader,
|
||||
body: jsonEncode({'since': since}))
|
||||
@@ -153,7 +155,7 @@ class CloudService {
|
||||
/// Song aus Playlist entfernen
|
||||
Future<bool> removeSongFromPlaylist(int playlistId, String songId) async {
|
||||
try {
|
||||
final r = await http
|
||||
final r = await _client
|
||||
.delete(
|
||||
Uri.parse(
|
||||
'$_base/api/cloud/playlists/$playlistId/songs/$songId'),
|
||||
@@ -169,7 +171,7 @@ class CloudService {
|
||||
Future<bool> updatePlaylistPositions(
|
||||
int playlistId, List<Map<String, dynamic>> positions) async {
|
||||
try {
|
||||
final r = await http
|
||||
final r = await _client
|
||||
.put(
|
||||
Uri.parse(
|
||||
'$_base/api/cloud/playlists/$playlistId/positions'),
|
||||
@@ -231,7 +233,7 @@ class CloudService {
|
||||
|
||||
Future<List<Map>> globalList() async {
|
||||
try {
|
||||
final r = await http
|
||||
final r = await _client
|
||||
.get(Uri.parse('$_base/api/cloud/global'), headers: _authHeader)
|
||||
.timeout(const Duration(seconds: 10));
|
||||
if (r.statusCode == 200) {
|
||||
@@ -243,7 +245,7 @@ class CloudService {
|
||||
|
||||
Future<bool> toggleGlobal(String songId) async {
|
||||
try {
|
||||
final r = await http
|
||||
final r = await _client
|
||||
.post(Uri.parse('$_base/api/cloud/toggle-global'),
|
||||
headers: _jsonHeader,
|
||||
body: jsonEncode({'song_id': songId}))
|
||||
@@ -256,7 +258,7 @@ class CloudService {
|
||||
|
||||
Future<String?> share(List<String> songIds) async {
|
||||
try {
|
||||
final r = await http
|
||||
final r = await _client
|
||||
.post(Uri.parse('$_base/api/cloud/share'),
|
||||
headers: _jsonHeader,
|
||||
body: jsonEncode({'song_ids': songIds}))
|
||||
@@ -271,7 +273,7 @@ class CloudService {
|
||||
|
||||
Future<Map?> importCode(String code) async {
|
||||
try {
|
||||
final r = await http
|
||||
final r = await _client
|
||||
.post(Uri.parse('$_base/api/cloud/import'),
|
||||
headers: _jsonHeader,
|
||||
body: jsonEncode({'code': code}))
|
||||
@@ -283,7 +285,7 @@ class CloudService {
|
||||
|
||||
Future<List<Map>> getCorrupted() async {
|
||||
try {
|
||||
final r = await http
|
||||
final r = await _client
|
||||
.get(Uri.parse('$_base/api/cloud/corrupted'), headers: _authHeader)
|
||||
.timeout(const Duration(seconds: 15));
|
||||
if (r.statusCode == 200) {
|
||||
@@ -300,7 +302,7 @@ class CloudService {
|
||||
|
||||
Future<Map?> _get(String path) async {
|
||||
try {
|
||||
final r = await http
|
||||
final r = await _client
|
||||
.get(Uri.parse('$_base$path'), headers: _authHeader)
|
||||
.timeout(const Duration(seconds: 10));
|
||||
if (r.statusCode == 200) return jsonDecode(r.body);
|
||||
@@ -313,7 +315,7 @@ class CloudService {
|
||||
|
||||
Future<Map?> _post(String path, Map<String, dynamic> body) async {
|
||||
try {
|
||||
final r = await http
|
||||
final r = await _client
|
||||
.post(Uri.parse('$_base$path'),
|
||||
headers: _jsonHeader, body: jsonEncode(body))
|
||||
.timeout(const Duration(seconds: 10));
|
||||
|
||||
Reference in New Issue
Block a user