Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@
F719D9E0288D37A300762E33 /* NCColorPicker.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F719D9DF288D37A300762E33 /* NCColorPicker.storyboard */; };
F719D9E2288D396100762E33 /* NCColorPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = F719D9E1288D396100762E33 /* NCColorPicker.swift */; };
F71CD6CA2930D7B1006C95C1 /* NCApplicationHandle.swift in Sources */ = {isa = PBXBuildFile; fileRef = F71CD6C92930D7B1006C95C1 /* NCApplicationHandle.swift */; };
F71CFA672F2A07DB007A3AE9 /* NCMedia+Netwoking.swift in Sources */ = {isa = PBXBuildFile; fileRef = F71CFA662F2A07C6007A3AE9 /* NCMedia+Netwoking.swift */; };
F71D2FB72E09BBD700B751CC /* NCAutoUploadModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F71D2FB62E09BBD700B751CC /* NCAutoUploadModel.swift */; };
F71F6D072B6A6A5E00F1EB15 /* ThreadSafeArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = F71F6D062B6A6A5E00F1EB15 /* ThreadSafeArray.swift */; };
F71F6D082B6A6A5E00F1EB15 /* ThreadSafeArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = F71F6D062B6A6A5E00F1EB15 /* ThreadSafeArray.swift */; };
Expand Down Expand Up @@ -1337,6 +1338,7 @@
F719D9DF288D37A300762E33 /* NCColorPicker.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = NCColorPicker.storyboard; sourceTree = "<group>"; };
F719D9E1288D396100762E33 /* NCColorPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCColorPicker.swift; sourceTree = "<group>"; };
F71CD6C92930D7B1006C95C1 /* NCApplicationHandle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCApplicationHandle.swift; sourceTree = "<group>"; };
F71CFA662F2A07C6007A3AE9 /* NCMedia+Netwoking.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCMedia+Netwoking.swift"; sourceTree = "<group>"; };
F71D2FB62E09BBD700B751CC /* NCAutoUploadModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCAutoUploadModel.swift; sourceTree = "<group>"; };
F71F6D062B6A6A5E00F1EB15 /* ThreadSafeArray.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreadSafeArray.swift; sourceTree = "<group>"; };
F722133A2D40EF8C002F7438 /* NCFilesNavigationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCFilesNavigationController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3161,12 +3163,13 @@
F72408322B8A27C900F128E2 /* NCMedia+Command.swift */,
F7802B312BD5584F00D74270 /* NCMedia+DragDrop.swift */,
F7BD0A032C4689E9003A4A6D /* NCMedia+MediaLayout.swift */,
F71CFA662F2A07C6007A3AE9 /* NCMedia+Netwoking.swift */,
F7E2B64E2DDCC5C30075B4D0 /* NCMedia+TransferDelegate.swift */,
F78B87E62B62527100C65ADC /* NCMediaDataSource.swift */,
F79699E62E689F68000EC82A /* NCMediaNavigationController.swift */,
F7D60CAE2C941ACB008FBFDD /* NCMediaPinchGesture.swift */,
F78B87E82B62550800C65ADC /* NCMediaDownloadThumbnail.swift */,
F755CB3F2B8CB13C00CE27E9 /* NCMediaLayout.swift */,
F79699E62E689F68000EC82A /* NCMediaNavigationController.swift */,
F7D60CAE2C941ACB008FBFDD /* NCMediaPinchGesture.swift */,
F741C2232B6B9FD600E849BB /* NCMediaSelectTabBar.swift */,
);
path = Media;
Expand Down Expand Up @@ -4559,6 +4562,7 @@
F7D4BF4D2CA2E8D800A5E746 /* TOPasscodeViewController.m in Sources */,
F75C0C4823D1FAE300163CC8 /* NCRichWorkspaceCommon.swift in Sources */,
AAE330042D2ED20200B04903 /* NCShareNavigationTitleSetting.swift in Sources */,
F71CFA672F2A07DB007A3AE9 /* NCMedia+Netwoking.swift in Sources */,
F7DF7B422F1A36C100514020 /* HelperBanner.swift in Sources */,
F78ACD4A21903F850088454D /* NCTrashListCell.swift in Sources */,
F7386E482DA90E0F009A00F6 /* NCAppVersionManager.swift in Sources */,
Expand Down
117 changes: 117 additions & 0 deletions iOSClient/Media/NCMedia+Netwoking.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// SPDX-FileCopyrightText: Nextcloud GmbH
// SPDX-FileCopyrightText: 2026 Marino Faggiana
// SPDX-License-Identifier: GPL-3.0-or-later

import Foundation
import NextcloudKit
import Alamofire

extension NCMedia {
func searchMediaAsync(path: String = "",
lessDate: Any,
greaterDate: Any,
elementDate: String,
limit: Int,
account: String,
options: NKRequestOptions = NKRequestOptions(),
taskHandler: @escaping (_ task: URLSessionTask) -> Void = { _ in }
) async -> (account: String, files: [NKFile]?, error: NKError) {
guard let nkSession = NextcloudKit.shared.nkCommonInstance.nksessions.session(forAccount: account) else {
return (account, nil, .urlError)
}
let files: [NKFile] = []
let elementDate = elementDate + "/"
var greaterDateString: String?, lessDateString: String?
let href = "/files/" + nkSession.userId + path
if let lessDate = lessDate as? Date {
lessDateString = lessDate.formatted(using: "yyyy-MM-dd'T'HH:mm:ssZZZZZ")
} else if let lessDate = lessDate as? Int {
lessDateString = String(lessDate)
}
if let greaterDate = greaterDate as? Date {
greaterDateString = greaterDate.formatted(using: "yyyy-MM-dd'T'HH:mm:ssZZZZZ")
} else if let greaterDate = greaterDate as? Int {
greaterDateString = String(greaterDate)
}
guard let lessDateString, let greaterDateString else {
return (account, files, .invalidDate)
}

let httpBodyString = String(format: getRequestBodySearchMedia(createProperties: options.createProperties, removeProperties: options.removeProperties), href, elementDate, elementDate, lessDateString, elementDate, greaterDateString, String(limit))

guard let httpBody = httpBodyString.data(using: .utf8) else {
return (account, files, .invalidData)
}

let results = await NextcloudKit.shared.searchAsync(serverUrl: nkSession.urlBase, httpBody: httpBody, showHiddenFiles: false, includeHiddenFiles: [], account: account, options: options, taskHandler: taskHandler)

return(results.account, results.files, results.error)
}

func getRequestBodySearchMedia(createProperties: [NKProperties]?, removeProperties: [NKProperties] = []) -> String {
let request = """
<?xml version=\"1.0\"?>
<d:searchrequest xmlns:d=\"DAV:\" xmlns:oc=\"http://owncloud.org/ns\" xmlns:nc=\"http://nextcloud.org/ns\">
<d:basicsearch>
<d:select>
<d:prop>
""" + NKProperties.properties(createProperties: createProperties, removeProperties: removeProperties) + """
</d:prop>
</d:select>
<d:from>
<d:scope>
<d:href>%@</d:href>
<d:depth>infinity</d:depth>
</d:scope>
</d:from>
<d:orderby>
<d:order>
<d:prop><%@></d:prop>
<d:descending/>
</d:order>
<d:order>
<d:prop><d:displayname/></d:prop>
<d:descending/>
</d:order>
</d:orderby>
<d:where>
<d:and>
<d:or>
<d:like>
<d:prop><d:getcontenttype/></d:prop>
<d:literal>image/%%</d:literal>
</d:like>
<d:like>
<d:prop><d:getcontenttype/></d:prop>
<d:literal>video/%%</d:literal>
</d:like>
</d:or>
<d:or>
<d:and>
<d:lt>
<d:prop><%@></d:prop>
<d:literal>%@</d:literal>
</d:lt>
<d:gt>
<d:prop><%@></d:prop>
<d:literal>%@</d:literal>
</d:gt>
</d:and>
</d:or>
</d:and>
</d:where>
<d:limit>
<d:nresults>%@</d:nresults>
</d:limit>
</d:basicsearch>
</d:searchrequest>
"""
return request
}
}

extension Date {
func formatted(using format: String) -> String {
NKLogFileManager.shared.convertDate(self, format: format)
}
}
14 changes: 7 additions & 7 deletions iOSClient/Media/NCMediaDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ extension NCMedia {

let options = NKRequestOptions(timeout: 180, taskDescription: self.global.taskDescriptionRetrievesProperties, queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)

let result = await NextcloudKit.shared.searchMediaAsync(path: tblAccount.mediaPath,
lessDate: lessDateAny,
greaterDate: greaterDateAny,
elementDate: elementDate,
limit: limit,
account: self.session.account,
options: options) { task in
let result = await searchMediaAsync(path: tblAccount.mediaPath,
lessDate: lessDateAny,
greaterDate: greaterDateAny,
elementDate: elementDate,
limit: limit,
account: self.session.account,
options: options) { task in
Task {
let identifier = await NCNetworking.shared.networkingTasks.createIdentifier(account: self.session.account,
name: "searchMedia")
Expand Down
Loading