Fix id of Items, saving

This commit is contained in:
Christoph Hagen
2025-06-11 08:19:44 +02:00
parent 5970ce2e9f
commit 1d0eba9d78
64 changed files with 233 additions and 217 deletions

View File

@ -49,18 +49,18 @@ final class FileResource: Item, LocalizedItem {
/// The dimensions of the image
var imageDimensions: CGSize? {
get { content.dimensions(of: id) }
get { content.dimensions(of: identifier) }
set {
content.cache(dimensions: newValue, of: id)
content.cache(dimensions: newValue, of: identifier)
didChange(save: false)
}
}
/// The size of the file in bytes
var fileSize: Int? {
get { content.size(of: id) }
get { content.size(of: identifier) }
set {
content.cache(size: newValue, of: id)
content.cache(size: newValue, of: identifier)
didChange(save: false)
}
}
@ -114,11 +114,11 @@ final class FileResource: Item, LocalizedItem {
// MARK: Text
func textContent() -> String {
content.storage.fileContent(for: id) ?? ""
content.storage.fileContent(for: identifier) ?? ""
}
func save(textContent: String) -> Bool {
guard content.storage.save(fileContent: textContent, for: id) else {
guard content.storage.save(fileContent: textContent, for: identifier) else {
return false
}
modifiedDate = .now
@ -126,7 +126,7 @@ final class FileResource: Item, LocalizedItem {
}
func dataContent() -> Foundation.Data? {
content.storage.fileData(for: id)
content.storage.fileData(for: identifier)
}
// MARK: Images
@ -165,7 +165,7 @@ final class FileResource: Item, LocalizedItem {
}
update(fileSize: displayImageData.count)
guard let loadedImage = NSImage(data: displayImageData) else {
print("Failed to create image \(id)")
print("Failed to create image \(identifier)")
return nil
}
update(imageDimensions: loadedImage.size)
@ -191,14 +191,14 @@ final class FileResource: Item, LocalizedItem {
private var displayImageData: Foundation.Data? {
if type.isImage {
guard let data = content.storage.fileData(for: id) else {
print("Failed to load data for image \(id)")
guard let data = content.storage.fileData(for: identifier) else {
print("Failed to load data for image \(identifier)")
return nil
}
return data
}
if type.isVideo {
return content.storage.getVideoThumbnail(for: id)
return content.storage.getVideoThumbnail(for: identifier)
}
return nil
}
@ -234,7 +234,7 @@ final class FileResource: Item, LocalizedItem {
func determineFileSize() {
DispatchQueue.global(qos: .userInitiated).async {
let size = self.content.storage.size(of: self.id)
let size = self.content.storage.size(of: self.identifier)
self.update(fileSize: size)
}
}
@ -249,7 +249,7 @@ final class FileResource: Item, LocalizedItem {
/// The path to the output folder where image versions are stored (no leading slash)
var outputImageFolder: String {
"\(content.settings.paths.imagesOutputFolderPath)/\(id.fileNameWithoutExtension)"
"\(content.settings.paths.imagesOutputFolderPath)/\(identifier.fileNameWithoutExtension)"
}
func outputPath(width: Int, height: Int, type: FileType?) -> String {
@ -293,9 +293,9 @@ final class FileResource: Item, LocalizedItem {
func createVideoThumbnail() {
guard type.isVideo else { return }
guard !content.storage.hasVideoThumbnail(for: id) else { return }
guard !content.storage.hasVideoThumbnail(for: identifier) else { return }
Task {
if await content.imageGenerator.createVideoThumbnail(for: id) {
if await content.imageGenerator.createVideoThumbnail(for: identifier) {
didChange()
}
}
@ -322,7 +322,7 @@ final class FileResource: Item, LocalizedItem {
return "/" + customOutputPath
}
}
let path = pathPrefix + "/" + id
let path = pathPrefix + "/" + identifier
return makeCleanAbsolutePath(path)
}
@ -353,14 +353,14 @@ final class FileResource: Item, LocalizedItem {
@discardableResult
func update(id newId: String) -> Bool {
guard !isExternallyStored else {
id = newId
identifier = newId
return true
}
guard content.storage.move(file: id, to: newId) else {
print("Failed to move file \(id) to \(newId)")
guard content.storage.move(file: identifier, to: newId) else {
print("Failed to move file \(identifier) to \(newId)")
return false
}
id = newId
identifier = newId
return true
}
}
@ -368,7 +368,7 @@ final class FileResource: Item, LocalizedItem {
extension FileResource: CustomStringConvertible {
var description: String {
id
identifier
}
}
@ -418,6 +418,6 @@ extension FileResource: StorageItem {
}
func saveToDisk(_ data: Data) -> Bool {
content.storage.save(fileResource: data, for: id)
content.storage.save(fileResource: data, for: identifier)
}
}