feat: add remote products and qr code for payconic
This commit is contained in:
@@ -104,6 +104,43 @@ class KoolTapApiClient {
|
||||
);
|
||||
}
|
||||
|
||||
/// Uploads a picture taken on this tablet; the server crops and stores it
|
||||
/// and returns its id, which a `product_updated` event then links.
|
||||
Future<String> uploadImage({
|
||||
required String token,
|
||||
required String deviceId,
|
||||
required List<int> bytes,
|
||||
required String filename,
|
||||
}) async {
|
||||
final request =
|
||||
http.MultipartRequest(
|
||||
'POST',
|
||||
Uri.parse('$baseUrl/devices/$deviceId/images'),
|
||||
)
|
||||
..headers['Authorization'] = 'Bearer $token'
|
||||
..files.add(
|
||||
http.MultipartFile.fromBytes('file', bytes, filename: filename),
|
||||
);
|
||||
// Uploading a photo over a slow connection takes longer than a sync
|
||||
final response = await http.Response.fromStream(
|
||||
await _client.send(request).timeout(_timeout * 4),
|
||||
);
|
||||
|
||||
final data = _decode(response, authenticated: true) as Map<String, dynamic>;
|
||||
return data['imageId'] as String;
|
||||
}
|
||||
|
||||
/// A product picture (public: pictures never change at their address).
|
||||
Future<List<int>> downloadImage(String imageId) async {
|
||||
final response = await _client
|
||||
.get(Uri.parse('$baseUrl/images/$imageId'))
|
||||
.timeout(_timeout * 2);
|
||||
if (response.statusCode != 200) {
|
||||
throw ApiException(response.statusCode, 'Image $imageId not available');
|
||||
}
|
||||
return response.bodyBytes;
|
||||
}
|
||||
|
||||
Future<Object?> _post(
|
||||
String path,
|
||||
Map<String, dynamic> body, {
|
||||
|
||||
Reference in New Issue
Block a user