From 4c63a45cc556ed4b63834959dae6e0e4f9f8eb0d Mon Sep 17 00:00:00 2001 From: danny Date: Mon, 3 Jul 2023 15:55:35 +0200 Subject: [PATCH 1/2] Preparing new release --- version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version b/version index 2b7483e..5ce99c9 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.3.0-alpha \ No newline at end of file +1.4.0-alpha \ No newline at end of file From 1c0ab1420cbc155aa58ece73e6ebe781da768fcb Mon Sep 17 00:00:00 2001 From: danny Date: Mon, 3 Jul 2023 16:48:07 +0200 Subject: [PATCH 2/2] Fix for web version --- .../lib/findMy/reports_fetcher.dart | 63 ++++++++++++------- version | 2 +- 2 files changed, 43 insertions(+), 22 deletions(-) diff --git a/headless_haystack/lib/findMy/reports_fetcher.dart b/headless_haystack/lib/findMy/reports_fetcher.dart index 57784a1..00537ca 100644 --- a/headless_haystack/lib/findMy/reports_fetcher.dart +++ b/headless_haystack/lib/findMy/reports_fetcher.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'package:http/http.dart' as http; import 'package:logger/logger.dart'; +import 'package:flutter/foundation.dart' show kIsWeb; class ReportsFetcher { /// Fetches the location reports corresponding to the given hashed advertisement @@ -18,29 +19,49 @@ class ReportsFetcher { [String? url]) async { var keys = hashedAdvertisementKeys.toList(growable: false); logger.i('Using ${keys.length} key(s) to ask webservice'); - var httpClient = HttpClient(); - /*Ignore certificate errors*/ - httpClient.badCertificateCallback = - (X509Certificate cert, String host, int port) => true; + if (kIsWeb) { + final response = await http.post(Uri.parse(url as String), + headers: { + "Content-Type": "application/json", + }, + body: jsonEncode({ + "ids": keys, + "days": daysToFetch, + })); - final request = await httpClient.postUrl(Uri.parse(url as String)); - var body = jsonEncode({ - "ids": keys, - "days": daysToFetch, - }); - request.headers.set(HttpHeaders.contentTypeHeader, "application/json"); - request.headers - .set(HttpHeaders.contentLengthHeader, utf8.encode(body).length); - request.write(body); - final response = await request.close(); - - if (response.statusCode == 200) { - String body = await response.transform(utf8.decoder).join(); - var out = await jsonDecode(body)["results"]; - return out; + if (response.statusCode == 200) { + var out = await jsonDecode(response.body)["results"]; + logger.i('Found ${out.length} reports'); + return out; + } else { + throw Exception( + "Failed to fetch location reports with statusCode:${response.statusCode}\n\n Response:\n$response"); + } } else { - throw Exception( - "Failed to fetch location reports with statusCode:${response.statusCode}\n\n Response:\n$response"); + var httpClient = HttpClient(); + /*Ignore certificate errors*/ + httpClient.badCertificateCallback = + (X509Certificate cert, String host, int port) => true; + + final request = await httpClient.postUrl(Uri.parse(url as String)); + var body = jsonEncode({ + "ids": keys, + "days": daysToFetch, + }); + request.headers.set(HttpHeaders.contentTypeHeader, "application/json"); + request.headers + .set(HttpHeaders.contentLengthHeader, utf8.encode(body).length); + request.write(body); + final response = await request.close(); + + if (response.statusCode == 200) { + String body = await response.transform(utf8.decoder).join(); + var out = await jsonDecode(body)["results"]; + return out; + } else { + throw Exception( + "Failed to fetch location reports with statusCode:${response.statusCode}\n\n Response:\n$response"); + } } } } diff --git a/version b/version index 5ce99c9..2b7483e 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.4.0-alpha \ No newline at end of file +1.3.0-alpha \ No newline at end of file