Skip to content

Commit

Permalink
fix(PHAsset): use edit date instead of FullSizeRender when importing …
Browse files Browse the repository at this point in the history
…edited pictures from Photo.app
  • Loading branch information
adrien-coye committed Aug 4, 2023
1 parent c2be5a9 commit 7124cee
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Infomaniak/ios-core",
"state" : {
"revision" : "f0442baed7595fbd59119e5ae2ddcd82fee3832b",
"version" : "4.1.11"
"revision" : "749bcfa71388c0d46129d448f0aff3e7ae476da5",
"version" : "4.1.12"
}
},
{
Expand Down
8 changes: 6 additions & 2 deletions kDriveCore/Utils/Files/FileImportHelper+Upload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,13 @@ public extension FileImportHelper {
return url
}

static func getDefaultFileName() -> String {
private static let fileNameDateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "yyyyMMdd_HHmmssSS"
return formatter.string(from: Date())
return formatter
}()

static func getDefaultFileName() -> String {
return Self.fileNameDateFormatter.string(from: Date())
}
}
11 changes: 10 additions & 1 deletion kDriveCore/Utils/PHAsset+Exension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,16 @@ public extension PHAsset {
guard let resource = bestResource() else { return nil }

let lastPathComponent = resource.originalFilename.split(separator: ".")
return "\(lastPathComponent[0]).\(uti.preferredFilenameExtension ?? "")"
let filename = lastPathComponent[0]
let preferredFilenameExtension = uti.preferredFilenameExtension ?? ""

// Edited pictures on Photo.app have the same name, using modification date instead
guard filename != "FullSizeRender" else {
let editDate = modificationDate ?? Date()
return "\(URL.defaultFileName(date: editDate)).\(preferredFilenameExtension)"
}

return "\(filename).\(preferredFilenameExtension)"
}

func bestResource() -> PHAssetResource? {
Expand Down

0 comments on commit 7124cee

Please sign in to comment.