Skip to content

Commit 9e4e7af

Browse files
Version 5.5.2 (#3005)
1 parent ca03c1d commit 9e4e7af

18 files changed

+294
-192
lines changed

File Provider Extension/FileProviderData.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ class fileProviderData: NSObject {
5858
case workingSet
5959
}
6060

61+
struct UploadMetadata {
62+
var id: String
63+
var metadata: tableMetadata
64+
var task: URLSessionUploadTask?
65+
}
66+
67+
var uploadMetadata: [UploadMetadata] = []
68+
6169
// MARK: -
6270

6371
func setupAccount(domain: NSFileProviderDomain?, providerExtension: NSFileProviderExtension) -> tableAccount? {
@@ -140,4 +148,17 @@ class fileProviderData: NSObject {
140148
fileProviderManager.signalEnumerator(for: .workingSet) { _ in }
141149
return item
142150
}
151+
152+
// MARK: -
153+
154+
func appendUploadMetadata(id: String, metadata: tableMetadata, task: URLSessionUploadTask?) {
155+
if let index = uploadMetadata.firstIndex(where: { $0.id == id }) {
156+
uploadMetadata.remove(at: index)
157+
}
158+
uploadMetadata.append(UploadMetadata(id: id, metadata: metadata, task: task))
159+
}
160+
161+
func getUploadMetadata(id: String) -> UploadMetadata? {
162+
return uploadMetadata.filter({ $0.id == id }).first
163+
}
143164
}

File Provider Extension/FileProviderExtension+NetworkingDelegate.swift

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,37 +36,45 @@ extension FileProviderExtension: NCNetworkingDelegate {
3636
func uploadComplete(fileName: String, serverUrl: String, ocId: String?, etag: String?, date: Date?, size: Int64, task: URLSessionTask, error: NKError) {
3737
guard let url = task.currentRequest?.url,
3838
let metadata = NCManageDatabase.shared.getMetadata(from: url, sessionTaskIdentifier: task.taskIdentifier) else { return }
39-
if error == .success, let ocId {
40-
/// SIGNAL
41-
fileProviderData.shared.signalEnumerator(ocId: metadata.ocIdTemp, type: .delete)
42-
metadata.fileName = fileName
43-
metadata.serverUrl = serverUrl
44-
metadata.uploadDate = (date as? NSDate) ?? NSDate()
45-
metadata.etag = etag ?? ""
46-
metadata.ocId = ocId
47-
metadata.size = size
48-
if let fileId = NCUtility().ocIdToFileId(ocId: ocId) {
49-
metadata.fileId = fileId
50-
}
51-
metadata.session = ""
52-
metadata.sessionError = ""
53-
metadata.status = NCGlobal.shared.metadataStatusNormal
5439

55-
NCManageDatabase.shared.addMetadata(metadata)
56-
NCManageDatabase.shared.addLocalFile(metadata: metadata)
57-
/// NEW File
58-
if ocId != metadata.ocIdTemp {
59-
let atPath = utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocIdTemp)
60-
let toPath = utilityFileSystem.getDirectoryProviderStorageOcId(ocId)
61-
utilityFileSystem.copyFile(atPath: atPath, toPath: toPath)
40+
DispatchQueue.global(qos: .userInteractive).async {
41+
if error == .success, let ocId {
42+
/// SIGNAL
43+
fileProviderData.shared.signalEnumerator(ocId: metadata.ocIdTemp, type: .delete)
44+
metadata.fileName = fileName
45+
metadata.serverUrl = serverUrl
46+
metadata.uploadDate = (date as? NSDate) ?? NSDate()
47+
metadata.etag = etag ?? ""
48+
metadata.ocId = ocId
49+
metadata.size = size
50+
if let fileId = NCUtility().ocIdToFileId(ocId: ocId) {
51+
metadata.fileId = fileId
52+
}
53+
54+
metadata.sceneIdentifier = nil
55+
metadata.session = ""
56+
metadata.sessionError = ""
57+
metadata.sessionSelector = ""
58+
metadata.sessionDate = nil
59+
metadata.sessionTaskIdentifier = 0
60+
metadata.status = NCGlobal.shared.metadataStatusNormal
61+
62+
NCManageDatabase.shared.addMetadata(metadata)
63+
NCManageDatabase.shared.addLocalFile(metadata: metadata)
64+
/// NEW File
65+
if !metadata.ocIdTemp.isEmpty, ocId != metadata.ocIdTemp {
66+
let atPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocIdTemp)
67+
let toPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(ocId)
68+
self.utilityFileSystem.copyFile(atPath: atPath, toPath: toPath)
69+
NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocIdTemp))
70+
}
71+
/// SIGNAL
72+
fileProviderData.shared.signalEnumerator(ocId: metadata.ocId, type: .update)
73+
} else {
6274
NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocIdTemp))
75+
/// SIGNAL
76+
fileProviderData.shared.signalEnumerator(ocId: metadata.ocIdTemp, type: .delete)
6377
}
64-
/// SIGNAL
65-
fileProviderData.shared.signalEnumerator(ocId: metadata.ocId, type: .update)
66-
} else {
67-
NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocIdTemp))
68-
/// SIGNAL
69-
fileProviderData.shared.signalEnumerator(ocId: metadata.ocIdTemp, type: .delete)
7078
}
7179
}
7280
}

File Provider Extension/FileProviderExtension.swift

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,13 @@ class FileProviderExtension: NSFileProviderExtension {
166166
override func startProvidingItem(at url: URL, completionHandler: @escaping ((_ error: Error?) -> Void)) {
167167
let pathComponents = url.pathComponents
168168
let itemIdentifier = NSFileProviderItemIdentifier(pathComponents[pathComponents.count - 2])
169-
guard let metadata = providerUtility.getTableMetadataFromItemIdentifier(itemIdentifier) else {
169+
var metadata: tableMetadata?
170+
if let result = fileProviderData.shared.getUploadMetadata(id: itemIdentifier.rawValue) {
171+
metadata = result.metadata
172+
} else {
173+
metadata = NCManageDatabase.shared.getMetadataFromOcIdAndOcIdTemp(itemIdentifier.rawValue)
174+
}
175+
guard let metadata else {
170176
return completionHandler(NSFileProviderError(.noSuchItem))
171177
}
172178
if metadata.session == NCNetworking.shared.sessionUploadBackgroundExtension {
@@ -200,6 +206,12 @@ class FileProviderExtension: NSFileProviderExtension {
200206
return completionHandler(NSFileProviderError(.noSuchItem))
201207
}
202208
if error == .success {
209+
metadata.sceneIdentifier = nil
210+
metadata.session = ""
211+
metadata.sessionError = ""
212+
metadata.sessionSelector = ""
213+
metadata.sessionDate = nil
214+
metadata.sessionTaskIdentifier = 0
203215
metadata.status = NCGlobal.shared.metadataStatusNormal
204216
metadata.date = (date as? NSDate) ?? NSDate()
205217
metadata.etag = etag ?? ""
@@ -226,16 +238,23 @@ class FileProviderExtension: NSFileProviderExtension {
226238
assert(pathComponents.count > 2)
227239
let itemIdentifier = NSFileProviderItemIdentifier(pathComponents[pathComponents.count - 2])
228240
let fileName = pathComponents[pathComponents.count - 1]
229-
guard let metadata = NCManageDatabase.shared.getMetadataFromOcIdAndOcIdTemp(itemIdentifier.rawValue) else { return }
241+
var metadata: tableMetadata?
242+
if let result = fileProviderData.shared.getUploadMetadata(id: itemIdentifier.rawValue) {
243+
metadata = result.metadata
244+
} else {
245+
metadata = NCManageDatabase.shared.getMetadataFromOcIdAndOcIdTemp(itemIdentifier.rawValue)
246+
}
247+
guard let metadata else {
248+
return
249+
}
230250
let serverUrlFileName = metadata.serverUrl + "/" + fileName
231-
let fileNameLocalPath = utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: fileName)
232-
utilityFileSystem.copyFile(atPath: url.path, toPath: fileNameLocalPath)
251+
233252
NCManageDatabase.shared.setMetadataSession(ocId: metadata.ocId,
234253
session: NCNetworking.shared.sessionUploadBackgroundExtension,
235254
sessionError: "",
236255
selector: "",
237256
status: NCGlobal.shared.metadataStatusUploading)
238-
if let task = NKBackground(nkCommonInstance: NextcloudKit.shared.nkCommonInstance).upload(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, dateCreationFile: nil, dateModificationFile: nil, session: NCNetworking.shared.sessionManagerUploadBackgroundExtension) {
257+
if let task = NKBackground(nkCommonInstance: NextcloudKit.shared.nkCommonInstance).upload(serverUrlFileName: serverUrlFileName, fileNameLocalPath: url.path, dateCreationFile: nil, dateModificationFile: nil, session: NCNetworking.shared.sessionManagerUploadBackgroundExtension) {
239258
NCManageDatabase.shared.setMetadataSession(ocId: metadata.ocId,
240259
status: NCGlobal.shared.metadataStatusUploading,
241260
taskIdentifier: task.taskIdentifier)
@@ -304,6 +323,7 @@ class FileProviderExtension: NSFileProviderExtension {
304323
status: NCGlobal.shared.metadataStatusUploading,
305324
taskIdentifier: task.taskIdentifier)
306325
fileProviderData.shared.fileProviderManager.register(task, forItemWithIdentifier: NSFileProviderItemIdentifier(ocIdTemp)) { _ in }
326+
fileProviderData.shared.appendUploadMetadata(id: ocIdTemp, metadata: metadata, task: task)
307327
}
308328

309329
let item = FileProviderItem(metadata: tableMetadata.init(value: metadata), parentItemIdentifier: parentItemIdentifier)

File Provider Extension/FileProviderUtility.swift

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ class fileProviderUtility: NSObject {
7575
do {
7676
try fileManager.removeItem(atPath: toPath)
7777
} catch let error {
78-
print("error: \(error)")
78+
print("Error: \(error.localizedDescription)")
7979
}
8080
do {
8181
try fileManager.copyItem(atPath: atPath, toPath: toPath)
8282
} catch let error {
83-
print("error: \(error)")
83+
print("Error: \(error.localizedDescription)")
8484
}
8585
}
8686

@@ -90,12 +90,28 @@ class fileProviderUtility: NSObject {
9090
do {
9191
try fileManager.removeItem(atPath: toPath)
9292
} catch let error {
93-
print("error: \(error)")
93+
print("Error: \(error.localizedDescription)")
9494
}
9595
do {
9696
try fileManager.moveItem(atPath: atPath, toPath: toPath)
9797
} catch let error {
98-
print("error: \(error)")
98+
print("Error: \(error.localizedDescription)")
99+
}
100+
}
101+
102+
func getFileSize(from url: URL) -> Int64? {
103+
do {
104+
let attributes = try fileManager.attributesOfItem(atPath: url.path)
105+
106+
if let fileSize = attributes[FileAttributeKey.size] as? Int64 {
107+
return fileSize
108+
} else {
109+
print("Failed to retrieve file size.")
110+
return nil
111+
}
112+
} catch {
113+
print("Error: \(error.localizedDescription)")
114+
return nil
99115
}
100116
}
101117
}

Nextcloud.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5414,7 +5414,7 @@
54145414
CLANG_WARN_UNREACHABLE_CODE = YES;
54155415
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
54165416
COPY_PHASE_STRIP = NO;
5417-
CURRENT_PROJECT_VERSION = 11;
5417+
CURRENT_PROJECT_VERSION = 2;
54185418
DEBUG_INFORMATION_FORMAT = dwarf;
54195419
DEVELOPMENT_TEAM = NKUJUXUJ3B;
54205420
ENABLE_STRICT_OBJC_MSGSEND = YES;
@@ -5441,7 +5441,7 @@
54415441
"@executable_path/Frameworks",
54425442
"@executable_path/../../Frameworks",
54435443
);
5444-
MARKETING_VERSION = 5.5.0;
5444+
MARKETING_VERSION = 5.5.2;
54455445
ONLY_ACTIVE_ARCH = YES;
54465446
OTHER_CFLAGS = "-v";
54475447
OTHER_LDFLAGS = "";
@@ -5480,7 +5480,7 @@
54805480
CLANG_WARN_UNREACHABLE_CODE = YES;
54815481
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
54825482
COPY_PHASE_STRIP = NO;
5483-
CURRENT_PROJECT_VERSION = 11;
5483+
CURRENT_PROJECT_VERSION = 2;
54845484
DEVELOPMENT_TEAM = NKUJUXUJ3B;
54855485
ENABLE_STRICT_OBJC_MSGSEND = YES;
54865486
ENABLE_TESTABILITY = YES;
@@ -5504,7 +5504,7 @@
55045504
"@executable_path/Frameworks",
55055505
"@executable_path/../../Frameworks",
55065506
);
5507-
MARKETING_VERSION = 5.5.0;
5507+
MARKETING_VERSION = 5.5.2;
55085508
ONLY_ACTIVE_ARCH = YES;
55095509
OTHER_CFLAGS = "-v";
55105510
OTHER_LDFLAGS = "";

Nextcloud.xcodeproj/xcshareddata/xcschemes/File Provider Extension.xcscheme

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
buildForAnalyzing = "YES">
1616
<BuildableReference
1717
BuildableIdentifier = "primary"
18-
BlueprintIdentifier = "F771E3CF20E2392D00AFB62D"
19-
BuildableName = "File Provider Extension.appex"
20-
BlueprintName = "File Provider Extension"
18+
BlueprintIdentifier = "F77B0DEB1D118A16002130FE"
19+
BuildableName = "Nextcloud.app"
20+
BlueprintName = "Nextcloud"
2121
ReferencedContainer = "container:Nextcloud.xcodeproj">
2222
</BuildableReference>
2323
</BuildActionEntry>
@@ -29,9 +29,9 @@
2929
buildForAnalyzing = "YES">
3030
<BuildableReference
3131
BuildableIdentifier = "primary"
32-
BlueprintIdentifier = "F77B0DEB1D118A16002130FE"
33-
BuildableName = "Nextcloud.app"
34-
BlueprintName = "Nextcloud"
32+
BlueprintIdentifier = "F771E3CF20E2392D00AFB62D"
33+
BuildableName = "File Provider Extension.appex"
34+
BlueprintName = "File Provider Extension"
3535
ReferencedContainer = "container:Nextcloud.xcodeproj">
3636
</BuildableReference>
3737
</BuildActionEntry>

iOSClient/Account Settings/NCAccountSettingsModel.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ class NCAccountSettingsModel: ObservableObject, ViewOnAppearHandling {
140140
return (nil, "", "")
141141
}
142142

143+
/// Is the user an Admin
144+
func isAdminGroup() -> Bool {
145+
guard let activeAccount else { return false }
146+
let groups = NCManageDatabase.shared.getAccountGroups(account: activeAccount.account)
147+
return groups.contains(NCGlobal.shared.groupAdmin)
148+
}
149+
143150
/// Function to know the height of "account" data
144151
func getTableViewHeight() -> CGFloat {
145152
guard let activeAccount else { return 0 }

iOSClient/Account Settings/NCAccountSettingsView.swift

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -181,52 +181,54 @@ struct NCAccountSettingsView: View {
181181
}
182182
///
183183
/// Certificate server
184-
Button(action: {
185-
showServerCertificate.toggle()
186-
}, label: {
187-
HStack {
188-
Image(systemName: "lock")
189-
.resizable()
190-
.scaledToFit()
191-
.font(Font.system(.body).weight(.light))
192-
.frame(width: 20, height: 20)
193-
.foregroundStyle(Color(NCBrandColor.shared.iconImageColor))
194-
Text(NSLocalizedString("_certificate_details_", comment: ""))
195-
.lineLimit(1)
196-
.truncationMode(.middle)
197-
.foregroundStyle(Color(NCBrandColor.shared.textColor))
198-
.padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 20))
199-
}
200-
.font(.system(size: 14))
201-
})
202-
.sheet(isPresented: $showServerCertificate) {
203-
if let url = URL(string: model.activeAccount?.urlBase), let host = url.host {
204-
certificateDetailsView(host: host, title: NSLocalizedString("_certificate_view_", comment: ""))
205-
}
206-
}
207-
///
208-
/// Certificate push
209-
Button(action: {
210-
showPushCertificate.toggle()
211-
}, label: {
212-
HStack {
213-
Image(systemName: "lock")
214-
.resizable()
215-
.scaledToFit()
216-
.font(Font.system(.body).weight(.light))
217-
.frame(width: 20, height: 20)
218-
.foregroundStyle(Color(NCBrandColor.shared.iconImageColor))
219-
Text(NSLocalizedString("_certificate_pn_details_", comment: ""))
220-
.lineLimit(1)
221-
.truncationMode(.middle)
222-
.foregroundStyle(Color(NCBrandColor.shared.textColor))
223-
.padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 20))
184+
if model.isAdminGroup() {
185+
Button(action: {
186+
showServerCertificate.toggle()
187+
}, label: {
188+
HStack {
189+
Image(systemName: "lock")
190+
.resizable()
191+
.scaledToFit()
192+
.font(Font.system(.body).weight(.light))
193+
.frame(width: 20, height: 20)
194+
.foregroundStyle(Color(NCBrandColor.shared.iconImageColor))
195+
Text(NSLocalizedString("_certificate_details_", comment: ""))
196+
.lineLimit(1)
197+
.truncationMode(.middle)
198+
.foregroundStyle(Color(NCBrandColor.shared.textColor))
199+
.padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 20))
200+
}
201+
.font(.system(size: 14))
202+
})
203+
.sheet(isPresented: $showServerCertificate) {
204+
if let url = URL(string: model.activeAccount?.urlBase), let host = url.host {
205+
certificateDetailsView(host: host, title: NSLocalizedString("_certificate_view_", comment: ""))
206+
}
224207
}
225-
.font(.system(size: 14))
226-
})
227-
.sheet(isPresented: $showPushCertificate) {
228-
if let url = URL(string: NCBrandOptions.shared.pushNotificationServerProxy), let host = url.host {
229-
certificateDetailsView(host: host, title: NSLocalizedString("_certificate_pn_view_", comment: ""))
208+
///
209+
/// Certificate push
210+
Button(action: {
211+
showPushCertificate.toggle()
212+
}, label: {
213+
HStack {
214+
Image(systemName: "lock")
215+
.resizable()
216+
.scaledToFit()
217+
.font(Font.system(.body).weight(.light))
218+
.frame(width: 20, height: 20)
219+
.foregroundStyle(Color(NCBrandColor.shared.iconImageColor))
220+
Text(NSLocalizedString("_certificate_pn_details_", comment: ""))
221+
.lineLimit(1)
222+
.truncationMode(.middle)
223+
.foregroundStyle(Color(NCBrandColor.shared.textColor))
224+
.padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 20))
225+
}
226+
.font(.system(size: 14))
227+
})
228+
.sheet(isPresented: $showPushCertificate) {
229+
if let url = URL(string: NCBrandOptions.shared.pushNotificationServerProxy), let host = url.host {
230+
certificateDetailsView(host: host, title: NSLocalizedString("_certificate_pn_view_", comment: ""))
231+
}
230232
}
231233
}
232234
})

0 commit comments

Comments
 (0)