Store manual backup media in a separate directory

This commit is contained in:
Neeraj Gupta 2021-07-24 19:00:33 +05:30
parent 2559e90352
commit 4bab7ca586
6 changed files with 30 additions and 13 deletions

View file

@ -64,6 +64,7 @@ class Configuration {
FlutterSecureStorage _secureStorage;
String _tempDirectory;
String _thumbnailCacheDirectory;
String _sharedMediaDirectory;
String _volatilePassword;
final _secureStorageOptionsIOS =
@ -90,9 +91,11 @@ class Configuration {
_logger.warning(e);
}
tempDirectory.createSync(recursive: true);
_thumbnailCacheDirectory =
(await getTemporaryDirectory()).path + "/thumbnail-cache";
var tempDirectoryPath = (await getTemporaryDirectory()).path;
_thumbnailCacheDirectory = tempDirectoryPath + "/thumbnail-cache";
io.Directory(_thumbnailCacheDirectory).createSync(recursive: true);
_sharedMediaDirectory = tempDirectoryPath + "/ente-shared-media";
io.Directory(_sharedMediaDirectory).createSync(recursive: true);
if (!_preferences.containsKey(tokenKey)) {
await _secureStorage.deleteAll(iOptions: _secureStorageOptionsIOS);
} else {
@ -410,6 +413,10 @@ class Configuration {
return _thumbnailCacheDirectory;
}
String getSharedMediaCacheDirectory() {
return _sharedMediaDirectory;
}
bool hasConfiguredAccount() {
return getToken() != null && _key != null;
}

View file

@ -13,4 +13,4 @@ const int kAndroid11SDKINT = 30;
const int kGalleryLoadStartTime = -8000000000000000; // Wednesday, March 6, 1748
// used to identify which ente file are available in app cache
const String kAppCacheIdentifier = 'ente-cache://';
const String kSharedMediaIdentifier = 'ente-shared://';

View file

@ -137,7 +137,7 @@ class File {
bool isCachedInAppSandbox() {
return localID != null && localID.startsWith(kAppCacheIdentifier);
return localID != null && localID.startsWith(kSharedMediaIdentifier);
}
bool hasLocation() {

View file

@ -100,7 +100,7 @@ Future<MediaUploadData> _getMediaUploadDataFromAppCache(ente.File file) async {
io.File sourceFile;
Uint8List thumbnailData;
bool isDeleted = false;
var localPath = file.localID.replaceAll(kAppCacheIdentifier, '');
var localPath = getSharedMediaFilePath(file);
sourceFile = io.File(localPath);
if (!sourceFile.existsSync()) {
_logger.warning("File doesn't exist in app sandbox");
@ -111,7 +111,7 @@ Future<MediaUploadData> _getMediaUploadDataFromAppCache(ente.File file) async {
}
Future<Uint8List> getThumbnailFromInAppCacheFile(ente.File file) async {
var localPath = file.localID.replaceAll(kAppCacheIdentifier, '');
var localPath = getSharedMediaFilePath(file);
var thumbnailData = io.File(localPath).readAsBytesSync();
int compressionAttempts = 0;
while (thumbnailData.length > kThumbnailDataLimit &&

View file

@ -9,7 +9,6 @@ import 'package:flutter_sodium/flutter_sodium.dart';
import 'package:logging/logging.dart';
import 'package:path/path.dart';
import 'package:photos/core/cache/image_cache.dart';
import 'package:photos/core/cache/thumbnail_cache.dart';
import 'package:photos/core/cache/video_cache_manager.dart';
import 'package:photos/core/configuration.dart';
import 'package:photos/core/constants.dart';
@ -47,8 +46,7 @@ Future<io.File> getFile(ente.File file) async {
Future<io.File> _getLocalDiskFile(ente.File file) async {
if (file.isCachedInAppSandbox()) {
var localPath = file.localID.replaceAll(kAppCacheIdentifier, '');
return io.File(localPath);
return io.File(getSharedMediaFilePath(file));
} else {
return file.getAsset().then((asset) async {
if (asset == null || !(await asset.exists)) {
@ -59,6 +57,11 @@ Future<io.File> _getLocalDiskFile(ente.File file) async {
}
}
String getSharedMediaFilePath(ente.File file) {
return Configuration.instance.getSharedMediaCacheDirectory()
+ "/" + file.localID.replaceAll(kSharedMediaIdentifier, '');
}
void preloadThumbnail(ente.File file) {
if (file.isRemoteFile()) {
getThumbnailFromServer(file);

View file

@ -9,6 +9,7 @@ import 'package:photos/core/constants.dart';
import 'package:photos/models/file_type.dart';
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
import 'package:share/share.dart';
import 'package:photos/core/configuration.dart';
import 'package:flutter/widgets.dart';
import 'package:photos/models/file.dart';
import 'package:photos/utils/dialog_util.dart';
@ -38,12 +39,18 @@ Future<List<File>> convertIncomingSharedMediaToFile(
List<File> localFiles = [];
for (var media in sharedMedia) {
var enteFile = File();
enteFile.localID = kAppCacheIdentifier + media.path;
enteFile.collectionID = collectionID;
enteFile.fileType = FileType.image;
// fileName: img_x.jpg
enteFile.title = basename(media.path);
var exifMap = await readExifFromFile(dartio.File(media.path));
var ioFile = dartio.File(media.path);
ioFile = ioFile.renameSync(Configuration.instance.getSharedMediaCacheDirectory() +
"/" +
enteFile.title);
enteFile.localID = kSharedMediaIdentifier + enteFile.title;
enteFile.collectionID = collectionID;
enteFile.fileType = FileType.image;
var exifMap = await readExifFromFile(ioFile);
if (exifMap != null &&
exifMap["Image DateTime"] != null &&
'0000:00:00 00:00:00' != exifMap["Image DateTime"].toString()) {