|
@@ -61,8 +61,8 @@ class tableMetadata: Object, NCUserBaseUrl {
|
|
|
@objc dynamic var iconName = ""
|
|
|
@objc dynamic var iconUrl = ""
|
|
|
@objc dynamic var isExtractFile: Bool = false
|
|
|
- @objc dynamic var livePhoto: Bool = false
|
|
|
@objc dynamic var livePhotoFile = ""
|
|
|
+ @objc dynamic var livePhotoServer: Bool = false
|
|
|
@objc dynamic var mountType = ""
|
|
|
@objc dynamic var name = "" // for unifiedSearch is the provider.id
|
|
|
@objc dynamic var note = ""
|
|
@@ -249,6 +249,10 @@ extension tableMetadata {
|
|
|
NCUtilityFileSystem().isDirectoryE2EETop(account: account, serverUrl: serverUrl)
|
|
|
}
|
|
|
|
|
|
+ var isLivePhoto: Bool {
|
|
|
+ !livePhotoFile.isEmpty
|
|
|
+ }
|
|
|
+
|
|
|
/// Returns false if the user is lokced out of the file. I.e. The file is locked but by somone else
|
|
|
func canUnlock(as user: String) -> Bool {
|
|
|
return !lock || (lockOwner == user && lockOwnerType == 0)
|
|
@@ -342,9 +346,7 @@ extension NCManageDatabase {
|
|
|
metadata.height = file.height
|
|
|
metadata.width = file.width
|
|
|
metadata.livePhotoFile = file.livePhotoFile
|
|
|
- if !metadata.livePhotoFile.isEmpty {
|
|
|
- metadata.livePhoto = true
|
|
|
- }
|
|
|
+ metadata.livePhotoServer = file.livePhotoServer
|
|
|
|
|
|
// E2EE find the fileName for fileNameView
|
|
|
if isDirectoryE2EE || file.e2eEncrypted {
|
|
@@ -393,30 +395,10 @@ extension NCManageDatabase {
|
|
|
counter += 1
|
|
|
}
|
|
|
|
|
|
- //
|
|
|
- // Detect Live photo
|
|
|
- //
|
|
|
- var metadataOutput: [tableMetadata] = []
|
|
|
- metadatas = metadatas.sorted(by: {$0.fileNameView < $1.fileNameView})
|
|
|
-
|
|
|
- for index in metadatas.indices {
|
|
|
- let metadata = metadatas[index]
|
|
|
- if index < metadatas.count - 1,
|
|
|
- metadata.fileNoExtension == metadatas[index + 1].fileNoExtension,
|
|
|
- ((metadata.classFile == NKCommon.TypeClassFile.image.rawValue && metadatas[index + 1].classFile == NKCommon.TypeClassFile.video.rawValue) || (metadata.classFile == NKCommon.TypeClassFile.video.rawValue && metadatas[index + 1].classFile == NKCommon.TypeClassFile.image.rawValue)) {
|
|
|
- metadata.livePhoto = true
|
|
|
- metadatas[index + 1].livePhoto = true
|
|
|
- let metadata1 = metadata
|
|
|
- let metadata2 = metadatas[index + 1]
|
|
|
- NCLivePhoto().setLivePhoto(metadata1: metadata1, metadata2: metadata2)
|
|
|
- }
|
|
|
- metadataOutput.append(metadata)
|
|
|
- }
|
|
|
-
|
|
|
- completion(metadataFolder, metadataFolders, metadataOutput)
|
|
|
+ completion(metadataFolder, metadataFolders, metadatas)
|
|
|
}
|
|
|
|
|
|
- func createMetadata(account: String, user: String, userId: String, fileName: String, fileNameView: String, ocId: String, serverUrl: String, urlBase: String, url: String, contentType: String, isLivePhoto: Bool = false, isUrl: Bool = false, name: String = NCGlobal.shared.appName, subline: String? = nil, iconName: String? = nil, iconUrl: String? = nil) -> tableMetadata {
|
|
|
+ func createMetadata(account: String, user: String, userId: String, fileName: String, fileNameView: String, ocId: String, serverUrl: String, urlBase: String, url: String, contentType: String, isUrl: Bool = false, name: String = NCGlobal.shared.appName, subline: String? = nil, iconName: String? = nil, iconUrl: String? = nil) -> tableMetadata {
|
|
|
|
|
|
let metadata = tableMetadata()
|
|
|
if isUrl {
|
|
@@ -451,7 +433,6 @@ extension NCManageDatabase {
|
|
|
metadata.etag = ocId
|
|
|
metadata.fileName = fileName
|
|
|
metadata.fileNameView = fileName
|
|
|
- metadata.livePhoto = isLivePhoto
|
|
|
metadata.name = name
|
|
|
metadata.ocId = ocId
|
|
|
metadata.permissions = "RGDNVW"
|
|
@@ -546,7 +527,7 @@ extension NCManageDatabase {
|
|
|
}
|
|
|
|
|
|
@discardableResult
|
|
|
- func updateMetadatas(_ metadatas: [tableMetadata], metadatasResult: [tableMetadata], addCompareLivePhoto: Bool = true, addExistsInLocal: Bool = false, addCompareEtagLocal: Bool = false) -> (metadatasUpdate: [tableMetadata], metadatasLocalUpdate: [tableMetadata], metadatasDelete: [tableMetadata]) {
|
|
|
+ func updateMetadatas(_ metadatas: [tableMetadata], metadatasResult: [tableMetadata], addExistsInLocal: Bool = false, addCompareEtagLocal: Bool = false) -> (metadatasUpdate: [tableMetadata], metadatasLocalUpdate: [tableMetadata], metadatasDelete: [tableMetadata]) {
|
|
|
|
|
|
var ocIdsUdate: [String] = []
|
|
|
var ocIdsLocalUdate: [String] = []
|
|
@@ -590,7 +571,7 @@ extension NCManageDatabase {
|
|
|
result.tags != metadata.tags) {
|
|
|
ocIdsUdate.append(metadata.ocId)
|
|
|
realm.add(tableMetadata.init(value: metadata), update: .all)
|
|
|
- } else if result.status == NCGlobal.shared.metadataStatusNormal && addCompareLivePhoto && result.livePhoto != metadata.livePhoto {
|
|
|
+ } else if result.status == NCGlobal.shared.metadataStatusNormal {
|
|
|
ocIdsUdate.append(metadata.ocId)
|
|
|
realm.add(tableMetadata.init(value: metadata), update: .all)
|
|
|
}
|
|
@@ -734,6 +715,19 @@ extension NCManageDatabase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ func setMetadataLivePhotoServer(account: String, ocId: String) {
|
|
|
+
|
|
|
+ do {
|
|
|
+ let realm = try Realm()
|
|
|
+ try realm.write {
|
|
|
+ let result = realm.objects(tableMetadata.self).filter("account == %@ AND ocId == %@", account, ocId).first
|
|
|
+ result?.livePhotoServer = true
|
|
|
+ }
|
|
|
+ } catch let error {
|
|
|
+ NextcloudKit.shared.nkCommonInstance.writeLog("Could not write to database: \(error)")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
func updateMetadatasFavorite(account: String, metadatas: [tableMetadata]) {
|
|
|
|
|
|
do {
|
|
@@ -820,6 +814,18 @@ extension NCManageDatabase {
|
|
|
return []
|
|
|
}
|
|
|
|
|
|
+ func getResultsMetadatas(predicate: NSPredicate) -> Results<tableMetadata>? {
|
|
|
+
|
|
|
+ do {
|
|
|
+ let realm = try Realm()
|
|
|
+ return realm.objects(tableMetadata.self).filter(predicate)
|
|
|
+ } catch let error as NSError {
|
|
|
+ NextcloudKit.shared.nkCommonInstance.writeLog("Could not access database: \(error)")
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
func getAdvancedMetadatas(predicate: NSPredicate, page: Int = 0, limit: Int = 0, sorted: String, ascending: Bool) -> [tableMetadata] {
|
|
|
|
|
|
var metadatas: [tableMetadata] = []
|
|
@@ -992,7 +998,6 @@ extension NCManageDatabase {
|
|
|
|
|
|
do {
|
|
|
let realm = try Realm()
|
|
|
- realm.refresh()
|
|
|
let results = realm.objects(tableMetadata.self).filter("account == %@ AND assetLocalIdentifier != '' AND deleteAssetLocalIdentifier == true", account)
|
|
|
for result in results {
|
|
|
assetLocalIdentifiers.append(result.assetLocalIdentifier)
|
|
@@ -1008,7 +1013,6 @@ extension NCManageDatabase {
|
|
|
|
|
|
do {
|
|
|
let realm = try Realm()
|
|
|
- realm.refresh()
|
|
|
try realm.write {
|
|
|
let results = realm.objects(tableMetadata.self).filter("account == %@ AND assetLocalIdentifier IN %@", account, assetLocalIdentifiers)
|
|
|
for result in results {
|
|
@@ -1021,95 +1025,33 @@ extension NCManageDatabase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- func isMetadataLivePhoto(metadata: tableMetadata) -> tableMetadata? {
|
|
|
-
|
|
|
- guard metadata.livePhoto, NCKeychain().livePhoto, metadata.livePhotoFile.isEmpty else { return nil }
|
|
|
-
|
|
|
- return getMetadataLivePhoto(metadata: metadata)
|
|
|
- }
|
|
|
-
|
|
|
func getMetadataLivePhoto(metadata: tableMetadata) -> tableMetadata? {
|
|
|
|
|
|
- guard metadata.livePhoto, NCKeychain().livePhoto else { return nil }
|
|
|
- var classFile = metadata.classFile
|
|
|
- var fileName = (metadata.fileNameView as NSString).deletingPathExtension
|
|
|
-
|
|
|
- if !metadata.livePhotoFile.isEmpty {
|
|
|
-
|
|
|
- do {
|
|
|
- let realm = try Realm()
|
|
|
- realm.refresh()
|
|
|
- guard let result = realm.objects(tableMetadata.self).filter(NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileNameView == %@", metadata.account, metadata.serverUrl, metadata.livePhotoFile)).first else { return nil }
|
|
|
- return tableMetadata.init(value: result)
|
|
|
- } catch let error as NSError {
|
|
|
- NextcloudKit.shared.nkCommonInstance.writeLog("Could not access database: \(error)")
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
+ guard metadata.isLivePhoto else { return nil }
|
|
|
|
|
|
- if classFile == NKCommon.TypeClassFile.image.rawValue {
|
|
|
- classFile = NKCommon.TypeClassFile.video.rawValue
|
|
|
- fileName = fileName + ".mov"
|
|
|
- } else {
|
|
|
- classFile = NKCommon.TypeClassFile.image.rawValue
|
|
|
- fileName = fileName + ".jpg"
|
|
|
- }
|
|
|
-
|
|
|
- do {
|
|
|
- let realm = try Realm()
|
|
|
- realm.refresh()
|
|
|
- guard let result = realm.objects(tableMetadata.self).filter(NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileNameView CONTAINS[cd] %@ AND ocId != %@ AND classFile == %@", metadata.account, metadata.serverUrl, fileName, metadata.ocId, classFile)).first else { return nil }
|
|
|
- return tableMetadata.init(value: result)
|
|
|
- } catch let error as NSError {
|
|
|
- NextcloudKit.shared.nkCommonInstance.writeLog("Could not access database: \(error)")
|
|
|
- }
|
|
|
+ do {
|
|
|
+ let realm = try Realm()
|
|
|
+ guard let result = realm.objects(tableMetadata.self).filter(NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileName == %@", metadata.account, metadata.serverUrl, metadata.livePhotoFile)).first else { return nil }
|
|
|
+ return tableMetadata.init(value: result)
|
|
|
+ } catch let error as NSError {
|
|
|
+ NextcloudKit.shared.nkCommonInstance.writeLog("Could not access database: \(error)")
|
|
|
}
|
|
|
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
- func getMetadatasMedia(predicate: NSPredicate, livePhoto: Bool) -> [tableMetadata] {
|
|
|
-
|
|
|
- var metadatas: [tableMetadata] = []
|
|
|
+ func getMetadatasMedia(predicate: NSPredicate) -> [tableMetadata] {
|
|
|
|
|
|
do {
|
|
|
let realm = try Realm()
|
|
|
- realm.refresh()
|
|
|
- try realm.write {
|
|
|
- let sortProperties = [SortDescriptor(keyPath: "serverUrl", ascending: false), SortDescriptor(keyPath: "fileNameView", ascending: false)]
|
|
|
- let results = realm.objects(tableMetadata.self).filter(predicate).sorted(by: sortProperties)
|
|
|
- if livePhoto {
|
|
|
- for index in results.indices {
|
|
|
- let metadata = results[index]
|
|
|
- if index < results.count - 1, metadata.fileNoExtension == results[index + 1].fileNoExtension {
|
|
|
- if !metadata.livePhoto {
|
|
|
- metadata.livePhoto = true
|
|
|
- }
|
|
|
- if !results[index + 1].livePhoto {
|
|
|
- results[index + 1].livePhoto = true
|
|
|
- }
|
|
|
- let metadata1 = tableMetadata(value: results[index + 1])
|
|
|
- let metadata2 = tableMetadata(value: results[index])
|
|
|
- NCLivePhoto().setLivePhoto(metadata1: metadata1, metadata2: metadata2)
|
|
|
- }
|
|
|
- if metadata.livePhoto {
|
|
|
- if metadata.classFile == NKCommon.TypeClassFile.image.rawValue {
|
|
|
- metadatas.append(tableMetadata.init(value: metadata))
|
|
|
- }
|
|
|
- continue
|
|
|
- } else {
|
|
|
- metadatas.append(tableMetadata.init(value: metadata))
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- metadatas = Array(results.map { tableMetadata.init(value: $0) })
|
|
|
- }
|
|
|
- }
|
|
|
+ let sortProperties = [SortDescriptor(keyPath: "serverUrl", ascending: false), SortDescriptor(keyPath: "fileName", ascending: false)]
|
|
|
+ let results = realm.objects(tableMetadata.self).filter(predicate).sorted(by: sortProperties)
|
|
|
+ return Array(results.map { tableMetadata.init(value: $0) })
|
|
|
} catch let error {
|
|
|
NextcloudKit.shared.nkCommonInstance.writeLog("Could not write to database: \(error)")
|
|
|
}
|
|
|
|
|
|
- return metadatas
|
|
|
+ return []
|
|
|
}
|
|
|
|
|
|
func isMetadataShareOrMounted(metadata: tableMetadata, metadataFolder: tableMetadata?) -> Bool {
|