|
@@ -39,10 +39,10 @@ Future<io.File> getFile(
|
|
bool isOrigin = false,
|
|
bool isOrigin = false,
|
|
} // only relevant for live photos
|
|
} // only relevant for live photos
|
|
) async {
|
|
) async {
|
|
- if (file.isRemoteFile()) {
|
|
|
|
|
|
+ if (file.isRemoteFile) {
|
|
return getFileFromServer(file, liveVideo: liveVideo);
|
|
return getFileFromServer(file, liveVideo: liveVideo);
|
|
} else {
|
|
} else {
|
|
- final String key = file.tag() + liveVideo.toString() + isOrigin.toString();
|
|
|
|
|
|
+ final String key = file.tag + liveVideo.toString() + isOrigin.toString();
|
|
final cachedFile = FileLruCache.get(key);
|
|
final cachedFile = FileLruCache.get(key);
|
|
if (cachedFile == null) {
|
|
if (cachedFile == null) {
|
|
final diskFile = await _getLocalDiskFile(
|
|
final diskFile = await _getLocalDiskFile(
|
|
@@ -70,7 +70,7 @@ Future<io.File> _getLocalDiskFile(
|
|
bool liveVideo = false,
|
|
bool liveVideo = false,
|
|
bool isOrigin = false,
|
|
bool isOrigin = false,
|
|
}) async {
|
|
}) async {
|
|
- if (file.isSharedMediaToAppSandbox()) {
|
|
|
|
|
|
+ if (file.isSharedMediaToAppSandbox) {
|
|
final localFile = io.File(getSharedMediaFilePath(file));
|
|
final localFile = io.File(getSharedMediaFilePath(file));
|
|
return localFile.exists().then((exist) {
|
|
return localFile.exists().then((exist) {
|
|
return exist ? localFile : null;
|
|
return exist ? localFile : null;
|
|
@@ -78,7 +78,7 @@ Future<io.File> _getLocalDiskFile(
|
|
} else if (file.fileType == FileType.livePhoto && liveVideo) {
|
|
} else if (file.fileType == FileType.livePhoto && liveVideo) {
|
|
return Motionphoto.getLivePhotoFile(file.localID);
|
|
return Motionphoto.getLivePhotoFile(file.localID);
|
|
} else {
|
|
} else {
|
|
- return file.getAsset().then((asset) async {
|
|
|
|
|
|
+ return file.getAsset.then((asset) async {
|
|
if (asset == null || !(await asset.exists)) {
|
|
if (asset == null || !(await asset.exists)) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
@@ -104,7 +104,7 @@ String getSharedMediaPathFromLocalID(String localID) {
|
|
}
|
|
}
|
|
|
|
|
|
void preloadThumbnail(ente.File file) {
|
|
void preloadThumbnail(ente.File file) {
|
|
- if (file.isRemoteFile()) {
|
|
|
|
|
|
+ if (file.isRemoteFile) {
|
|
getThumbnailFromServer(file);
|
|
getThumbnailFromServer(file);
|
|
} else {
|
|
} else {
|
|
getThumbnailFromLocal(file);
|
|
getThumbnailFromLocal(file);
|
|
@@ -122,8 +122,7 @@ Future<io.File> getFileFromServer(
|
|
final cacheManager = (file.fileType == FileType.video || liveVideo)
|
|
final cacheManager = (file.fileType == FileType.video || liveVideo)
|
|
? VideoCacheManager.instance
|
|
? VideoCacheManager.instance
|
|
: DefaultCacheManager();
|
|
: DefaultCacheManager();
|
|
- final fileFromCache =
|
|
|
|
- await cacheManager.getFileFromCache(file.getDownloadUrl());
|
|
|
|
|
|
+ final fileFromCache = await cacheManager.getFileFromCache(file.downloadUrl);
|
|
if (fileFromCache != null) {
|
|
if (fileFromCache != null) {
|
|
return fileFromCache.file;
|
|
return fileFromCache.file;
|
|
}
|
|
}
|
|
@@ -154,7 +153,7 @@ Future<bool> isFileCached(ente.File file, {bool liveVideo = false}) async {
|
|
final cacheManager = (file.fileType == FileType.video || liveVideo)
|
|
final cacheManager = (file.fileType == FileType.video || liveVideo)
|
|
? VideoCacheManager.instance
|
|
? VideoCacheManager.instance
|
|
: DefaultCacheManager();
|
|
: DefaultCacheManager();
|
|
- final fileInfo = await cacheManager.getFileFromCache(file.getDownloadUrl());
|
|
|
|
|
|
+ final fileInfo = await cacheManager.getFileFromCache(file.downloadUrl);
|
|
return fileInfo != null;
|
|
return fileInfo != null;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -222,9 +221,9 @@ Future<_LivePhoto> _downloadLivePhoto(
|
|
await imageFile.delete();
|
|
await imageFile.delete();
|
|
}
|
|
}
|
|
imageFileCache = await DefaultCacheManager().putFile(
|
|
imageFileCache = await DefaultCacheManager().putFile(
|
|
- file.getDownloadUrl(),
|
|
|
|
|
|
+ file.downloadUrl,
|
|
await imageConvertedFile.readAsBytes(),
|
|
await imageConvertedFile.readAsBytes(),
|
|
- eTag: file.getDownloadUrl(),
|
|
|
|
|
|
+ eTag: file.downloadUrl,
|
|
maxAge: const Duration(days: 365),
|
|
maxAge: const Duration(days: 365),
|
|
fileExtension: fileExtension,
|
|
fileExtension: fileExtension,
|
|
);
|
|
);
|
|
@@ -234,9 +233,9 @@ Future<_LivePhoto> _downloadLivePhoto(
|
|
await videoFile.create(recursive: true);
|
|
await videoFile.create(recursive: true);
|
|
await videoFile.writeAsBytes(data);
|
|
await videoFile.writeAsBytes(data);
|
|
videoFileCache = await VideoCacheManager.instance.putFile(
|
|
videoFileCache = await VideoCacheManager.instance.putFile(
|
|
- file.getDownloadUrl(),
|
|
|
|
|
|
+ file.downloadUrl,
|
|
await videoFile.readAsBytes(),
|
|
await videoFile.readAsBytes(),
|
|
- eTag: file.getDownloadUrl(),
|
|
|
|
|
|
+ eTag: file.downloadUrl,
|
|
maxAge: const Duration(days: 365),
|
|
maxAge: const Duration(days: 365),
|
|
fileExtension: fileExtension,
|
|
fileExtension: fileExtension,
|
|
);
|
|
);
|
|
@@ -246,7 +245,7 @@ Future<_LivePhoto> _downloadLivePhoto(
|
|
}
|
|
}
|
|
return _LivePhoto(imageFileCache, videoFileCache);
|
|
return _LivePhoto(imageFileCache, videoFileCache);
|
|
}).catchError((e) {
|
|
}).catchError((e) {
|
|
- _logger.warning("failed to download live photos : ${file.tag()}", e);
|
|
|
|
|
|
+ _logger.warning("failed to download live photos : ${file.tag}", e);
|
|
throw e;
|
|
throw e;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
@@ -274,16 +273,16 @@ Future<io.File> _downloadAndCache(
|
|
await decryptedFile.delete();
|
|
await decryptedFile.delete();
|
|
}
|
|
}
|
|
final cachedFile = await cacheManager.putFile(
|
|
final cachedFile = await cacheManager.putFile(
|
|
- file.getDownloadUrl(),
|
|
|
|
|
|
+ file.downloadUrl,
|
|
await outputFile.readAsBytes(),
|
|
await outputFile.readAsBytes(),
|
|
- eTag: file.getDownloadUrl(),
|
|
|
|
|
|
+ eTag: file.downloadUrl,
|
|
maxAge: const Duration(days: 365),
|
|
maxAge: const Duration(days: 365),
|
|
fileExtension: fileExtension,
|
|
fileExtension: fileExtension,
|
|
);
|
|
);
|
|
await outputFile.delete();
|
|
await outputFile.delete();
|
|
return cachedFile;
|
|
return cachedFile;
|
|
}).catchError((e) {
|
|
}).catchError((e) {
|
|
- _logger.warning("failed to download file : ${file.tag()}", e);
|
|
|
|
|
|
+ _logger.warning("failed to download file : ${file.tag}", e);
|
|
throw e;
|
|
throw e;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
@@ -309,9 +308,9 @@ Future<Uint8List> compressThumbnail(Uint8List thumbnail) {
|
|
|
|
|
|
Future<void> clearCache(ente.File file) async {
|
|
Future<void> clearCache(ente.File file) async {
|
|
if (file.fileType == FileType.video) {
|
|
if (file.fileType == FileType.video) {
|
|
- VideoCacheManager.instance.removeFile(file.getDownloadUrl());
|
|
|
|
|
|
+ VideoCacheManager.instance.removeFile(file.downloadUrl);
|
|
} else {
|
|
} else {
|
|
- DefaultCacheManager().removeFile(file.getDownloadUrl());
|
|
|
|
|
|
+ DefaultCacheManager().removeFile(file.downloadUrl);
|
|
}
|
|
}
|
|
final cachedThumbnail = io.File(
|
|
final cachedThumbnail = io.File(
|
|
Configuration.instance.getThumbnailCacheDirectory() +
|
|
Configuration.instance.getThumbnailCacheDirectory() +
|