Save automatically, improve mocks
This commit is contained in:
@ -51,6 +51,8 @@ final class FileResource: Item, LocalizedItem {
|
||||
@Published
|
||||
var fileSize: Int? = nil
|
||||
|
||||
var savedData: Data?
|
||||
|
||||
init(content: Content,
|
||||
id: String,
|
||||
isExternallyStored: Bool,
|
||||
@ -78,7 +80,7 @@ final class FileResource: Item, LocalizedItem {
|
||||
/**
|
||||
Only for bundle images
|
||||
*/
|
||||
init(resourceImage: String, type: FileType) {
|
||||
init(content: Content, resourceImage: String, type: FileType) {
|
||||
self.type = type
|
||||
self.english = "A test image included in the bundle"
|
||||
self.german = "Ein Testbild aus dem Bundle"
|
||||
@ -89,7 +91,7 @@ final class FileResource: Item, LocalizedItem {
|
||||
self.customOutputPath = nil
|
||||
self.addedDate = Date.now
|
||||
self.modifiedDate = Date.now
|
||||
super.init(content: .mock, id: resourceImage) // TODO: Add images to mock
|
||||
super.init(content: content, id: resourceImage)
|
||||
}
|
||||
|
||||
// MARK: Text
|
||||
@ -349,7 +351,7 @@ extension FileResource: CustomStringConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
extension FileResource {
|
||||
extension FileResource: StorageItem {
|
||||
|
||||
convenience init(content: Content, id: String, data: FileResource.Data, isExternalFile: Bool) {
|
||||
self.init(
|
||||
@ -364,6 +366,7 @@ extension FileResource {
|
||||
customOutputPath: data.customOutputPath,
|
||||
addedDate: data.addedDate,
|
||||
modifiedDate: data.modifiedDate)
|
||||
savedData = data
|
||||
}
|
||||
|
||||
var data: Data {
|
||||
@ -379,7 +382,7 @@ extension FileResource {
|
||||
}
|
||||
|
||||
/// This struct holds metadata about a file resource that is stored in the content folder.
|
||||
struct Data: Codable {
|
||||
struct Data: Codable, Equatable {
|
||||
let englishDescription: String?
|
||||
let germanDescription: String?
|
||||
let generatedImages: [String]?
|
||||
@ -389,4 +392,8 @@ extension FileResource {
|
||||
let addedDate: Date
|
||||
let modifiedDate: Date
|
||||
}
|
||||
|
||||
func saveToDisk(_ data: Data) -> Bool {
|
||||
content.storage.save(fileResource: data, for: id)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user