refactor
This commit is contained in:
@@ -739,22 +739,6 @@ class FilesDB with SqlDbBase {
|
||||
return convertToFiles(results);
|
||||
}
|
||||
|
||||
// todo:rewrite (upload related)
|
||||
Future<Set<String>> getExistingLocalFileIDs(int ownerID) async {
|
||||
final db = await instance.sqliteAsyncDB;
|
||||
final rows = await db.getAll(
|
||||
'SELECT DISTINCT $columnLocalID FROM $filesTable '
|
||||
'WHERE $columnLocalID IS NOT NULL AND ($columnOwnerID IS NULL OR '
|
||||
'$columnOwnerID = ?)',
|
||||
[ownerID],
|
||||
);
|
||||
final result = <String>{};
|
||||
for (final row in rows) {
|
||||
result.add(row[columnLocalID] as String);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// todo:rewrite (upload related)
|
||||
Future<void> markFilesForReUpload(
|
||||
int ownerID,
|
||||
@@ -1167,8 +1151,10 @@ class FilesDB with SqlDbBase {
|
||||
longitude,
|
||||
getInt(file.fileType),
|
||||
file.modificationTime,
|
||||
file.encryptedKey,
|
||||
file.keyDecryptionNonce,
|
||||
// file.encryptedKey,
|
||||
'no_encrypted_key', // encryptedKey is not used in this context
|
||||
// file.keyDecryptionNonce,
|
||||
'no_key_decryption_nonce', // keyDecryptionNonce is not used in this context
|
||||
file.fileDecryptionHeader,
|
||||
file.thumbnailDecryptionHeader,
|
||||
'na',
|
||||
@@ -1234,8 +1220,8 @@ class FilesDB with SqlDbBase {
|
||||
file.modificationTime = row[columnModificationTime];
|
||||
file.updationTime = row[columnUpdationTime] ?? -1;
|
||||
file.addedTime = row[columnAddedTime];
|
||||
file.encryptedKey = row[columnEncryptedKey];
|
||||
file.keyDecryptionNonce = row[columnKeyDecryptionNonce];
|
||||
// file.encryptedKey = row[columnEncryptedKey];
|
||||
// file.keyDecryptionNonce = row[columnKeyDecryptionNonce];
|
||||
file.fileDecryptionHeader = row[columnFileDecryptionHeader];
|
||||
file.thumbnailDecryptionHeader = row[columnThumbnailDecryptionHeader];
|
||||
file.fileSubType = row[columnFileSubType] ?? -1;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import "package:photos/core/configuration.dart";
|
||||
import 'package:photos/models/file/extensions/r_asset_props.dart';
|
||||
import "package:photos/models/file/file.dart";
|
||||
import "package:photos/models/file/file_type.dart";
|
||||
import "package:photos/services/collections_service.dart";
|
||||
@@ -6,7 +7,7 @@ import "package:photos/services/collections_service.dart";
|
||||
extension FilePropsExtn on EnteFile {
|
||||
bool get isLivePhoto => fileType == FileType.livePhoto;
|
||||
|
||||
bool get isMotionPhoto => (pubMagicMetadata?.mvi ?? 0) > 0;
|
||||
bool get isMotionPhoto => rAsset?.isMotionPhoto ?? false;
|
||||
|
||||
bool get isLiveOrMotionPhoto => isLivePhoto || isMotionPhoto;
|
||||
|
||||
@@ -51,8 +52,7 @@ extension FilePropsExtn on EnteFile {
|
||||
bool get skipIndex => !isUploaded || fileType == FileType.other;
|
||||
|
||||
bool canReUpload(int userID) =>
|
||||
localID != null &&
|
||||
localID!.isNotEmpty &&
|
||||
lAsset != null &&
|
||||
cf != null &&
|
||||
isOwner &&
|
||||
(CollectionsService.instance
|
||||
|
||||
8
mobile/lib/models/file/extensions/r_asset_props.dart
Normal file
8
mobile/lib/models/file/extensions/r_asset_props.dart
Normal file
@@ -0,0 +1,8 @@
|
||||
import "package:photos/models/file/remote/asset.dart";
|
||||
import "package:photos/models/metadata/file_magic.dart";
|
||||
|
||||
extension RemoteAssetExtension on RemoteAsset {
|
||||
bool get isMotionPhoto {
|
||||
return publicMetadata?.data[motionVideoIndexKey] ?? 0 > 0;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'dart:io';
|
||||
|
||||
import "package:ente_crypto/ente_crypto.dart";
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:path/path.dart';
|
||||
@@ -43,11 +42,10 @@ class EnteFile {
|
||||
String? exif;
|
||||
String? hash;
|
||||
int? metadataVersion;
|
||||
String? encryptedKey;
|
||||
String? keyDecryptionNonce;
|
||||
String? fileDecryptionHeader;
|
||||
@Deprecated(
|
||||
'use remoteAsset.thumbHeader instead. This will be removed in future')
|
||||
'use remoteAsset.thumbHeader instead. This will be removed in future',
|
||||
)
|
||||
String? thumbnailDecryptionHeader;
|
||||
|
||||
int? get fileSize {
|
||||
@@ -136,9 +134,6 @@ class EnteFile {
|
||||
file.metadataVersion = kCurrentMetadataVersion;
|
||||
file.duration = rAsset.durationInSec;
|
||||
file.collectionID = collection.collectionID;
|
||||
file.encryptedKey = CryptoUtil.bin2base64(collection.encFileKey);
|
||||
file.keyDecryptionNonce = CryptoUtil.bin2base64(collection.encFileKeyNonce);
|
||||
|
||||
file.pubMagicMetadata =
|
||||
PubMagicMetadata.fromMap(rAsset.publicMetadata?.data);
|
||||
return file;
|
||||
@@ -373,8 +368,6 @@ class EnteFile {
|
||||
String? exif,
|
||||
String? hash,
|
||||
int? metadataVersion,
|
||||
String? encryptedKey,
|
||||
String? keyDecryptionNonce,
|
||||
String? fileDecryptionHeader,
|
||||
String? thumbnailDecryptionHeader,
|
||||
int? fileSize,
|
||||
@@ -406,8 +399,6 @@ class EnteFile {
|
||||
..exif = exif ?? this.exif
|
||||
..hash = hash ?? this.hash
|
||||
..metadataVersion = metadataVersion ?? this.metadataVersion
|
||||
..encryptedKey = encryptedKey ?? this.encryptedKey
|
||||
..keyDecryptionNonce = keyDecryptionNonce ?? this.keyDecryptionNonce
|
||||
..fileDecryptionHeader = fileDecryptionHeader ?? this.fileDecryptionHeader
|
||||
..thumbnailDecryptionHeader =
|
||||
thumbnailDecryptionHeader ?? this.thumbnailDecryptionHeader
|
||||
|
||||
@@ -21,7 +21,7 @@ class FilesSplit {
|
||||
ownedByOtherUsers = [],
|
||||
pendingUploads = [];
|
||||
for (var f in files) {
|
||||
if (f.ownerID == null || f.uploadedFileID == null) {
|
||||
if (f.ownerID == null || !f.isUploaded) {
|
||||
pendingUploads.add(f);
|
||||
} else if (f.ownerID == currentUserID) {
|
||||
ownedByCurrentUser.add(f);
|
||||
|
||||
@@ -1622,7 +1622,7 @@ class CollectionsService {
|
||||
|
||||
params["files"].add(
|
||||
CollectionFileRequest(
|
||||
batchFile.uploadedFileID!,
|
||||
batchFile.remoteID,
|
||||
CryptoUtil.bin2base64(encryptedKeyData.encryptedData!),
|
||||
CryptoUtil.bin2base64(encryptedKeyData.nonce!),
|
||||
).toMap(),
|
||||
@@ -1659,7 +1659,7 @@ class CollectionsService {
|
||||
srcToCopiedFileIDs.remove(srcRemoteID);
|
||||
newFileKeys.remove(srcRemoteID);
|
||||
} else {
|
||||
throw Exception("Failed to copy file ${file.uploadedFileID}");
|
||||
throw Exception("Failed to copy file $srcRemoteID");
|
||||
}
|
||||
}
|
||||
if (srcToCopiedFileIDs.isNotEmpty) {
|
||||
|
||||
@@ -30,6 +30,7 @@ import "package:photos/models/backup/backup_item.dart";
|
||||
import "package:photos/models/backup/backup_item_status.dart";
|
||||
import 'package:photos/models/file/file.dart';
|
||||
import 'package:photos/models/file/file_type.dart';
|
||||
import "package:photos/models/file/remote/collection_file.dart";
|
||||
import "package:photos/models/metadata/file_magic.dart";
|
||||
import "package:photos/models/user_details.dart";
|
||||
import 'package:photos/module/upload/model/upload_url.dart';
|
||||
@@ -1175,12 +1176,20 @@ class FileUploader {
|
||||
try {
|
||||
final response = await _enteDio.post("/files", data: request);
|
||||
final data = response.data;
|
||||
file.uploadedFileID = data["id"];
|
||||
final int remoteID = data["id"];
|
||||
final int updatedAt = data["updationTime"];
|
||||
file.uploadedFileID = remoteID;
|
||||
file.collectionID = collectionID;
|
||||
file.updationTime = data["updationTime"];
|
||||
file.ownerID = data["ownerID"];
|
||||
file.encryptedKey = encryptedKey;
|
||||
file.keyDecryptionNonce = keyDecryptionNonce;
|
||||
file.cf = CollectionFile(
|
||||
collectionID: collectionID,
|
||||
fileID: remoteID,
|
||||
encFileKey: CryptoUtil.base642bin(encryptedKey),
|
||||
encFileKeyNonce: CryptoUtil.base642bin(keyDecryptionNonce),
|
||||
updatedAt: updatedAt,
|
||||
createdAt: updatedAt,
|
||||
);
|
||||
file.fileDecryptionHeader = fileDecryptionHeader;
|
||||
file.thumbnailDecryptionHeader = thumbnailDecryptionHeader;
|
||||
return file;
|
||||
|
||||
@@ -175,7 +175,7 @@ Future<bool> editTime(
|
||||
final files =
|
||||
filesToEditedTimes.keys.where((file) => file.isUploaded).toList();
|
||||
if (files.isEmpty) {
|
||||
_logger.severe('No files to edit time for');
|
||||
_logger.warning('No files to edit time for');
|
||||
return false;
|
||||
}
|
||||
final fileIdToTimeUpdate = <int, Map<String, dynamic>>{};
|
||||
@@ -183,7 +183,7 @@ Future<bool> editTime(
|
||||
final file = entry.key;
|
||||
if (!file.isUploaded) continue;
|
||||
final editedTime = entry.value;
|
||||
fileIdToTimeUpdate[file.uploadedFileID!] = {editTimeKey: editedTime};
|
||||
fileIdToTimeUpdate[file.remoteID] = {editTimeKey: editedTime};
|
||||
}
|
||||
|
||||
final dialog = createProgressDialog(context, S.of(context).pleaseWait);
|
||||
|
||||
@@ -105,7 +105,7 @@ Future<List<FileMLInstruction>> getFilesForMlIndexing() async {
|
||||
if (enteFile.skipIndex) {
|
||||
continue;
|
||||
}
|
||||
final int id = enteFile.uploadedFileID!;
|
||||
final int id = enteFile.remoteID;
|
||||
if (queuedFiledIDs.contains(id)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user