Clean up EnteFile
This commit is contained in:
@@ -605,7 +605,7 @@ class FilesDB with SqlDbBase {
|
||||
file.fileType = getFileType(row[columnFileType]);
|
||||
file.creationTime = row[columnCreationTime];
|
||||
file.modificationTime = row[columnModificationTime];
|
||||
file.updationTime = row[columnUpdationTime] ?? -1;
|
||||
// file.updationTime = row[columnUpdationTime] ?? -1;
|
||||
// file.encryptedKey = row[columnEncryptedKey];
|
||||
// file.keyDecryptionNonce = row[columnKeyDecryptionNonce];
|
||||
// file.fileDecryptionHeader = row[columnFileDecryptionHeader];
|
||||
@@ -614,7 +614,7 @@ class FilesDB with SqlDbBase {
|
||||
file.duration = row[columnDuration] ?? 0;
|
||||
// file.exif = row[columnExif];
|
||||
file.hash = row[columnHash];
|
||||
file.metadataVersion = row[columnMetadataVersion] ?? 0;
|
||||
// file.metadataVersion = row[columnMetadataVersion] ?? 0;
|
||||
// file.fileSize = row[columnFileSize];
|
||||
|
||||
// file.mMdVersion = row[columnMMdVersion] ?? 0;
|
||||
|
||||
@@ -30,17 +30,12 @@ class EnteFile {
|
||||
String? deviceFolder;
|
||||
int? creationTime;
|
||||
int? modificationTime;
|
||||
int? updationTime;
|
||||
|
||||
late Location? location;
|
||||
late FileType fileType;
|
||||
int? fileSubType;
|
||||
int? duration;
|
||||
String? hash;
|
||||
int? metadataVersion;
|
||||
|
||||
// in Version 1, live photo hash is stored as zip's hash.
|
||||
// in V2: LivePhoto hash is stored as imgHash:vidHash
|
||||
static const kCurrentMetadataVersion = 2;
|
||||
|
||||
EnteFile();
|
||||
|
||||
@@ -55,7 +50,6 @@ class EnteFile {
|
||||
file.creationTime = AssetEntityService.estimateCreationTime(lAsset);
|
||||
file.modificationTime = lAsset.modifiedDateTime.microsecondsSinceEpoch;
|
||||
file.fileSubType = lAsset.subtype;
|
||||
file.metadataVersion = kCurrentMetadataVersion;
|
||||
return file;
|
||||
}
|
||||
|
||||
@@ -70,7 +64,6 @@ class EnteFile {
|
||||
file.creationTime = asset.createDateTime.microsecondsSinceEpoch;
|
||||
file.modificationTime = asset.modifiedDateTime.microsecondsSinceEpoch;
|
||||
file.fileSubType = asset.subtype;
|
||||
file.metadataVersion = kCurrentMetadataVersion;
|
||||
file.duration = asset.duration;
|
||||
return file;
|
||||
}
|
||||
@@ -103,7 +96,6 @@ class EnteFile {
|
||||
file.creationTime = rAsset.creationTime;
|
||||
file.modificationTime = rAsset.modificationTime;
|
||||
file.fileSubType = rAsset.subType;
|
||||
file.metadataVersion = kCurrentMetadataVersion;
|
||||
file.duration = rAsset.durationInSec;
|
||||
file.collectionID = collection.collectionID;
|
||||
return file;
|
||||
@@ -179,7 +171,7 @@ class EnteFile {
|
||||
String toString() {
|
||||
return '''File(generatedID: $generatedID, localID: $localID, title: $title,
|
||||
type: $fileType, uploadedFileId: $uploadedFileID, modificationTime: $modificationTime,
|
||||
ownerID: $ownerID, collectionID: $collectionID, updationTime: $updationTime)''';
|
||||
ownerID: $ownerID, collectionID: $collectionID, updationTime: ${cf?.updatedAt})''';
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -239,12 +231,10 @@ class EnteFile {
|
||||
..deviceFolder = deviceFolder ?? this.deviceFolder
|
||||
..creationTime = creationTime ?? this.creationTime
|
||||
..modificationTime = modificationTime ?? this.modificationTime
|
||||
..updationTime = updationTime ?? this.updationTime
|
||||
..location = location ?? this.location
|
||||
..fileType = fileType ?? this.fileType
|
||||
..fileSubType = fileSubType ?? this.fileSubType
|
||||
..duration = duration ?? this.duration
|
||||
..hash = hash ?? this.hash
|
||||
..metadataVersion = metadataVersion ?? this.metadataVersion;
|
||||
..hash = hash ?? this.hash;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,9 @@ import "package:photos/utils/exif_util.dart";
|
||||
import "package:photos/utils/panorama_util.dart";
|
||||
|
||||
final _logger = Logger("FileUtil");
|
||||
// in Version 1, live photo hash is stored as zip's hash.
|
||||
// in V2: LivePhoto hash is stored as imgHash:vidHash
|
||||
const kCurrentMetadataVersion = 2;
|
||||
|
||||
Future<int?> motionVideoIndex(Map<String, dynamic> args) async {
|
||||
final String path = args['path'];
|
||||
@@ -134,7 +137,7 @@ Future<Map<String, dynamic>> getMetadata(
|
||||
final metadata = <String, dynamic>{
|
||||
"localID": asset?.id,
|
||||
"hash": uploadMedia.hash,
|
||||
"version": EnteFile.kCurrentMetadataVersion,
|
||||
"version": kCurrentMetadataVersion,
|
||||
"title": title,
|
||||
"deviceFolder": deviceFolder,
|
||||
"creationTime": creationTime,
|
||||
|
||||
@@ -517,7 +517,7 @@ class FileUploader {
|
||||
|
||||
try {
|
||||
final bool isUpdatedFile =
|
||||
file.uploadedFileID != null && file.updationTime == -1;
|
||||
file.rAsset != null && file.cf?.updatedAt == -1;
|
||||
_logger.info(
|
||||
'starting ${forcedUpload ? 'forced' : ''} '
|
||||
'${isUpdatedFile ? 're-upload' : 'upload'} of ${file.toString()}',
|
||||
|
||||
@@ -126,7 +126,7 @@ class FilesService {
|
||||
BuildContext context,
|
||||
) async {
|
||||
final List<EnteFile> uploadedFiles =
|
||||
files.where((element) => element.uploadedFileID != null).toList();
|
||||
files.where((element) => element.rAsset != null).toList();
|
||||
|
||||
final List<EnteFile> remoteFilesToUpdate = [];
|
||||
final Map<int, Map<String, dynamic>> fileIDToUpdateMetadata = {};
|
||||
|
||||
@@ -27,7 +27,7 @@ import 'package:synchronized/synchronized.dart';
|
||||
final LRUMap<String, bool> trackOriginFetchForUploadOrML = LRUMap(200);
|
||||
|
||||
class LocalImportService {
|
||||
final _log = Logger("LocalSyncService");
|
||||
final _log = Logger("LocalImportService");
|
||||
late SharedPreferences _prefs;
|
||||
Completer<void>? _existingSync;
|
||||
Completer<bool>? _fullSync;
|
||||
|
||||
@@ -182,7 +182,7 @@ class SmartMemoriesService {
|
||||
);
|
||||
final Set<EnteFile> allFiles = {};
|
||||
for (final file in allFilesFromSearchService) {
|
||||
if (file.uploadedFileID != null && file.creationTime != null) {
|
||||
if (file.rAsset != null && file.creationTime != null) {
|
||||
allFiles.add(file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -614,9 +614,9 @@ class CollectionActions {
|
||||
final Map<int, List<EnteFile>> destCollectionToFilesMap = {};
|
||||
final List<int> uploadedIDs = [];
|
||||
for (EnteFile f in split.ownedByCurrentUser) {
|
||||
if (f.uploadedFileID != null) {
|
||||
pendingAssignMap[f.uploadedFileID!] = f;
|
||||
uploadedIDs.add(f.uploadedFileID!);
|
||||
if (f.rAsset != null) {
|
||||
pendingAssignMap[f.rAsset!.id] = f;
|
||||
uploadedIDs.add(f.rAsset!.id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,10 +27,9 @@ Future<void> showSingleFileDeleteSheet(
|
||||
final String fileType = file.fileType == FileType.video
|
||||
? S.of(context).videoSmallCase
|
||||
: S.of(context).photoSmallCase;
|
||||
final bool isBothLocalAndRemote =
|
||||
file.uploadedFileID != null && file.localID != null;
|
||||
final bool isLocalOnly = file.uploadedFileID == null && file.localID != null;
|
||||
final bool isRemoteOnly = file.uploadedFileID != null && file.localID == null;
|
||||
final bool isBothLocalAndRemote = file.rAsset != null && file.localID != null;
|
||||
final bool isLocalOnly = file.rAsset == null && file.localID != null;
|
||||
final bool isRemoteOnly = file.rAsset != null && file.localID == null;
|
||||
final String bodyHighlight = S.of(context).singleFileDeleteHighlight;
|
||||
String body = "";
|
||||
if (isBothLocalAndRemote) {
|
||||
|
||||
@@ -40,7 +40,7 @@ class _BackupStatusScreenState extends State<BackupStatusScreen> {
|
||||
Future<void> getAllFiles() async {
|
||||
result = (await SearchService.instance.getAllFilesForSearch())
|
||||
.where(
|
||||
(e) => e.uploadedFileID != null && e.isOwner,
|
||||
(e) => e.rAsset != null && e.isOwner,
|
||||
)
|
||||
.map(
|
||||
(e) {
|
||||
@@ -53,7 +53,7 @@ class _BackupStatusScreenState extends State<BackupStatusScreen> {
|
||||
},
|
||||
)
|
||||
.sorted(
|
||||
(a, b) => (b.file.uploadedFileID!).compareTo(a.file.uploadedFileID!),
|
||||
(a, b) => (b.file.rAsset!.id).compareTo(a.file.rAsset!.id),
|
||||
)
|
||||
.toList();
|
||||
_fileUploadedSubscription =
|
||||
|
||||
@@ -370,7 +370,7 @@ class _BodyState extends State<_Body> {
|
||||
}
|
||||
|
||||
Future<void> _onEditFileRequested(EnteFile file) async {
|
||||
if (file.uploadedFileID != null &&
|
||||
if (file.rAsset != null &&
|
||||
file.ownerID != Configuration.instance.getUserID()) {
|
||||
_logger.severe(
|
||||
"Attempt to edit unowned file",
|
||||
|
||||
@@ -301,7 +301,7 @@ class _FileDetailsWidgetState extends State<FileDetailsWidget> {
|
||||
]);
|
||||
}
|
||||
|
||||
if (file.isUploaded && file.updationTime != null) {
|
||||
if (file.isUploaded && file.cf?.updatedAt != null) {
|
||||
fileDetailsTiles.addAll(
|
||||
[
|
||||
BackedUpTimeItemWidget(file),
|
||||
|
||||
@@ -36,8 +36,8 @@ class _VideoStreamChangeWidgetState extends State<VideoStreamChangeWidget> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bool isPreviewAvailable = widget.file.uploadedFileID != null &&
|
||||
(fileDataService.previewIds.containsKey(widget.file.uploadedFileID));
|
||||
final bool isPreviewAvailable = widget.file.rAsset != null &&
|
||||
(fileDataService.previewIds.containsKey(widget.file.rAsset!.id));
|
||||
if (!isPreviewAvailable) {
|
||||
return const SizedBox();
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class ZoomableLiveImageNew extends StatefulWidget {
|
||||
final Decoration? backgroundDecoration;
|
||||
final bool isFromMemories;
|
||||
final Function({required int memoryDuration})? onFinalFileLoad;
|
||||
|
||||
|
||||
const ZoomableLiveImageNew(
|
||||
this.enteFile, {
|
||||
super.key,
|
||||
@@ -172,7 +172,7 @@ class _ZoomableLiveImageNewState extends State<ZoomableLiveImageNew>
|
||||
// getFile with liveVideo as true can fail for file with localID when
|
||||
// the live photo was downloaded from remote.
|
||||
if ((videoFile == null || !videoFile.existsSync()) &&
|
||||
_enteFile.uploadedFileID != null) {
|
||||
_enteFile.rAsset != null) {
|
||||
videoFile = await getFileFromServer(widget.enteFile, liveVideo: true)
|
||||
.timeout(const Duration(seconds: 15))
|
||||
.onError((dynamic e, s) {
|
||||
|
||||
@@ -12,7 +12,7 @@ class BackedUpTimeItemWidget extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final dateTimeForUpdationTime =
|
||||
DateTime.fromMicrosecondsSinceEpoch(file.updationTime!);
|
||||
DateTime.fromMicrosecondsSinceEpoch(file.cf!.updatedAt);
|
||||
return InfoItemWidget(
|
||||
key: const ValueKey("Backedup date"),
|
||||
leadingIcon: Icons.backup_outlined,
|
||||
|
||||
@@ -5,6 +5,7 @@ import "package:photos/theme/ente_theme.dart";
|
||||
import "package:photos/ui/components/info_item_widget.dart";
|
||||
import "package:photos/ui/viewer/date/edit_date_sheet.dart";
|
||||
import "package:photos/utils/standalone/date_time.dart";
|
||||
|
||||
class CreationTimeItem extends StatefulWidget {
|
||||
final EnteFile file;
|
||||
final int currentUserID;
|
||||
@@ -34,7 +35,7 @@ class _CreationTimeItemState extends State<CreationTimeItem> {
|
||||
]),
|
||||
editOnTap: ((widget.file.ownerID == null ||
|
||||
widget.file.ownerID == widget.currentUserID) &&
|
||||
widget.file.uploadedFileID != null)
|
||||
widget.file.rAsset != null)
|
||||
? () {
|
||||
_showDateTimePicker(widget.file);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ class TrashPage extends StatelessWidget {
|
||||
reloadEvent: Bus.instance.on<FilesUpdatedEvent>().where(
|
||||
(event) =>
|
||||
event.updatedFiles.firstWhereOrNull(
|
||||
(element) => element.uploadedFileID != null,
|
||||
(element) => element.rAsset != null,
|
||||
) !=
|
||||
null,
|
||||
),
|
||||
|
||||
@@ -144,22 +144,22 @@ Future<void> deleteFilesFromRemoteOnly(
|
||||
BuildContext context,
|
||||
List<EnteFile> files,
|
||||
) async {
|
||||
files.removeWhere((element) => element.uploadedFileID == null);
|
||||
files.removeWhere((element) => element.rAsset == null);
|
||||
if (files.isEmpty) {
|
||||
showToast(context, S.of(context).selectedFilesAreNotOnEnte);
|
||||
return;
|
||||
}
|
||||
_logger.info(
|
||||
"Trying to deleteFilesFromRemoteOnly " +
|
||||
files.map((f) => f.uploadedFileID).toString(),
|
||||
files.map((f) => f.remoteID).toString(),
|
||||
);
|
||||
final updatedCollectionIDs = <int>{};
|
||||
final List<int> uploadedFileIDs = [];
|
||||
final List<TrashRequest> trashRequests = [];
|
||||
for (final file in files) {
|
||||
updatedCollectionIDs.add(file.collectionID!);
|
||||
uploadedFileIDs.add(file.uploadedFileID!);
|
||||
trashRequests.add(TrashRequest(file.uploadedFileID!, file.collectionID!));
|
||||
uploadedFileIDs.add(file.remoteID);
|
||||
trashRequests.add(TrashRequest(file.remoteID, file.collectionID!));
|
||||
}
|
||||
try {
|
||||
await trashSyncService.trashFilesOnServer(trashRequests);
|
||||
|
||||
@@ -221,8 +221,8 @@ Future<List<AlbumFilter>> _curateAlbumFilters(
|
||||
final albumFilters = <AlbumFilter>[];
|
||||
final uploadedIDs = <int>[];
|
||||
for (EnteFile file in files) {
|
||||
if (file.uploadedFileID != null && file.uploadedFileID != -1) {
|
||||
uploadedIDs.add(file.uploadedFileID!);
|
||||
if (file.rAsset != null) {
|
||||
uploadedIDs.add(file.rAsset!.id);
|
||||
}
|
||||
}
|
||||
final idToOccurrence = await remoteDB.getCollectionIdToFileCount(uploadedIDs);
|
||||
|
||||
Reference in New Issue
Block a user