started working on cloud sync (testing)

This commit is contained in:
Kima
2024-11-16 22:21:22 +01:00
parent c9666f5333
commit 7d5b97fe00
9 changed files with 617 additions and 0 deletions

View File

@@ -54,6 +54,9 @@ class FilcAPI {
static const payment = "$baseUrl/v4/payment";
static const stripeSheet = "$payment/stripe-sheet";
// Cloud Sync
static const cloudSyncApi = "$baseUrl/v4/me/cloud-sync";
static Future<bool> checkConnectivity() async =>
(await Connectivity().checkConnectivity())[0] != ConnectivityResult.none;
@@ -390,6 +393,32 @@ class FilcAPI {
return null;
}
// cloud sync
static Future<Map?> cloudSync(Map data, String token) async {
try {
var client = http.Client();
http.Response res = await client.post(
Uri.parse(cloudSyncApi),
body: data,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Bearer $token',
},
);
if (res.statusCode != 200) {
throw "HTTP ${res.statusCode}: ${res.body}";
}
return jsonDecode(res.body);
} on Exception catch (error, stacktrace) {
log("ERROR: FilcAPI.cloudSync: $error $stacktrace");
}
return null;
}
}
class ErrorReport {