OpenContacts/lib/clients/audio_cache_client.dart

24 lines
838 B
Dart
Raw Normal View History

2023-05-20 15:09:22 -04:00
import 'dart:io';
import 'package:recon/auxiliary.dart';
import 'package:recon/clients/api_client.dart';
2023-05-20 15:09:22 -04:00
import 'package:http/http.dart' as http;
import 'package:recon/models/message.dart';
2023-05-20 15:09:22 -04:00
import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';
class AudioCacheClient {
final Future<Directory> _directoryFuture = getTemporaryDirectory();
Future<File> cachedNetworkAudioFile(AudioClipContent clip) async {
final directory = await _directoryFuture;
final file = File("${directory.path}/${basename(clip.assetUri)}");
if (!await file.exists()) {
await file.create(recursive: true);
2023-09-29 03:51:46 -04:00
final response = await http.get(Uri.parse(Aux.resdbToHttp(clip.assetUri)));
2023-05-25 09:50:38 -04:00
ApiClient.checkResponseCode(response);
2023-05-20 15:09:22 -04:00
await file.writeAsBytes(response.bodyBytes);
}
return file;
}
}