Skip to content

Commit

Permalink
Version 5.5.5 (#3033)
Browse files Browse the repository at this point in the history
Filename validator Nextcloud 30
  • Loading branch information
marinofaggiana authored Aug 27, 2024
1 parent 7a4bb44 commit 6d1744a
Show file tree
Hide file tree
Showing 134 changed files with 338 additions and 541 deletions.
4 changes: 2 additions & 2 deletions File Provider Extension/FileProviderData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class fileProviderData: NSObject {
homeServerUrl = utilityFileSystem.getHomeServer(urlBase: activeAccount.urlBase, userId: activeAccount.userId)

NCManageDatabase.shared.setCapabilities(account: account)
NextcloudKit.shared.setup(account: activeAccount.account, user: activeAccount.user, userId: activeAccount.userId, password: NCKeychain().getPassword(account: activeAccount.account), urlBase: activeAccount.urlBase, userAgent: userAgent, nextcloudVersion: NCGlobal.shared.capabilityServerVersionMajor, groupIdentifier: NCBrandOptions.shared.capabilitiesGroup, delegate: NCNetworking.shared)
NextcloudKit.shared.setup(account: activeAccount.account, user: activeAccount.user, userId: activeAccount.userId, password: NCKeychain().getPassword(account: activeAccount.account), urlBase: activeAccount.urlBase, userAgent: userAgent, nextcloudVersion: NCGlobal.shared.capabilityServerVersionMajor, delegate: NCNetworking.shared)
NCNetworking.shared.delegate = providerExtension as? NCNetworkingDelegate

return tableAccount.init(value: activeAccount)
Expand All @@ -114,7 +114,7 @@ class fileProviderData: NSObject {

NCManageDatabase.shared.setCapabilities(account: account)

NextcloudKit.shared.setup(account: activeAccount.account, user: activeAccount.user, userId: activeAccount.userId, password: NCKeychain().getPassword(account: activeAccount.account), urlBase: activeAccount.urlBase, userAgent: userAgent, nextcloudVersion: NCGlobal.shared.capabilityServerVersionMajor, groupIdentifier: NCBrandOptions.shared.capabilitiesGroup, delegate: NCNetworking.shared)
NextcloudKit.shared.setup(account: activeAccount.account, user: activeAccount.user, userId: activeAccount.userId, password: NCKeychain().getPassword(account: activeAccount.account), urlBase: activeAccount.urlBase, userAgent: userAgent, nextcloudVersion: NCGlobal.shared.capabilityServerVersionMajor, delegate: NCNetworking.shared)
NCNetworking.shared.delegate = providerExtension as? NCNetworkingDelegate

return tableAccount.init(value: activeAccount)
Expand Down
8 changes: 6 additions & 2 deletions File Provider Extension/FileProviderExtension+Actions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ extension FileProviderExtension {
}
}
} else {
completionHandler(nil, NSFileProviderError(.serverUnreachable))
completionHandler(nil, NSFileProviderError(.filenameCollision))
}
}
}
Expand All @@ -70,7 +70,7 @@ extension FileProviderExtension {
let fileName = metadata.fileName

NextcloudKit.shared.deleteFileOrFolder(serverUrlFileName: serverUrlFileName, account: metadata.account) { account, error in
if error == .success { // || error == kOCErrorServerPathNotFound {
if error == .success {
let fileNamePath = self.utilityFileSystem.getDirectoryProviderStorageOcId(itemIdentifier.rawValue)

do {
Expand Down Expand Up @@ -122,6 +122,8 @@ extension FileProviderExtension {
let item = FileProviderItem(metadata: metadata, parentItemIdentifier: parentItemIdentifier)

completionHandler(item, nil)
} else if error.errorCode == NCGlobal.shared.errorBadRequest {
completionHandler(nil, NSFileProviderError(.noSuchItem, userInfo: [NSLocalizedDescriptionKey: error.errorDescription, NSLocalizedFailureReasonErrorKey: ""]))
} else {
completionHandler(nil, NSFileProviderError(.serverUnreachable))
}
Expand Down Expand Up @@ -161,6 +163,8 @@ extension FileProviderExtension {
}
let item = FileProviderItem(metadata: tableMetadata.init(value: metadata), parentItemIdentifier: parentItemIdentifier)
completionHandler(item, nil)
} else if error.errorCode == NCGlobal.shared.errorBadRequest {

Check warning on line 166 in File Provider Extension/FileProviderExtension+Actions.swift

View workflow job for this annotation

GitHub Actions / Lint

Opening Brace Spacing Violation: Opening braces should be preceded by a single space and on the same line as the declaration (opening_brace)
completionHandler(nil, NSFileProviderError(.noSuchItem, userInfo: [NSLocalizedDescriptionKey: error.errorDescription, NSLocalizedFailureReasonErrorKey: ""]))
} else {
completionHandler(nil, NSFileProviderError(.serverUnreachable))
}
Expand Down
30 changes: 5 additions & 25 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,6 @@
F70CAE3A1F8CF31A008125FD /* NCEndToEndEncryption.m in Sources */ = {isa = PBXBuildFile; fileRef = F70CAE391F8CF31A008125FD /* NCEndToEndEncryption.m */; };
F70CEF5623E9C7E50007035B /* UIColor+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F70CEF5523E9C7E50007035B /* UIColor+Extension.swift */; };
F70D7C3725FFBF82002B9E34 /* NCCollectionViewCommon.swift in Sources */ = {isa = PBXBuildFile; fileRef = F70D7C3525FFBF81002B9E34 /* NCCollectionViewCommon.swift */; };
F70D87CF25EE6E58008CBBBD /* NCRenameFile.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F70D87CD25EE6E58008CBBBD /* NCRenameFile.storyboard */; };
F70D87D025EE6E58008CBBBD /* NCRenameFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = F70D87CE25EE6E58008CBBBD /* NCRenameFile.swift */; };
F70D8D8124A4A9BF000A5756 /* NCNetworkingProcess.swift in Sources */ = {isa = PBXBuildFile; fileRef = F70D8D8024A4A9BF000A5756 /* NCNetworkingProcess.swift */; };
F710D1F52405770F00A6033D /* NCViewerPDF.swift in Sources */ = {isa = PBXBuildFile; fileRef = F710D1F42405770F00A6033D /* NCViewerPDF.swift */; };
F710D2022405826100A6033D /* NCViewer+Menu.swift in Sources */ = {isa = PBXBuildFile; fileRef = F710D2012405826100A6033D /* NCViewer+Menu.swift */; };
Expand Down Expand Up @@ -712,8 +710,6 @@
F79B646226CA661600838ACA /* UIControl+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F79B645F26CA661600838ACA /* UIControl+Extension.swift */; };
F79B646326CA661600838ACA /* UIControl+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F79B645F26CA661600838ACA /* UIControl+Extension.swift */; };
F79B869B265E19D40085C0E0 /* NSMutableAttributedString+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F79B869A265E19D40085C0E0 /* NSMutableAttributedString+Extension.swift */; };
F79EC77F26316193004E59D6 /* NCRenameFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = F70D87CE25EE6E58008CBBBD /* NCRenameFile.swift */; };
F79EC784263161BA004E59D6 /* NCRenameFile.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F70D87CD25EE6E58008CBBBD /* NCRenameFile.storyboard */; };
F79EC78926316AC4004E59D6 /* NCPopupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F702F30725EE5D47008F8E80 /* NCPopupViewController.swift */; };
F79EDAA326B004980007D134 /* NCPlayerToolBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = F79EDA9F26B004980007D134 /* NCPlayerToolBar.swift */; };
F79EDAA526B004980007D134 /* NCPlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F79EDAA126B004980007D134 /* NCPlayer.swift */; };
Expand Down Expand Up @@ -1217,8 +1213,6 @@
F70CAE391F8CF31A008125FD /* NCEndToEndEncryption.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NCEndToEndEncryption.m; sourceTree = "<group>"; };
F70CEF5523E9C7E50007035B /* UIColor+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Extension.swift"; sourceTree = "<group>"; };
F70D7C3525FFBF81002B9E34 /* NCCollectionViewCommon.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCCollectionViewCommon.swift; sourceTree = "<group>"; };
F70D87CD25EE6E58008CBBBD /* NCRenameFile.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = NCRenameFile.storyboard; sourceTree = "<group>"; };
F70D87CE25EE6E58008CBBBD /* NCRenameFile.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCRenameFile.swift; sourceTree = "<group>"; };
F70D8D8024A4A9BF000A5756 /* NCNetworkingProcess.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCNetworkingProcess.swift; sourceTree = "<group>"; };
F70F2BA4225F2D8900EBB73E /* ZIPFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ZIPFoundation.framework; path = Carthage/Build/iOS/ZIPFoundation.framework; sourceTree = "<group>"; };
F70F96AF2874394B006C8379 /* Nextcloud-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Nextcloud-Bridging-Header.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2082,15 +2076,6 @@
path = Color;
sourceTree = "<group>";
};
F70D87CC25EE6E58008CBBBD /* Rename file */ = {
isa = PBXGroup;
children = (
F70D87CD25EE6E58008CBBBD /* NCRenameFile.storyboard */,
F70D87CE25EE6E58008CBBBD /* NCRenameFile.swift */,
);
path = "Rename file";
sourceTree = "<group>";
};
F713418B2597513800768D21 /* PushNotification */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2980,7 +2965,6 @@
F7381ED9218218A4000B1560 /* Offline */,
F713418B2597513800768D21 /* PushNotification */,
F765F72E25237E3F00391DBE /* Recent */,
F70D87CC25EE6E58008CBBBD /* Rename file */,
F7CADB3D23CCDDA1000EEC78 /* RichWorkspace */,
F76882042C0DD1E7001CF441 /* Settings */,
F758B41E212C516300515F55 /* Scan document */,
Expand Down Expand Up @@ -3668,7 +3652,6 @@
F7145A231D12E3B700CAFEEC /* Localizable.strings in Resources */,
F746EC51273906C40052598D /* NCViewCertificateDetails.storyboard in Resources */,
F76C26A62850D3A500E42BDF /* Images.xcassets in Resources */,
F79EC784263161BA004E59D6 /* NCRenameFile.storyboard in Resources */,
F714805E262ED52900693E51 /* NCSectionFooter.xib in Resources */,
F700222D1EC479840080073F /* Custom.xcassets in Resources */,
);
Expand Down Expand Up @@ -3714,7 +3697,6 @@
F702F2F125EE5CDB008F8E80 /* NCLogin.storyboard in Resources */,
F723985C253C95CE00257F49 /* NCViewerRichdocument.storyboard in Resources */,
F758B45A212C564000515F55 /* NCScan.storyboard in Resources */,
F70D87CF25EE6E58008CBBBD /* NCRenameFile.storyboard in Resources */,
F765F73225237E3F00391DBE /* NCRecent.storyboard in Resources */,
F78F74342163757000C2ADAD /* NCTrash.storyboard in Resources */,
F702F30225EE5D2C008F8E80 /* english.txt in Resources */,
Expand Down Expand Up @@ -4046,7 +4028,6 @@
F76D364728A4F8BF00214537 /* NCActivityIndicator.swift in Sources */,
F73EF7CA2B0225610087E6E9 /* NCManageDatabase+PhotoLibrary.swift in Sources */,
F749B654297B0F2400087535 /* NCManageDatabase+Avatar.swift in Sources */,
F79EC77F26316193004E59D6 /* NCRenameFile.swift in Sources */,
AF22B208277B4E4C00DAB0CC /* NCCreateFormUploadConflictCell.swift in Sources */,
F74C86382AEFBE64009A1D4A /* NCImageCache.swift in Sources */,
F73EF7C22B02250B0087E6E9 /* NCManageDatabase+GPS.swift in Sources */,
Expand Down Expand Up @@ -4234,7 +4215,6 @@
F702F30825EE5D47008F8E80 /* NCPopupViewController.swift in Sources */,
F733598125C1C188002ABA72 /* NCAskAuthorization.swift in Sources */,
370D26AF248A3D7A00121797 /* NCCellProtocol.swift in Sources */,
F70D87D025EE6E58008CBBBD /* NCRenameFile.swift in Sources */,
F768822C2C0DD1E7001CF441 /* NCKeychain.swift in Sources */,
F71CD6CA2930D7B1006C95C1 /* NCApplicationHandle.swift in Sources */,
F73EF7D72B0226080087E6E9 /* NCManageDatabase+Tip.swift in Sources */,
Expand Down Expand Up @@ -5414,7 +5394,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 13;
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = NKUJUXUJ3B;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand All @@ -5441,7 +5421,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 5.5.4;
MARKETING_VERSION = 5.5.5;
ONLY_ACTIVE_ARCH = YES;
OTHER_CFLAGS = "-v";
OTHER_LDFLAGS = "";
Expand Down Expand Up @@ -5480,7 +5460,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 13;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = NKUJUXUJ3B;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
Expand All @@ -5504,7 +5484,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 5.5.4;
MARKETING_VERSION = 5.5.5;
ONLY_ACTIVE_ARCH = YES;
OTHER_CFLAGS = "-v";
OTHER_LDFLAGS = "";
Expand Down Expand Up @@ -5779,7 +5759,7 @@
repositoryURL = "https://github.com/nextcloud/NextcloudKit";
requirement = {
kind = exactVersion;
version = 4.0.6;
version = 4.0.8;
};
};
F788ECC5263AAAF900ADC67F /* XCRemoteSwiftPackageReference "MarkdownKit" */ = {
Expand Down
7 changes: 5 additions & 2 deletions Share/NCShareExtension+DataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ extension NCShareExtension: UICollectionViewDelegate {
showAlert(title: "_info_", description: "_e2e_goto_settings_for_enable_")
}

if let fileNameError = FileNameValidator.shared.checkFileName(metadata.fileNameView) {
present(UIAlertController.warning(message: "\(fileNameError.errorDescription) \(NSLocalizedString("_please_rename_file_", comment: ""))"), animated: true)
return
}

self.serverUrl = serverUrl
reloadDatasource(withLoadFolder: true)
setNavigationBar(navigationTitle: metadata.fileNameView)
Expand Down Expand Up @@ -84,8 +89,6 @@ extension NCShareExtension: UICollectionViewDataSource {
return UICollectionViewCell()
}

cell.listCellDelegate = self

cell.fileObjectId = metadata.ocId
cell.indexPath = indexPath
cell.fileUser = metadata.ownerId
Expand Down
1 change: 1 addition & 0 deletions Share/NCShareExtension+Files.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import Foundation
import UniformTypeIdentifiers
import NextcloudKit

extension NCShareExtension {
@objc func reloadDatasource(withLoadFolder: Bool) {
Expand Down
79 changes: 31 additions & 48 deletions Share/NCShareExtension+NCDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,30 @@ extension NCShareExtension: NCAccountRequestDelegate {

reloadDatasource(withLoadFolder: true)
setNavigationBar(navigationTitle: NCBrandOptions.shared.brand)

FileNameValidator.shared.setup(
forbiddenFileNames: NCGlobal.shared.capabilityForbiddenFileNames,
forbiddenFileNameBasenames: NCGlobal.shared.capabilityForbiddenFileNameBasenames,
forbiddenFileNameCharacters: NCGlobal.shared.capabilityForbiddenFileNameCharacters,
forbiddenFileNameExtensions: NCGlobal.shared.capabilityForbiddenFileNameExtensions
)
}
}

extension NCShareExtension: NCCreateFormUploadConflictDelegate {
func dismissCreateFormUploadConflict(metadatas: [tableMetadata]?) {
guard let metadatas = metadatas else {
uploadStarted = false
uploadMetadata.removeAll()
return
}

self.uploadMetadata.append(contentsOf: metadatas)
self.upload()
}
}

extension NCShareExtension: NCShareCellDelegate, NCRenameFileDelegate, NCListCellDelegate {
extension NCShareExtension: NCShareCellDelegate {
func removeFile(named fileName: String) {
guard let index = self.filesName.firstIndex(of: fileName) else {
return showAlert(title: "_file_not_found_", description: fileName)
Expand All @@ -110,54 +130,17 @@ extension NCShareExtension: NCShareCellDelegate, NCRenameFileDelegate, NCListCel
}

func renameFile(named fileName: String) {
guard let vcRename = UIStoryboard(name: "NCRenameFile", bundle: nil).instantiateInitialViewController() as? NCRenameFile else { return }

let resultInternalType = NextcloudKit.shared.nkCommonInstance.getInternalType(fileName: fileName, mimeType: "", directory: false)
vcRename.delegate = self
vcRename.fileName = fileName
vcRename.indexPath = IndexPath()
if let previewImage = UIImage.downsample(imageAt: URL(fileURLWithPath: NSTemporaryDirectory() + fileName), to: CGSize(width: 140, height: 140)) {
vcRename.imagePreview = previewImage
} else {
vcRename.imagePreview = UIImage(named: resultInternalType.iconName) ?? NCImageCache.images.file
let alert = UIAlertController.renameFile(fileName: fileName) { [self] newFileName in
guard let fileIx = self.filesName.firstIndex(of: fileName),
!self.filesName.contains(newFileName),
utilityFileSystem.moveFile(atPath: (NSTemporaryDirectory() + fileName), toPath: (NSTemporaryDirectory() + newFileName)) else {
return showAlert(title: "_single_file_conflict_title_", description: "'\(fileName)' -> '\(newFileName)'")
}

filesName[fileIx] = newFileName
tableView.reloadData()
}

let popup = NCPopupViewController(contentController: vcRename, popupWidth: vcRename.width, popupHeight: vcRename.height)

self.present(popup, animated: true)
}

func rename(fileName: String, fileNameNew: String) {
guard fileName != fileNameNew else { return }
guard let fileIx = self.filesName.firstIndex(of: fileName),
!self.filesName.contains(fileNameNew),
utilityFileSystem.moveFile(atPath: (NSTemporaryDirectory() + fileName), toPath: (NSTemporaryDirectory() + fileNameNew)) else {
return showAlert(title: "_single_file_conflict_title_", description: "'\(fileName)' -> '\(fileNameNew)'")
}

filesName[fileIx] = fileNameNew
tableView.reloadData()
}

func tapShareListItem(with objectId: String, indexPath: IndexPath, sender: Any) {
}

func tapMoreListItem(with objectId: String, namedButtonMore: String, image: UIImage?, indexPath: IndexPath, sender: Any) {
}

func longPressListItem(with objectId: String, indexPath: IndexPath, gestureRecognizer: UILongPressGestureRecognizer) {
}
}

extension NCShareExtension: NCCreateFormUploadConflictDelegate {
func dismissCreateFormUploadConflict(metadatas: [tableMetadata]?) {
guard let metadatas = metadatas else {
uploadStarted = false
uploadMetadata.removeAll()
return
}

self.uploadMetadata.append(contentsOf: metadatas)
self.upload()
present(alert, animated: true)
}
}
7 changes: 7 additions & 0 deletions Share/NCShareExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,12 @@ extension NCShareExtension {

var conflicts: [tableMetadata] = []
for fileName in filesName {
if let fileNameError = FileNameValidator.shared.checkFileName(fileName) {
present(UIAlertController.warning(message: "\(fileNameError.errorDescription) \(NSLocalizedString("_please_rename_file_", comment: ""))"), animated: true)

continue
}

let ocId = NSUUID().uuidString
let toPath = utilityFileSystem.getDirectoryProviderStorageOcId(ocId, fileNameView: fileName)
guard utilityFileSystem.copyFile(atPath: (NSTemporaryDirectory() + fileName), toPath: toPath) else { continue }
Expand Down Expand Up @@ -335,6 +341,7 @@ extension NCShareExtension {
guard uploadStarted else { return }
guard uploadMetadata.count > counterUploaded else { return DispatchQueue.main.async { self.finishedUploading() } }
let metadata = uploadMetadata[counterUploaded]

let results = NextcloudKit.shared.nkCommonInstance.getInternalType(fileName: metadata.fileNameView, mimeType: metadata.contentType, directory: false)
metadata.contentType = results.mimeType
metadata.iconName = results.iconName
Expand Down
Loading

0 comments on commit 6d1744a

Please sign in to comment.