2022-06-08 08:49:23 +00:00
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:core';
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:logging/logging.dart';
|
2023-08-22 13:54:40 +00:00
|
|
|
import "package:photos/core/configuration.dart";
|
2023-01-11 08:30:20 +00:00
|
|
|
import 'package:photos/core/errors.dart';
|
2022-08-29 04:30:28 +00:00
|
|
|
import 'package:photos/db/file_updation_db.dart';
|
2022-06-08 08:49:23 +00:00
|
|
|
import 'package:photos/db/files_db.dart';
|
2023-12-06 07:04:06 +00:00
|
|
|
import "package:photos/extensions/list.dart";
|
2023-12-04 04:55:17 +00:00
|
|
|
import "package:photos/extensions/stop_watch.dart";
|
2023-12-06 08:02:11 +00:00
|
|
|
import "package:photos/models/file/extensions/file_props.dart";
|
2023-08-25 04:39:30 +00:00
|
|
|
import 'package:photos/models/file/file.dart';
|
|
|
|
import 'package:photos/models/file/file_type.dart';
|
2023-12-04 04:55:17 +00:00
|
|
|
import "package:photos/services/files_service.dart";
|
2022-08-05 11:09:56 +00:00
|
|
|
import 'package:photos/utils/file_uploader_util.dart';
|
2022-10-17 18:42:48 +00:00
|
|
|
import 'package:photos/utils/file_util.dart';
|
2022-06-08 08:49:23 +00:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
2022-07-29 06:06:03 +00:00
|
|
|
// LocalFileUpdateService tracks all the potential local file IDs which have
|
|
|
|
// changed/modified on the device and needed to be uploaded again.
|
2022-08-01 11:05:16 +00:00
|
|
|
class LocalFileUpdateService {
|
2022-12-30 09:08:23 +00:00
|
|
|
late FileUpdationDB _fileUpdationDB;
|
|
|
|
late SharedPreferences _prefs;
|
|
|
|
late Logger _logger;
|
2023-12-06 03:44:33 +00:00
|
|
|
final String _iosLivePhotoSizeMigrationDone = 'fm_ios_live_photo_check';
|
|
|
|
final String _doneLivePhotoImport = 'fm_import_ios_live_photo_check';
|
|
|
|
static int twoHundredKb = 200 * 1024;
|
2023-05-24 06:43:00 +00:00
|
|
|
final List<String> _oldMigrationKeys = [
|
|
|
|
'fm_badCreationTime',
|
|
|
|
'fm_badCreationTimeCompleted',
|
|
|
|
'fm_missingLocationV2ImportDone',
|
|
|
|
'fm_missingLocationV2MigrationDone',
|
|
|
|
'fm_badLocationImportDone',
|
|
|
|
'fm_badLocationMigrationDone',
|
2023-12-06 03:44:33 +00:00
|
|
|
'fm_ios_live_photo_size',
|
|
|
|
'fm_import_ios_live_photo_size',
|
2023-05-24 06:43:00 +00:00
|
|
|
];
|
2023-04-25 06:40:10 +00:00
|
|
|
|
2022-12-30 09:08:23 +00:00
|
|
|
Completer<void>? _existingMigration;
|
2022-06-08 08:49:23 +00:00
|
|
|
|
2022-08-01 11:05:16 +00:00
|
|
|
LocalFileUpdateService._privateConstructor() {
|
|
|
|
_logger = Logger((LocalFileUpdateService).toString());
|
2022-08-29 04:30:28 +00:00
|
|
|
_fileUpdationDB = FileUpdationDB.instance;
|
2022-06-08 09:30:21 +00:00
|
|
|
}
|
|
|
|
|
2022-11-06 06:24:10 +00:00
|
|
|
void init(SharedPreferences preferences) {
|
2022-11-06 06:14:46 +00:00
|
|
|
_prefs = preferences;
|
2022-06-08 08:49:23 +00:00
|
|
|
}
|
|
|
|
|
2022-08-01 11:05:16 +00:00
|
|
|
static LocalFileUpdateService instance =
|
|
|
|
LocalFileUpdateService._privateConstructor();
|
2022-06-08 08:49:23 +00:00
|
|
|
|
2022-08-01 11:05:16 +00:00
|
|
|
Future<void> markUpdatedFilesForReUpload() async {
|
2022-06-08 08:49:23 +00:00
|
|
|
if (_existingMigration != null) {
|
2022-06-08 09:51:03 +00:00
|
|
|
_logger.info("migration is already in progress, skipping");
|
2022-12-30 09:08:23 +00:00
|
|
|
return _existingMigration!.future;
|
2022-06-08 08:49:23 +00:00
|
|
|
}
|
|
|
|
_existingMigration = Completer<void>();
|
|
|
|
try {
|
2022-08-05 11:09:56 +00:00
|
|
|
await _markFilesWhichAreActuallyUpdated();
|
2023-12-06 03:44:33 +00:00
|
|
|
_cleanUpOlderMigration().ignore();
|
|
|
|
if (!Platform.isAndroid) {
|
2023-12-04 04:55:17 +00:00
|
|
|
await _handleLivePhotosSizedCheck();
|
2022-11-14 09:33:16 +00:00
|
|
|
}
|
2022-06-08 08:49:23 +00:00
|
|
|
} catch (e, s) {
|
|
|
|
_logger.severe('failed to perform migration', e, s);
|
2022-08-29 17:43:17 +00:00
|
|
|
} finally {
|
|
|
|
_existingMigration?.complete();
|
2022-06-08 08:49:23 +00:00
|
|
|
_existingMigration = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-24 06:53:33 +00:00
|
|
|
Future<void> _cleanUpOlderMigration() async {
|
2023-05-24 06:43:00 +00:00
|
|
|
// check if any old_migration_keys are present in shared preferences
|
|
|
|
bool hasOldMigrationKey = false;
|
|
|
|
for (String key in _oldMigrationKeys) {
|
|
|
|
if (_prefs.containsKey(key)) {
|
|
|
|
hasOldMigrationKey = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (hasOldMigrationKey) {
|
2023-05-24 06:53:33 +00:00
|
|
|
await _fileUpdationDB.deleteByReasons([
|
|
|
|
'missing_location',
|
|
|
|
'badCreationTime',
|
|
|
|
'missingLocationV2',
|
|
|
|
'badLocationCord',
|
2023-12-06 03:44:33 +00:00
|
|
|
'livePhotoSize',
|
2023-05-24 06:53:33 +00:00
|
|
|
]);
|
2023-12-06 03:44:33 +00:00
|
|
|
for (var element in _oldMigrationKeys) {
|
|
|
|
await _prefs.remove(element);
|
|
|
|
}
|
2023-05-24 06:43:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-05 11:09:56 +00:00
|
|
|
// This method analyses all of local files for which the file
|
|
|
|
// modification/update time was changed. It checks if the existing fileHash
|
|
|
|
// is different from the hash of uploaded file. If fileHash are different,
|
|
|
|
// then it marks the file for file update.
|
|
|
|
Future<void> _markFilesWhichAreActuallyUpdated() async {
|
|
|
|
final sTime = DateTime.now().microsecondsSinceEpoch;
|
2022-10-03 05:45:23 +00:00
|
|
|
// singleRunLimit indicates number of files to check during single
|
|
|
|
// invocation of this method. The limit act as a crude way to limit the
|
|
|
|
// resource consumed by the method
|
|
|
|
const int singleRunLimit = 10;
|
|
|
|
final localIDsToProcess =
|
|
|
|
await _fileUpdationDB.getLocalIDsForPotentialReUpload(
|
|
|
|
singleRunLimit,
|
|
|
|
FileUpdationDB.modificationTimeUpdated,
|
|
|
|
);
|
|
|
|
if (localIDsToProcess.isNotEmpty) {
|
|
|
|
await _checkAndMarkFilesWithDifferentHashForFileUpdate(
|
|
|
|
localIDsToProcess,
|
|
|
|
);
|
|
|
|
final eTime = DateTime.now().microsecondsSinceEpoch;
|
|
|
|
final d = Duration(microseconds: eTime - sTime);
|
|
|
|
_logger.info(
|
|
|
|
'Performed hashCheck for ${localIDsToProcess.length} updated files '
|
|
|
|
'completed in ${d.inSeconds.toString()} secs',
|
2022-08-05 11:09:56 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _checkAndMarkFilesWithDifferentHashForFileUpdate(
|
|
|
|
List<String> localIDsToProcess,
|
|
|
|
) async {
|
2023-08-22 13:54:40 +00:00
|
|
|
final int userID = Configuration.instance.getUserID()!;
|
2023-08-24 16:56:24 +00:00
|
|
|
final List<EnteFile> result =
|
2022-08-30 07:41:35 +00:00
|
|
|
await FilesDB.instance.getLocalFiles(localIDsToProcess);
|
2023-08-24 16:56:24 +00:00
|
|
|
final List<EnteFile> localFilesForUser = [];
|
2023-11-27 09:25:14 +00:00
|
|
|
final Set<String> localIDsWithFile = {};
|
2023-08-24 16:56:24 +00:00
|
|
|
for (EnteFile file in result) {
|
2023-08-22 13:54:40 +00:00
|
|
|
if (file.ownerID == null || file.ownerID == userID) {
|
|
|
|
localFilesForUser.add(file);
|
2023-11-27 09:25:14 +00:00
|
|
|
localIDsWithFile.add(file.localID!);
|
2023-08-22 13:54:40 +00:00
|
|
|
}
|
|
|
|
}
|
2023-11-27 09:25:14 +00:00
|
|
|
|
2022-08-30 07:33:54 +00:00
|
|
|
final Set<String> processedIDs = {};
|
2023-11-27 09:25:14 +00:00
|
|
|
// if a file for localID doesn't exist, then mark it as processed
|
|
|
|
// otherwise the app will be stuck in retrying same set of ids
|
|
|
|
for (String localID in localIDsToProcess) {
|
|
|
|
if (!localIDsWithFile.contains(localID)) {
|
|
|
|
processedIDs.add(localID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_logger.info("files to process ${localIDsToProcess.length} for reupload, "
|
|
|
|
"missing localFile cnt ${processedIDs.length}");
|
|
|
|
|
2023-08-24 16:56:24 +00:00
|
|
|
for (EnteFile file in localFilesForUser) {
|
2022-08-05 11:09:56 +00:00
|
|
|
if (processedIDs.contains(file.localID)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
MediaUploadData uploadData;
|
|
|
|
try {
|
2022-08-29 17:43:17 +00:00
|
|
|
uploadData = await getUploadData(file);
|
2022-12-30 09:08:23 +00:00
|
|
|
if (uploadData.hashData != null &&
|
2022-08-29 07:58:49 +00:00
|
|
|
file.hash != null &&
|
2022-12-30 09:08:23 +00:00
|
|
|
(file.hash == uploadData.hashData!.fileHash ||
|
|
|
|
file.hash == uploadData.hashData!.zipHash)) {
|
2022-09-23 01:48:25 +00:00
|
|
|
_logger.info("Skip file update as hash matched ${file.tag}");
|
2022-08-05 11:09:56 +00:00
|
|
|
} else {
|
|
|
|
_logger.info(
|
2022-09-23 01:48:25 +00:00
|
|
|
"Marking for file update as hash did not match ${file.tag}",
|
2022-08-05 11:09:56 +00:00
|
|
|
);
|
2022-10-17 18:42:48 +00:00
|
|
|
await clearCache(file);
|
2023-08-22 15:05:29 +00:00
|
|
|
await FilesDB.instance.markFilesForReUpload(
|
|
|
|
userID,
|
2022-12-30 09:08:23 +00:00
|
|
|
file.localID!,
|
2022-08-05 11:09:56 +00:00
|
|
|
file.title,
|
|
|
|
file.location,
|
2022-12-30 09:08:23 +00:00
|
|
|
file.creationTime!,
|
|
|
|
file.modificationTime!,
|
2023-08-22 15:05:29 +00:00
|
|
|
file.fileType,
|
2022-08-05 11:09:56 +00:00
|
|
|
);
|
|
|
|
}
|
2022-12-30 09:08:23 +00:00
|
|
|
processedIDs.add(file.localID!);
|
2023-08-22 13:00:24 +00:00
|
|
|
} on InvalidFileError catch (e) {
|
2023-08-22 15:05:29 +00:00
|
|
|
if (e.reason == InvalidReason.livePhotoToImageTypeChanged ||
|
|
|
|
e.reason == InvalidReason.imageToLivePhotoTypeChanged) {
|
|
|
|
late FileType fileType;
|
|
|
|
if (e.reason == InvalidReason.livePhotoToImageTypeChanged) {
|
|
|
|
fileType = FileType.image;
|
|
|
|
} else if (e.reason == InvalidReason.imageToLivePhotoTypeChanged) {
|
|
|
|
fileType = FileType.livePhoto;
|
|
|
|
}
|
|
|
|
final int count = await FilesDB.instance.markFilesForReUpload(
|
|
|
|
userID,
|
|
|
|
file.localID!,
|
|
|
|
file.title,
|
|
|
|
file.location,
|
|
|
|
file.creationTime!,
|
|
|
|
file.modificationTime!,
|
|
|
|
fileType,
|
|
|
|
);
|
|
|
|
_logger.fine('fileType changed for ${file.tag} to ${e.reason} for '
|
|
|
|
'$count files');
|
|
|
|
} else {
|
|
|
|
_logger.severe("failed to check hash: invalid file ${file.tag}", e);
|
|
|
|
}
|
2023-01-11 08:30:20 +00:00
|
|
|
processedIDs.add(file.localID!);
|
2022-08-05 11:09:56 +00:00
|
|
|
} catch (e) {
|
2023-08-22 13:00:24 +00:00
|
|
|
_logger.severe("Failed to check hash", e);
|
2022-08-29 17:43:17 +00:00
|
|
|
} finally {}
|
2022-08-05 11:09:56 +00:00
|
|
|
}
|
2022-08-29 04:30:28 +00:00
|
|
|
await _fileUpdationDB.deleteByLocalIDs(
|
2022-08-05 11:35:32 +00:00
|
|
|
processedIDs.toList(),
|
2022-08-29 04:30:28 +00:00
|
|
|
FileUpdationDB.modificationTimeUpdated,
|
2022-08-05 11:35:32 +00:00
|
|
|
);
|
2022-08-05 11:09:56 +00:00
|
|
|
}
|
|
|
|
|
2023-12-06 08:02:11 +00:00
|
|
|
Future<void> checkLivePhoto(EnteFile file) async {
|
|
|
|
if (file.localID == null ||
|
|
|
|
file.localID!.isEmpty ||
|
|
|
|
!file.isUploaded ||
|
|
|
|
file.fileType != FileType.livePhoto ||
|
|
|
|
!file.isOwner) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_prefs.containsKey(_iosLivePhotoSizeMigrationDone)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bool hasEntry = await _fileUpdationDB.isExisting(
|
|
|
|
file.localID!,
|
|
|
|
FileUpdationDB.livePhotoCheck,
|
|
|
|
);
|
|
|
|
if (hasEntry) {
|
|
|
|
_logger.info('eager checkLivePhoto ${file.tag}');
|
|
|
|
await _checkLivePhotoWithLowOrUnknownSize([file.localID!]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-04 04:55:17 +00:00
|
|
|
Future<void> _handleLivePhotosSizedCheck() async {
|
|
|
|
try {
|
|
|
|
if (_prefs.containsKey(_iosLivePhotoSizeMigrationDone)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
await _importLivePhotoReUploadCandidates();
|
2023-12-06 07:04:06 +00:00
|
|
|
|
2023-12-04 04:55:17 +00:00
|
|
|
// singleRunLimit indicates number of files to check during single
|
|
|
|
// invocation of this method. The limit act as a crude way to limit the
|
|
|
|
// resource consumed by the method
|
2023-12-06 07:04:06 +00:00
|
|
|
const int singleRunLimit = 500;
|
2023-12-04 04:55:17 +00:00
|
|
|
final localIDsToProcess =
|
|
|
|
await _fileUpdationDB.getLocalIDsForPotentialReUpload(
|
|
|
|
singleRunLimit,
|
2023-12-06 03:44:33 +00:00
|
|
|
FileUpdationDB.livePhotoCheck,
|
2023-12-04 04:55:17 +00:00
|
|
|
);
|
|
|
|
if (localIDsToProcess.isNotEmpty) {
|
2023-12-06 08:02:11 +00:00
|
|
|
final chunksOf50 = localIDsToProcess.chunks(50);
|
|
|
|
for (final chunk in chunksOf50) {
|
2023-12-06 07:04:06 +00:00
|
|
|
final sTime = DateTime.now().microsecondsSinceEpoch;
|
2023-12-06 08:02:11 +00:00
|
|
|
final List<Future> futures = [];
|
|
|
|
final chunkOf10 = chunk.chunks(10);
|
|
|
|
for (final smallChunk in chunkOf10) {
|
|
|
|
futures.add(_checkLivePhotoWithLowOrUnknownSize(smallChunk));
|
|
|
|
}
|
|
|
|
await Future.wait(futures);
|
2023-12-06 07:04:06 +00:00
|
|
|
final eTime = DateTime.now().microsecondsSinceEpoch;
|
|
|
|
final d = Duration(microseconds: eTime - sTime);
|
|
|
|
_logger.info(
|
|
|
|
'Performed hashCheck for ${chunk.length} livePhoto files '
|
|
|
|
'completed in ${d.inSeconds.toString()} secs',
|
|
|
|
);
|
|
|
|
}
|
2023-12-04 04:55:17 +00:00
|
|
|
} else {
|
2023-12-06 03:44:33 +00:00
|
|
|
await _prefs.setBool(_iosLivePhotoSizeMigrationDone, true);
|
2023-12-04 04:55:17 +00:00
|
|
|
}
|
|
|
|
} catch (e, s) {
|
|
|
|
_logger.severe('error while checking livePhotoSize check', e, s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _checkLivePhotoWithLowOrUnknownSize(
|
|
|
|
List<String> localIDsToProcess,
|
|
|
|
) async {
|
|
|
|
final int userID = Configuration.instance.getUserID()!;
|
|
|
|
final List<EnteFile> result =
|
|
|
|
await FilesDB.instance.getLocalFiles(localIDsToProcess);
|
|
|
|
final List<EnteFile> localFilesForUser = [];
|
|
|
|
final Set<String> localIDsWithFile = {};
|
|
|
|
final Set<int> missingSizeIDs = {};
|
2023-12-06 03:50:28 +00:00
|
|
|
final Set<String> processedIDs = {};
|
2023-12-04 04:55:17 +00:00
|
|
|
for (EnteFile file in result) {
|
|
|
|
if (file.ownerID == null || file.ownerID == userID) {
|
|
|
|
localFilesForUser.add(file);
|
|
|
|
localIDsWithFile.add(file.localID!);
|
|
|
|
if (file.isUploaded && file.fileSize == null) {
|
|
|
|
missingSizeIDs.add(file.uploadedFileID!);
|
|
|
|
}
|
2023-12-06 03:50:28 +00:00
|
|
|
if (file.isUploaded && file.updationTime == null) {
|
|
|
|
// file already queued for re-upload
|
|
|
|
processedIDs.add(file.localID!);
|
|
|
|
}
|
2023-12-04 04:55:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (missingSizeIDs.isNotEmpty) {
|
|
|
|
await FilesService.instance.backFillSizes(missingSizeIDs.toList());
|
|
|
|
_logger.info('sizes back fill for ${missingSizeIDs.length} files');
|
|
|
|
// return early, let the check run in the next batch
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if a file for localID doesn't exist, then mark it as processed
|
|
|
|
// otherwise the app will be stuck in retrying same set of ids
|
|
|
|
|
|
|
|
for (String localID in localIDsToProcess) {
|
|
|
|
if (!localIDsWithFile.contains(localID)) {
|
|
|
|
processedIDs.add(localID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_logger.info(" check ${localIDsToProcess.length} files for livePhotoSize, "
|
|
|
|
"missing file cnt ${processedIDs.length}");
|
|
|
|
|
|
|
|
for (EnteFile file in localFilesForUser) {
|
|
|
|
if (file.fileSize == null) {
|
|
|
|
_logger.info('fileSize still null, skip this file');
|
|
|
|
continue;
|
|
|
|
} else if (file.fileType != FileType.livePhoto) {
|
|
|
|
_logger.severe('fileType is not livePhoto, skip this file');
|
|
|
|
processedIDs.add(file.localID!);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (processedIDs.contains(file.localID)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
try {
|
2023-12-06 03:44:33 +00:00
|
|
|
late MediaUploadData uploadData;
|
|
|
|
late int mediaUploadSize;
|
|
|
|
(uploadData, mediaUploadSize) = await getUploadDataWithSizeSize(file);
|
|
|
|
if ((file.fileSize! - mediaUploadSize).abs() > twoHundredKb) {
|
|
|
|
_logger.info(
|
|
|
|
'Re-upload livePhoto localHash ${uploadData.hashData?.fileHash ?? "null"} & localSize: $mediaUploadSize'
|
|
|
|
' and remoteHash ${file.hash ?? "null"} & removeSize: ${file.fileSize!}',
|
|
|
|
);
|
|
|
|
await FilesDB.instance.markFilesForReUpload(
|
|
|
|
userID,
|
|
|
|
file.localID!,
|
|
|
|
file.title,
|
|
|
|
file.location,
|
|
|
|
file.creationTime!,
|
|
|
|
file.modificationTime!,
|
|
|
|
file.fileType,
|
|
|
|
);
|
|
|
|
}
|
2023-12-04 04:55:17 +00:00
|
|
|
processedIDs.add(file.localID!);
|
|
|
|
} on InvalidFileError catch (e) {
|
|
|
|
if (e.reason == InvalidReason.livePhotoToImageTypeChanged ||
|
|
|
|
e.reason == InvalidReason.imageToLivePhotoTypeChanged) {
|
|
|
|
// let existing file update check handle this case
|
|
|
|
_fileUpdationDB.insertMultiple(
|
|
|
|
[file.localID!],
|
|
|
|
FileUpdationDB.modificationTimeUpdated,
|
|
|
|
).ignore();
|
|
|
|
} else {
|
|
|
|
_logger.severe("livePhoto check failed: invalid file ${file.tag}", e);
|
|
|
|
}
|
|
|
|
processedIDs.add(file.localID!);
|
|
|
|
} catch (e) {
|
|
|
|
_logger.severe("livePhoto check failed", e);
|
|
|
|
} finally {}
|
|
|
|
}
|
2023-12-06 03:44:33 +00:00
|
|
|
_logger.info('completed check for ${localIDsToProcess.length} files');
|
2023-12-04 04:55:17 +00:00
|
|
|
await _fileUpdationDB.deleteByLocalIDs(
|
|
|
|
processedIDs.toList(),
|
2023-12-06 03:44:33 +00:00
|
|
|
FileUpdationDB.livePhotoCheck,
|
2023-12-04 04:55:17 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _importLivePhotoReUploadCandidates() async {
|
|
|
|
if (_prefs.containsKey(_doneLivePhotoImport)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_logger.info('_importLivePhotoReUploadCandidates');
|
|
|
|
final EnteWatch watch = EnteWatch("_importLivePhotoReUploadCandidates");
|
|
|
|
final int ownerID = Configuration.instance.getUserID()!;
|
2023-12-06 03:44:33 +00:00
|
|
|
final List<String> localIDs =
|
|
|
|
await FilesDB.instance.getLivePhotosForUser(ownerID);
|
2023-12-04 04:55:17 +00:00
|
|
|
await _fileUpdationDB.insertMultiple(
|
|
|
|
localIDs,
|
2023-12-06 03:44:33 +00:00
|
|
|
FileUpdationDB.livePhotoCheck,
|
2023-12-04 04:55:17 +00:00
|
|
|
);
|
|
|
|
watch.log("imported ${localIDs.length} files");
|
|
|
|
await _prefs.setBool(_doneLivePhotoImport, true);
|
|
|
|
}
|
|
|
|
|
2023-08-24 16:56:24 +00:00
|
|
|
Future<MediaUploadData> getUploadData(EnteFile file) async {
|
2022-08-29 17:43:17 +00:00
|
|
|
final mediaUploadData = await getUploadDataFromEnteFile(file);
|
|
|
|
// delete the file from app's internal cache if it was copied to app
|
|
|
|
// for upload. Shared Media should only be cleared when the upload
|
|
|
|
// succeeds.
|
2022-12-30 09:08:23 +00:00
|
|
|
if (Platform.isIOS && mediaUploadData.sourceFile != null) {
|
|
|
|
await mediaUploadData.sourceFile?.delete();
|
2022-08-29 17:43:17 +00:00
|
|
|
}
|
|
|
|
return mediaUploadData;
|
|
|
|
}
|
2023-12-06 03:44:33 +00:00
|
|
|
|
|
|
|
Future<(MediaUploadData, int)> getUploadDataWithSizeSize(
|
|
|
|
EnteFile file,
|
|
|
|
) async {
|
|
|
|
final mediaUploadData = await getUploadDataFromEnteFile(file);
|
|
|
|
final int size = await mediaUploadData.sourceFile!.length();
|
|
|
|
// delete the file from app's internal cache if it was copied to app
|
|
|
|
// for upload. Shared Media should only be cleared when the upload
|
|
|
|
// succeeds.
|
|
|
|
if (Platform.isIOS && mediaUploadData.sourceFile != null) {
|
|
|
|
await mediaUploadData.sourceFile?.delete();
|
|
|
|
}
|
|
|
|
return (mediaUploadData, size);
|
|
|
|
}
|
2022-06-08 08:49:23 +00:00
|
|
|
}
|