Skip to content

[stable-5.2.7] NMC/2248 - Image video upload #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
36 changes: 36 additions & 0 deletions Tests/NextcloudUnitTests/AssetUploadTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// AssetUploadTest.swift
// NextcloudTests
//
// Created by A200020526 on 12/06/23.
// Copyright © 2023 Marino Faggiana. All rights reserved.
//

import XCTest

final class AssetUploadTest: XCTestCase {

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
// Any test you write for XCTest can be annotated as throws and async.
// Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
// Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
}

func testPerformanceExample() throws {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}

}
248 changes: 99 additions & 149 deletions iOSClient/Main/Create cloud/NCUploadAssets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ struct UploadAssetsView: View {
}

private func setFileNameMaskForPreview(fileName: String?) -> String {
let utilityFileSystem = NCUtilityFileSystem()
guard let asset = uploadAssets.assets.first?.phAsset else { return "" }
var preview: String = ""
let creationDate = asset.creationDate ?? Date()
Expand All @@ -200,8 +201,30 @@ struct UploadAssetsView: View {
)

let trimmedPreview = preview.trimmingCharacters(in: .whitespacesAndNewlines)

if !(fileName?.isEmpty ?? false) {

NCKeychain().setFileNameMask(key: fileName ?? "", mask: NCGlobal.shared.keyFileNameMask)
preview = CCUtility.createFileName(asset.value(forKey: "filename") as? String,
fileDate: creationDate, fileType: asset.mediaType,
keyFileName: NCGlobal.shared.keyFileNameMask,
keyFileNameType: NCGlobal.shared.keyFileNameType,
keyFileNameOriginal: NCGlobal.shared.keyFileNameOriginal,
forcedNewFileName: false)

} else {

NCKeychain().setFileNameMask(key: "", mask: NCGlobal.shared.keyFileNameMask)
preview = CCUtility.createFileName(asset.value(forKey: "filename") as? String,
fileDate: creationDate,
fileType: asset.mediaType,
keyFileName: nil,
keyFileNameType: NCGlobal.shared.keyFileNameType,
keyFileNameOriginal: NCGlobal.shared.keyFileNameOriginal,
forcedNewFileName: false)
}

return String(format: NSLocalizedString("_preview_filename_", comment: ""), "MM, MMM, DD, YY, YYYY, HH, hh, mm, ss, ampm") + ":" + "\n\n" + (trimmedPreview as NSString).deletingPathExtension
return (!isMaintainOriginalFilename ? (String(format: NSLocalizedString("_preview_filename_", comment: ""), "MM, MMM, DD, YY, YYYY, HH, hh, mm, ss, ampm") + ":" + "\n\n") : #"\#(NSLocalizedString("_filename_", comment: "") ): "#) + preview
}

private func save(completion: @escaping (_ metadatasNOConflict: [tableMetadata], _ metadatasUploadInConflict: [tableMetadata]) -> Void) {
Expand Down Expand Up @@ -339,74 +362,48 @@ struct UploadAssetsView: View {
NavigationView {
ZStack(alignment: .top) {
List {
Section(footer: Text(NSLocalizedString("_modify_image_desc_", comment: ""))) {
ScrollView(.horizontal) {
LazyHGrid(rows: gridItems, alignment: .center, spacing: 10) {
ForEach(0..<uploadAssets.previewStore.count, id: \.self) { index in
let item = uploadAssets.previewStore[index]
Menu {
Button(action: {
renameFileName = uploadAssets.previewStore[index].fileName
renameIndex = index
isPresentedAlert = true
}) {
Label(NSLocalizedString("_rename_", comment: ""), systemImage: "pencil")
}
if item.asset.type == .photo || item.asset.type == .livePhoto {
Button(action: {
presentedQuickLook(index: index)
}) {
Label(NSLocalizedString("_modify_", comment: ""), systemImage: "pencil.tip.crop.circle")
}
}
if item.data != nil {
Button(action: {
if let image = uploadAssets.previewStore[index].asset.fullResolutionImage?.resizeImage(size: CGSize(width: 300, height: 300), isAspectRation: true) {
uploadAssets.previewStore[index].image = image
uploadAssets.previewStore[index].data = nil
uploadAssets.previewStore[index].assetType = uploadAssets.previewStore[index].asset.type
}
}) {
Label(NSLocalizedString("_undo_modify_", comment: ""), systemImage: "arrow.uturn.backward.circle")
}
}
if item.data == nil && item.asset.type == .livePhoto && item.assetType == .livePhoto {
Button(action: {
uploadAssets.previewStore[index].assetType = .photo
}) {
Label(NSLocalizedString("_disable_livephoto_", comment: ""), systemImage: "livephoto.slash")
}
} else if item.data == nil && item.asset.type == .livePhoto && item.assetType == .photo {
Button(action: {
uploadAssets.previewStore[index].assetType = .livePhoto
}) {
Label(NSLocalizedString("_enable_livephoto_", comment: ""), systemImage: "livephoto")
}
}
Button(role: .destructive, action: {
deleteAsset(index: index)
}) {
Label(NSLocalizedString("_remove_", comment: ""), systemImage: "trash")
}
} label: {
ImageAsset(uploadAssets: uploadAssets, index: index)
.alert(NSLocalizedString("_rename_file_", comment: ""), isPresented: $isPresentedAlert) {
TextField(NSLocalizedString("_enter_filename_", comment: ""), text: $renameFileName)
.autocapitalization(.none)
.autocorrectionDisabled()
Button(NSLocalizedString("_rename_", comment: ""), action: {
uploadAssets.previewStore[renameIndex].fileName = renameFileName.trimmingCharacters(in: .whitespacesAndNewlines)
})
Button(NSLocalizedString("_cancel_", comment: ""), role: .cancel, action: {})
}
}
}
//Save Path
Section(header: Text(NSLocalizedString("_save_path_", comment: "").uppercased()), footer: Text(NSLocalizedString("_auto_upload_help_text_", comment: ""))) {
HStack {
if utilityFileSystem.getHomeServer(urlBase: uploadAssets.userBaseUrl.urlBase, userId: uploadAssets.userBaseUrl.userId) == uploadAssets.serverUrl {
Text(NSLocalizedString("_prefix_upload_path_", comment: ""))
.font(.system(size: 15))
.frame(maxWidth: .infinity, alignment: .leading)
} else {
Text(self.getTextServerUrl(uploadAssets.serverUrl))
.font(.system(size: 15))
.frame(maxWidth: .infinity, alignment: .leading)
}

Image("folder")
.renderingMode(.template)
.resizable()
.scaledToFit()
.foregroundColor(Color(NCBrandColor.shared.brand))
.frame(width: 25, height: 25, alignment: .trailing)
}
.onTapGesture {
isPresentedSelect = true
}


Toggle(isOn: $uploadAssets.isUseAutoUploadFolder, label: {
Text(NSLocalizedString("_use_folder_auto_upload_", comment: ""))
.font(.system(size: 15))
})
.toggleStyle(SwitchToggleStyle(tint: Color(NCBrandColor.shared.brand)))

Toggle(isOn: $uploadAssets.isUseAutoUploadSubFolder, label: {
Text(NSLocalizedString("_autoupload_create_subfolder_", comment: ""))
.font(.system(size: 15))
.disabled(!uploadAssets.isUseAutoUploadFolder)
})
.toggleStyle(SwitchToggleStyle(tint: Color(NCBrandColor.shared.brand)))
.disabled(!uploadAssets.isUseAutoUploadFolder)
}
// .redacted(reason: uploadAssets.previewStore.isEmpty ? .placeholder : [])

Section {

//File Name
Section(header: Text(NSLocalizedString("_filename_", comment: "").uppercased()), footer: Text(setFileNameMaskForPreview(fileName: fileName))) {
Toggle(isOn: $isMaintainOriginalFilename, label: {
Text(NSLocalizedString("_maintain_original_filename_", comment: ""))
.font(.system(size: 15))
Expand All @@ -419,99 +416,52 @@ struct UploadAssetsView: View {
.font(.system(size: 15))
})
.toggleStyle(SwitchToggleStyle(tint: Color(NCBrandColor.shared.brand)))
}
}

Section {
Toggle(isOn: $uploadAssets.isUseAutoUploadFolder, label: {
Text(NSLocalizedString("_use_folder_auto_upload_", comment: ""))
.font(.system(size: 15))
})
.toggleStyle(SwitchToggleStyle(tint: Color(NCBrandColor.shared.brand)))

if uploadAssets.isUseAutoUploadFolder {
Toggle(isOn: $uploadAssets.isUseAutoUploadSubFolder, label: {
Text(NSLocalizedString("_autoupload_create_subfolder_", comment: ""))
.font(.system(size: 15))
})
.toggleStyle(SwitchToggleStyle(tint: Color(NCBrandColor.shared.brand)))
}

if !uploadAssets.isUseAutoUploadFolder {
HStack {
Label {
if utilityFileSystem.getHomeServer(urlBase: uploadAssets.userBaseUrl.urlBase, userId: uploadAssets.userBaseUrl.userId) == uploadAssets.serverUrl {
Text("/")
.font(.system(size: 15))
.frame(maxWidth: .infinity, alignment: .trailing)
} else {
Text(self.getTextServerUrl(uploadAssets.serverUrl))
.font(.system(size: 15))
.frame(maxWidth: .infinity, alignment: .trailing)
}
} icon: {
Image("folder")
.renderingMode(.template)
.resizable()
.scaledToFit()
.foregroundColor(Color(NCBrandColor.shared.brand))
if isMaintainOriginalFilename {
Text(getOriginalFilenameForPreview() as? String ?? "")
.font(.system(size: 15))
.frame(maxWidth: .infinity, alignment: .leading)
.foregroundColor(Color.gray)
} else {
TextField(NSLocalizedString("_enter_filename_", comment: ""), text: $fileName)
.font(.system(size: 15))
.modifier(TextFieldClearButton(text: $fileName))
.multilineTextAlignment(.leading)
}
}
.contentShape(Rectangle())
.onTapGesture {
isPresentedSelect = true
}
}
}

Section {
HStack {
Text(NSLocalizedString("_filename_", comment: ""))
if isMaintainOriginalFilename {
Text(getOriginalFilenameForPreview().deletingPathExtension)
.font(.system(size: 15))
.frame(maxWidth: .infinity, alignment: .trailing)
.foregroundColor(Color.gray)
} else {
TextField(NSLocalizedString("_enter_filename_", comment: ""), text: $fileName)
.font(.system(size: 15))
.modifier(TextFieldClearButton(text: $fileName))
.multilineTextAlignment(.trailing)
}
}
if !isMaintainOriginalFilename {
Text(setFileNameMaskForPreview(fileName: fileName))
.font(.system(size: 11))
.foregroundColor(Color.gray)
}
}
.complexModifier { view in
}.complexModifier { view in
view.listRowSeparator(.hidden)
}

Button(NSLocalizedString("_save_", comment: "")) {
if uploadAssets.isUseAutoUploadFolder, uploadAssets.isUseAutoUploadSubFolder {
uploadAssets.showHUD = true
}
uploadAssets.uploadInProgress.toggle()
save { metadatasNOConflict, metadatasUploadInConflict in
if metadatasUploadInConflict.isEmpty {
uploadAssets.dismissCreateFormUploadConflict(metadatas: metadatasNOConflict)
} else {
uploadAssets.metadatasNOConflict = metadatasNOConflict
uploadAssets.metadatasUploadInConflict = metadatasUploadInConflict
isPresentedUploadConflict = true
}
}
}
.frame(maxWidth: .infinity)
.buttonStyle(ButtonRounded(disabled: uploadAssets.uploadInProgress))
.listRowBackground(Color(UIColor.systemGroupedBackground))
.disabled(uploadAssets.uploadInProgress)
.hiddenConditionally(isHidden: uploadAssets.isHiddenSave)
}
.listStyle(GroupedListStyle())
.navigationTitle(NSLocalizedString("_upload_photos_videos_", comment: ""))
.navigationBarTitleDisplayMode(.inline)
.toolbar{
ToolbarItem(placement: .navigationBarLeading) {
Button(NSLocalizedString("_cancel_", comment: "")) {
self.uploadAssets.dismiss = true
}.foregroundColor(Color(NCBrandColor.shared.brand))
}
ToolbarItem(placement: .navigationBarTrailing) {
Button(NSLocalizedString("_save_", comment: "")) {
if uploadAssets.isUseAutoUploadFolder, uploadAssets.isUseAutoUploadSubFolder {
uploadAssets.showHUD = true
}
uploadAssets.uploadInProgress.toggle()
save { metadatasNOConflict, metadatasUploadInConflict in
if metadatasUploadInConflict.isEmpty {
uploadAssets.dismissCreateFormUploadConflict(metadatas: metadatasNOConflict)
} else {
uploadAssets.metadatasNOConflict = metadatasNOConflict
uploadAssets.metadatasUploadInConflict = metadatasUploadInConflict
isPresentedUploadConflict = true
}
}
}.foregroundColor(Color(NCBrandColor.shared.brand))
}
}

HUDView(showHUD: $uploadAssets.showHUD, textLabel: NSLocalizedString("_wait_", comment: ""), image: "doc.badge.arrow.up")
.offset(y: uploadAssets.showHUD ? 5 : -200)
Expand Down