Skip to content

Commit

Permalink
Version 5.5.2 (#3005)
Browse files Browse the repository at this point in the history
  • Loading branch information
marinofaggiana authored Jul 30, 2024
1 parent ca03c1d commit 9e4e7af
Show file tree
Hide file tree
Showing 18 changed files with 294 additions and 192 deletions.
21 changes: 21 additions & 0 deletions File Provider Extension/FileProviderData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ class fileProviderData: NSObject {
case workingSet
}

struct UploadMetadata {
var id: String
var metadata: tableMetadata
var task: URLSessionUploadTask?
}

var uploadMetadata: [UploadMetadata] = []

// MARK: -

func setupAccount(domain: NSFileProviderDomain?, providerExtension: NSFileProviderExtension) -> tableAccount? {
Expand Down Expand Up @@ -140,4 +148,17 @@ class fileProviderData: NSObject {
fileProviderManager.signalEnumerator(for: .workingSet) { _ in }
return item
}

// MARK: -

func appendUploadMetadata(id: String, metadata: tableMetadata, task: URLSessionUploadTask?) {
if let index = uploadMetadata.firstIndex(where: { $0.id == id }) {
uploadMetadata.remove(at: index)
}
uploadMetadata.append(UploadMetadata(id: id, metadata: metadata, task: task))
}

func getUploadMetadata(id: String) -> UploadMetadata? {
return uploadMetadata.filter({ $0.id == id }).first
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,37 +36,45 @@ extension FileProviderExtension: NCNetworkingDelegate {
func uploadComplete(fileName: String, serverUrl: String, ocId: String?, etag: String?, date: Date?, size: Int64, task: URLSessionTask, error: NKError) {
guard let url = task.currentRequest?.url,
let metadata = NCManageDatabase.shared.getMetadata(from: url, sessionTaskIdentifier: task.taskIdentifier) else { return }
if error == .success, let ocId {
/// SIGNAL
fileProviderData.shared.signalEnumerator(ocId: metadata.ocIdTemp, type: .delete)
metadata.fileName = fileName
metadata.serverUrl = serverUrl
metadata.uploadDate = (date as? NSDate) ?? NSDate()
metadata.etag = etag ?? ""
metadata.ocId = ocId
metadata.size = size
if let fileId = NCUtility().ocIdToFileId(ocId: ocId) {
metadata.fileId = fileId
}
metadata.session = ""
metadata.sessionError = ""
metadata.status = NCGlobal.shared.metadataStatusNormal

NCManageDatabase.shared.addMetadata(metadata)
NCManageDatabase.shared.addLocalFile(metadata: metadata)
/// NEW File
if ocId != metadata.ocIdTemp {
let atPath = utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocIdTemp)
let toPath = utilityFileSystem.getDirectoryProviderStorageOcId(ocId)
utilityFileSystem.copyFile(atPath: atPath, toPath: toPath)
DispatchQueue.global(qos: .userInteractive).async {
if error == .success, let ocId {
/// SIGNAL
fileProviderData.shared.signalEnumerator(ocId: metadata.ocIdTemp, type: .delete)
metadata.fileName = fileName
metadata.serverUrl = serverUrl
metadata.uploadDate = (date as? NSDate) ?? NSDate()
metadata.etag = etag ?? ""
metadata.ocId = ocId
metadata.size = size
if let fileId = NCUtility().ocIdToFileId(ocId: ocId) {
metadata.fileId = fileId
}

metadata.sceneIdentifier = nil
metadata.session = ""
metadata.sessionError = ""
metadata.sessionSelector = ""
metadata.sessionDate = nil
metadata.sessionTaskIdentifier = 0
metadata.status = NCGlobal.shared.metadataStatusNormal

NCManageDatabase.shared.addMetadata(metadata)
NCManageDatabase.shared.addLocalFile(metadata: metadata)
/// NEW File
if !metadata.ocIdTemp.isEmpty, ocId != metadata.ocIdTemp {
let atPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocIdTemp)
let toPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(ocId)
self.utilityFileSystem.copyFile(atPath: atPath, toPath: toPath)
NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocIdTemp))
}
/// SIGNAL
fileProviderData.shared.signalEnumerator(ocId: metadata.ocId, type: .update)
} else {
NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocIdTemp))
/// SIGNAL
fileProviderData.shared.signalEnumerator(ocId: metadata.ocIdTemp, type: .delete)
}
/// SIGNAL
fileProviderData.shared.signalEnumerator(ocId: metadata.ocId, type: .update)
} else {
NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocIdTemp))
/// SIGNAL
fileProviderData.shared.signalEnumerator(ocId: metadata.ocIdTemp, type: .delete)
}
}
}
30 changes: 25 additions & 5 deletions File Provider Extension/FileProviderExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,13 @@ class FileProviderExtension: NSFileProviderExtension {
override func startProvidingItem(at url: URL, completionHandler: @escaping ((_ error: Error?) -> Void)) {
let pathComponents = url.pathComponents
let itemIdentifier = NSFileProviderItemIdentifier(pathComponents[pathComponents.count - 2])
guard let metadata = providerUtility.getTableMetadataFromItemIdentifier(itemIdentifier) else {
var metadata: tableMetadata?
if let result = fileProviderData.shared.getUploadMetadata(id: itemIdentifier.rawValue) {
metadata = result.metadata
} else {
metadata = NCManageDatabase.shared.getMetadataFromOcIdAndOcIdTemp(itemIdentifier.rawValue)
}
guard let metadata else {
return completionHandler(NSFileProviderError(.noSuchItem))
}
if metadata.session == NCNetworking.shared.sessionUploadBackgroundExtension {
Expand Down Expand Up @@ -200,6 +206,12 @@ class FileProviderExtension: NSFileProviderExtension {
return completionHandler(NSFileProviderError(.noSuchItem))
}
if error == .success {
metadata.sceneIdentifier = nil
metadata.session = ""
metadata.sessionError = ""
metadata.sessionSelector = ""
metadata.sessionDate = nil
metadata.sessionTaskIdentifier = 0
metadata.status = NCGlobal.shared.metadataStatusNormal
metadata.date = (date as? NSDate) ?? NSDate()
metadata.etag = etag ?? ""
Expand All @@ -226,16 +238,23 @@ class FileProviderExtension: NSFileProviderExtension {
assert(pathComponents.count > 2)
let itemIdentifier = NSFileProviderItemIdentifier(pathComponents[pathComponents.count - 2])
let fileName = pathComponents[pathComponents.count - 1]
guard let metadata = NCManageDatabase.shared.getMetadataFromOcIdAndOcIdTemp(itemIdentifier.rawValue) else { return }
var metadata: tableMetadata?
if let result = fileProviderData.shared.getUploadMetadata(id: itemIdentifier.rawValue) {
metadata = result.metadata
} else {
metadata = NCManageDatabase.shared.getMetadataFromOcIdAndOcIdTemp(itemIdentifier.rawValue)
}
guard let metadata else {
return
}
let serverUrlFileName = metadata.serverUrl + "/" + fileName
let fileNameLocalPath = utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: fileName)
utilityFileSystem.copyFile(atPath: url.path, toPath: fileNameLocalPath)

NCManageDatabase.shared.setMetadataSession(ocId: metadata.ocId,
session: NCNetworking.shared.sessionUploadBackgroundExtension,
sessionError: "",
selector: "",
status: NCGlobal.shared.metadataStatusUploading)
if let task = NKBackground(nkCommonInstance: NextcloudKit.shared.nkCommonInstance).upload(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, dateCreationFile: nil, dateModificationFile: nil, session: NCNetworking.shared.sessionManagerUploadBackgroundExtension) {
if let task = NKBackground(nkCommonInstance: NextcloudKit.shared.nkCommonInstance).upload(serverUrlFileName: serverUrlFileName, fileNameLocalPath: url.path, dateCreationFile: nil, dateModificationFile: nil, session: NCNetworking.shared.sessionManagerUploadBackgroundExtension) {
NCManageDatabase.shared.setMetadataSession(ocId: metadata.ocId,
status: NCGlobal.shared.metadataStatusUploading,
taskIdentifier: task.taskIdentifier)
Expand Down Expand Up @@ -304,6 +323,7 @@ class FileProviderExtension: NSFileProviderExtension {
status: NCGlobal.shared.metadataStatusUploading,
taskIdentifier: task.taskIdentifier)
fileProviderData.shared.fileProviderManager.register(task, forItemWithIdentifier: NSFileProviderItemIdentifier(ocIdTemp)) { _ in }
fileProviderData.shared.appendUploadMetadata(id: ocIdTemp, metadata: metadata, task: task)
}

let item = FileProviderItem(metadata: tableMetadata.init(value: metadata), parentItemIdentifier: parentItemIdentifier)
Expand Down
24 changes: 20 additions & 4 deletions File Provider Extension/FileProviderUtility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ class fileProviderUtility: NSObject {
do {
try fileManager.removeItem(atPath: toPath)
} catch let error {
print("error: \(error)")
print("Error: \(error.localizedDescription)")
}
do {
try fileManager.copyItem(atPath: atPath, toPath: toPath)
} catch let error {
print("error: \(error)")
print("Error: \(error.localizedDescription)")
}
}

Expand All @@ -90,12 +90,28 @@ class fileProviderUtility: NSObject {
do {
try fileManager.removeItem(atPath: toPath)
} catch let error {
print("error: \(error)")
print("Error: \(error.localizedDescription)")
}
do {
try fileManager.moveItem(atPath: atPath, toPath: toPath)
} catch let error {
print("error: \(error)")
print("Error: \(error.localizedDescription)")
}
}

func getFileSize(from url: URL) -> Int64? {
do {
let attributes = try fileManager.attributesOfItem(atPath: url.path)

if let fileSize = attributes[FileAttributeKey.size] as? Int64 {
return fileSize
} else {
print("Failed to retrieve file size.")
return nil
}
} catch {
print("Error: \(error.localizedDescription)")
return nil
}
}
}
8 changes: 4 additions & 4 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5414,7 +5414,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 11;
CURRENT_PROJECT_VERSION = 2;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = NKUJUXUJ3B;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand All @@ -5441,7 +5441,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 5.5.0;
MARKETING_VERSION = 5.5.2;
ONLY_ACTIVE_ARCH = YES;
OTHER_CFLAGS = "-v";
OTHER_LDFLAGS = "";
Expand Down Expand Up @@ -5480,7 +5480,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 11;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = NKUJUXUJ3B;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
Expand All @@ -5504,7 +5504,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 5.5.0;
MARKETING_VERSION = 5.5.2;
ONLY_ACTIVE_ARCH = YES;
OTHER_CFLAGS = "-v";
OTHER_LDFLAGS = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "F771E3CF20E2392D00AFB62D"
BuildableName = "File Provider Extension.appex"
BlueprintName = "File Provider Extension"
BlueprintIdentifier = "F77B0DEB1D118A16002130FE"
BuildableName = "Nextcloud.app"
BlueprintName = "Nextcloud"
ReferencedContainer = "container:Nextcloud.xcodeproj">
</BuildableReference>
</BuildActionEntry>
Expand All @@ -29,9 +29,9 @@
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "F77B0DEB1D118A16002130FE"
BuildableName = "Nextcloud.app"
BlueprintName = "Nextcloud"
BlueprintIdentifier = "F771E3CF20E2392D00AFB62D"
BuildableName = "File Provider Extension.appex"
BlueprintName = "File Provider Extension"
ReferencedContainer = "container:Nextcloud.xcodeproj">
</BuildableReference>
</BuildActionEntry>
Expand Down
7 changes: 7 additions & 0 deletions iOSClient/Account Settings/NCAccountSettingsModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ class NCAccountSettingsModel: ObservableObject, ViewOnAppearHandling {
return (nil, "", "")
}

/// Is the user an Admin
func isAdminGroup() -> Bool {
guard let activeAccount else { return false }
let groups = NCManageDatabase.shared.getAccountGroups(account: activeAccount.account)
return groups.contains(NCGlobal.shared.groupAdmin)
}

/// Function to know the height of "account" data
func getTableViewHeight() -> CGFloat {
guard let activeAccount else { return 0 }
Expand Down
92 changes: 47 additions & 45 deletions iOSClient/Account Settings/NCAccountSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,52 +181,54 @@ struct NCAccountSettingsView: View {
}
///
/// Certificate server
Button(action: {
showServerCertificate.toggle()
}, label: {
HStack {
Image(systemName: "lock")
.resizable()
.scaledToFit()
.font(Font.system(.body).weight(.light))
.frame(width: 20, height: 20)
.foregroundStyle(Color(NCBrandColor.shared.iconImageColor))
Text(NSLocalizedString("_certificate_details_", comment: ""))
.lineLimit(1)
.truncationMode(.middle)
.foregroundStyle(Color(NCBrandColor.shared.textColor))
.padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 20))
}
.font(.system(size: 14))
})
.sheet(isPresented: $showServerCertificate) {
if let url = URL(string: model.activeAccount?.urlBase), let host = url.host {
certificateDetailsView(host: host, title: NSLocalizedString("_certificate_view_", comment: ""))
}
}
///
/// Certificate push
Button(action: {
showPushCertificate.toggle()
}, label: {
HStack {
Image(systemName: "lock")
.resizable()
.scaledToFit()
.font(Font.system(.body).weight(.light))
.frame(width: 20, height: 20)
.foregroundStyle(Color(NCBrandColor.shared.iconImageColor))
Text(NSLocalizedString("_certificate_pn_details_", comment: ""))
.lineLimit(1)
.truncationMode(.middle)
.foregroundStyle(Color(NCBrandColor.shared.textColor))
.padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 20))
if model.isAdminGroup() {
Button(action: {
showServerCertificate.toggle()
}, label: {
HStack {
Image(systemName: "lock")
.resizable()
.scaledToFit()
.font(Font.system(.body).weight(.light))
.frame(width: 20, height: 20)
.foregroundStyle(Color(NCBrandColor.shared.iconImageColor))
Text(NSLocalizedString("_certificate_details_", comment: ""))
.lineLimit(1)
.truncationMode(.middle)
.foregroundStyle(Color(NCBrandColor.shared.textColor))
.padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 20))
}
.font(.system(size: 14))
})
.sheet(isPresented: $showServerCertificate) {
if let url = URL(string: model.activeAccount?.urlBase), let host = url.host {
certificateDetailsView(host: host, title: NSLocalizedString("_certificate_view_", comment: ""))
}
}
.font(.system(size: 14))
})
.sheet(isPresented: $showPushCertificate) {
if let url = URL(string: NCBrandOptions.shared.pushNotificationServerProxy), let host = url.host {
certificateDetailsView(host: host, title: NSLocalizedString("_certificate_pn_view_", comment: ""))
///
/// Certificate push
Button(action: {
showPushCertificate.toggle()
}, label: {
HStack {
Image(systemName: "lock")
.resizable()
.scaledToFit()
.font(Font.system(.body).weight(.light))
.frame(width: 20, height: 20)
.foregroundStyle(Color(NCBrandColor.shared.iconImageColor))
Text(NSLocalizedString("_certificate_pn_details_", comment: ""))
.lineLimit(1)
.truncationMode(.middle)
.foregroundStyle(Color(NCBrandColor.shared.textColor))
.padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 20))
}
.font(.system(size: 14))
})
.sheet(isPresented: $showPushCertificate) {
if let url = URL(string: NCBrandOptions.shared.pushNotificationServerProxy), let host = url.host {
certificateDetailsView(host: host, title: NSLocalizedString("_certificate_pn_view_", comment: ""))
}
}
}
})
Expand Down
Loading

0 comments on commit 9e4e7af

Please sign in to comment.