2022-04-19 12:29:03 +04:00
|
|
|
//
|
|
|
|
// FileUtils.swift
|
|
|
|
// SimpleX (iOS)
|
|
|
|
//
|
|
|
|
// Created by JRoberts on 15.04.2022.
|
|
|
|
// Copyright © 2022 SimpleX Chat. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import SwiftUI
|
|
|
|
|
2022-04-25 12:44:24 +04:00
|
|
|
// maximum image file size to be auto-accepted
|
|
|
|
let maxImageSize = 236700
|
|
|
|
|
2022-04-19 12:29:03 +04:00
|
|
|
func getDocumentsDirectory() -> URL {
|
|
|
|
return FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
|
|
|
|
}
|
|
|
|
|
|
|
|
func getAppFilesDirectory() -> URL {
|
|
|
|
return getDocumentsDirectory().appendingPathComponent("app_files", isDirectory: true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func getStoredFilePath(_ file: CIFile?) -> String? {
|
|
|
|
if let file = file,
|
|
|
|
file.stored,
|
|
|
|
let savedFile = file.filePath {
|
|
|
|
return getAppFilesDirectory().path + "/" + savedFile
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func getStoredImage(_ file: CIFile?) -> UIImage? {
|
|
|
|
if let filePath = getStoredFilePath(file) {
|
|
|
|
return UIImage(contentsOfFile: filePath)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|