Improve storage

This commit is contained in:
Christoph Hagen
2024-12-19 16:25:05 +01:00
parent 9c828ff80a
commit 41887a1401
30 changed files with 926 additions and 831 deletions

View File

@ -39,16 +39,11 @@ final class FileResource: Item {
// MARK: Text
func textContent() -> String {
do {
return try content.storage.fileContent(for: id)
} catch {
print("Failed to load text of file \(id): \(error)")
return ""
}
content.storage.fileContent(for: id) ?? ""
}
func dataContent() throws -> Data {
try content.storage.fileData(for: id)
func dataContent() -> Data? {
content.storage.fileData(for: id)
}
// MARK: Images
@ -61,11 +56,8 @@ final class FileResource: Item {
}
var imageToDisplay: Image {
let imageData: Data
do {
imageData = try content.storage.fileData(for: id)
} catch {
print("Failed to load data for image \(id): \(error)")
guard let imageData = content.storage.fileData(for: id) else {
print("Failed to load data for image \(id)")
return failureImage
}
guard let loadedImage = NSImage(data: imageData) else {
@ -123,14 +115,12 @@ final class FileResource: Item {
id = newId
return true
}
do {
try content.storage.move(file: id, to: newId)
id = newId
return true
} catch {
guard content.storage.move(file: id, to: newId) else {
print("Failed to move file \(id) to \(newId)")
return false
}
id = newId
return true
}
}