Merge pull request #1039 from mpretty-cyro/fix/attachment-path-creation

Fixed a couple of bugs with attachment path creation
pull/1040/head
Morgan Pretty 6 months ago committed by GitHub
commit d21578e77f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -610,10 +610,6 @@ extension Attachment {
}
public static func originalFilePath(id: String, mimeType: String, sourceFilename: String?) -> String? {
// Store the file in a subdirectory whose name is the uniqueId of this attachment,
// to avoid collisions between multiple attachments with the same name
let attachmentFolder: String = Attachment.attachmentsFolder.appending("/\(id)")
if let sourceFilename: String = sourceFilename, !sourceFilename.isEmpty {
// Ensure that the filename is a valid filesystem name,
// replacing invalid characters with an underscore.
@ -647,6 +643,10 @@ extension Attachment {
targetFileExtension = targetFileExtension.lowercased()
if !targetFileExtension.isEmpty {
// Store the file in a subdirectory whose name is the uniqueId of this attachment,
// to avoid collisions between multiple attachments with the same name
let attachmentFolder: String = Attachment.attachmentsFolder.appending("/\(id)")
guard case .success = Result(try FileSystem.ensureDirectoryExists(at: attachmentFolder)) else {
return nil
}
@ -660,7 +660,7 @@ extension Attachment {
UTType.fileExtensionDefault
).lowercased()
return attachmentFolder.appending("/\(id).\(targetFileExtension)")
return Attachment.attachmentsFolder.appending("/\(id).\(targetFileExtension)")
}
public static func localRelativeFilePath(from originalFilePath: String?) -> String? {

@ -123,7 +123,7 @@ public extension UTType {
let mimeType: String = preferredMIMEType,
let fileExtension: String = UTType.genericExtensionTypesToMimeTypes
.first(where: { _, value in value == mimeType })?
.value
.key
else { return preferredFilenameExtension }
return fileExtension

Loading…
Cancel
Save