fix getCachedImageFile

This commit is contained in:
kodjomoustapha 2024-12-24 12:46:12 +01:00
parent ff2bf3317d
commit 36fd6d2709

View file

@ -10,6 +10,8 @@ import 'package:mangayomi/modules/more/settings/reader/providers/reader_state_pr
import 'package:mangayomi/modules/widgets/custom_extended_image_provider.dart';
import 'package:mangayomi/utils/headers.dart';
import 'package:mangayomi/utils/reg_exp_matcher.dart';
import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';
extension LetExtension<T> on T {
R let<R>(R Function(T) block) {
@ -48,11 +50,11 @@ extension UChapDataPreloadExtensions on UChapDataPreload {
} else {
File? cachedImage;
if (pageUrl != null) {
cachedImage = await getCachedImageFile(pageUrl!.url);
cachedImage = await _getCachedImageFile(pageUrl!.url);
}
if (cachedImage == null) {
await Future.delayed(const Duration(seconds: 3));
cachedImage = await getCachedImageFile(pageUrl!.url);
cachedImage = await _getCachedImageFile(pageUrl!.url);
}
imageBytes = cachedImage?.readAsBytesSync();
}
@ -86,3 +88,21 @@ extension UChapDataPreloadExtensions on UChapDataPreload {
})) as ImageProvider<Object>;
}
}
Future<File?> _getCachedImageFile(String url, {String? cacheKey}) async {
try {
final String key = cacheKey ?? keyToMd5(url);
final Directory cacheImagesDirectory = Directory(join(
(await getTemporaryDirectory()).path, 'Mangayomi', 'cacheimagemanga'));
if (cacheImagesDirectory.existsSync()) {
await for (final FileSystemEntity file in cacheImagesDirectory.list()) {
if (file.path.endsWith(key)) {
return File(file.path);
}
}
}
} catch (_) {
return null;
}
return null;
}