From 451b82504ba4b50a678172d63f4532c77922e726 Mon Sep 17 00:00:00 2001 From: eToledo Date: Tue, 1 Dec 2020 13:28:04 +0100 Subject: [PATCH 1/6] Adding Audio Block upload processor --- .../Classes/Services/PostCoordinator.swift | 3 ++ .../GutenbergAudioUploadProcessor.swift | 54 +++++++++++++++++++ WordPress/WordPress.xcodeproj/project.pbxproj | 4 ++ 3 files changed, 61 insertions(+) create mode 100644 WordPress/Classes/ViewRelated/Gutenberg/Processors/GutenbergAudioUploadProcessor.swift diff --git a/WordPress/Classes/Services/PostCoordinator.swift b/WordPress/Classes/Services/PostCoordinator.swift index 4ae92b9104cb..693531800a10 100644 --- a/WordPress/Classes/Services/PostCoordinator.swift +++ b/WordPress/Classes/Services/PostCoordinator.swift @@ -330,6 +330,9 @@ class PostCoordinator: NSObject { let videoPostUploadProcessor = VideoUploadProcessor(mediaUploadID: mediaUploadID, remoteURLString: remoteURLStr, videoPressID: media.videopressGUID) aztecProcessors.append(videoPostUploadProcessor) + } else if media.mediaType == .audio { + let gutenbergAudioProcessor = GutenbergAudioUploadProcessor(mediaUploadID: gutenbergMediaUploadID, serverMediaID: mediaID, remoteURLString: remoteURLStr) + gutenbergProcessors.append(gutenbergAudioProcessor) } else if let remoteURL = URL(string: remoteURLStr) { let documentTitle = remoteURL.lastPathComponent let documentUploadProcessor = DocumentUploadProcessor(mediaUploadID: mediaUploadID, remoteURLString: remoteURLStr, title: documentTitle) diff --git a/WordPress/Classes/ViewRelated/Gutenberg/Processors/GutenbergAudioUploadProcessor.swift b/WordPress/Classes/ViewRelated/Gutenberg/Processors/GutenbergAudioUploadProcessor.swift new file mode 100644 index 000000000000..1c48b5d838e7 --- /dev/null +++ b/WordPress/Classes/ViewRelated/Gutenberg/Processors/GutenbergAudioUploadProcessor.swift @@ -0,0 +1,54 @@ +import Foundation +import Aztec + +class GutenbergAudioUploadProcessor: Processor { + private struct AudioBlockKeys { + static var name = "wp:audio" + static var id = "id" + static var src = "src" + } + + let mediaUploadID: Int32 + let remoteURLString: String + let serverMediaID: Int + + init(mediaUploadID: Int32, serverMediaID: Int, remoteURLString: String) { + self.mediaUploadID = mediaUploadID + self.serverMediaID = serverMediaID + self.remoteURLString = remoteURLString + } + + lazy var fileHtmlProcessor = HTMLProcessor(for: "audio", replacer: { (audio) in + var attributes = audio.attributes + + attributes.set(.string(self.remoteURLString), forKey: AudioBlockKeys.src) + + var html = "