From 50fba234b0db92f28161542133a8106cd700f7a0 Mon Sep 17 00:00:00 2001 From: fmodf Date: Fri, 12 Jul 2024 13:54:40 +0200 Subject: [PATCH] wip --- .../AppCore/Files/DownloadManager.swift | 26 +++++++++++++++++++ .../AppCore/Files/FileManager.swift | 3 +++ .../AppCore/Middlewares/FileMiddleware.swift | 25 ------------------ 3 files changed, 29 insertions(+), 25 deletions(-) create mode 100644 ConversationsClassic/AppCore/Files/DownloadManager.swift create mode 100644 ConversationsClassic/AppCore/Files/FileManager.swift diff --git a/ConversationsClassic/AppCore/Files/DownloadManager.swift b/ConversationsClassic/AppCore/Files/DownloadManager.swift new file mode 100644 index 0000000..f548244 --- /dev/null +++ b/ConversationsClassic/AppCore/Files/DownloadManager.swift @@ -0,0 +1,26 @@ +import Foundation + +final class DownloadManager { + private let urlSession: URLSession + + init() { + let configuration = URLSessionConfiguration.default + urlSession = URLSession(configuration: configuration) + } + + func download(from url: URL, to localUrl: URL, completion: @escaping (Error?) -> Void) { + let task = urlSession.downloadTask(with: url) { tempLocalUrl, _, error in + if let tempLocalUrl = tempLocalUrl, error == nil { + do { + try FileManager.default.copyItem(at: tempLocalUrl, to: localUrl) + completion(nil) + } catch let writeError { + completion(writeError) + } + } else { + completion(error) + } + } + task.resume() + } +} diff --git a/ConversationsClassic/AppCore/Files/FileManager.swift b/ConversationsClassic/AppCore/Files/FileManager.swift new file mode 100644 index 0000000..8ee7823 --- /dev/null +++ b/ConversationsClassic/AppCore/Files/FileManager.swift @@ -0,0 +1,3 @@ +import Foundation + +final class FileManager {} diff --git a/ConversationsClassic/AppCore/Middlewares/FileMiddleware.swift b/ConversationsClassic/AppCore/Middlewares/FileMiddleware.swift index fcac91b..ac69cc9 100644 --- a/ConversationsClassic/AppCore/Middlewares/FileMiddleware.swift +++ b/ConversationsClassic/AppCore/Middlewares/FileMiddleware.swift @@ -69,28 +69,3 @@ private extension FileMiddleware { return documentsURL.appendingPathComponent(Const.fileFolder) } } - -private final class DownloadManager { - private let urlSession: URLSession - - init() { - let configuration = URLSessionConfiguration.default - urlSession = URLSession(configuration: configuration) - } - - func download(from url: URL, to localUrl: URL, completion: @escaping (Error?) -> Void) { - let task = urlSession.downloadTask(with: url) { tempLocalUrl, _, error in - if let tempLocalUrl = tempLocalUrl, error == nil { - do { - try FileManager.default.copyItem(at: tempLocalUrl, to: localUrl) - completion(nil) - } catch let writeError { - completion(writeError) - } - } else { - completion(error) - } - } - task.resume() - } -}