Generate tag overview, add file action

This commit is contained in:
Christoph Hagen
2025-01-05 09:21:21 +01:00
parent 0dca633805
commit 01baf560ee
27 changed files with 501 additions and 137 deletions

View File

@ -28,6 +28,8 @@ struct LocalizedTagFile {
let description: String?
let linkPreviewTitle: String?
/// The image id of the thumbnail
let thumbnail: String?

View File

@ -1,4 +1,5 @@
import Foundation
import AppKit
struct SecurityBookmark {
@ -28,6 +29,14 @@ struct SecurityBookmark {
// MARK: Write
func openFinderWindow(relativePath: String) {
with(relativePath: relativePath) { path in
print("Opening file at \(path)")
NSWorkspace.shared.activateFileViewerSelecting([path])
return
}
}
func fullPath(to relativePath: String) -> URL {
url.appending(path: relativePath, directoryHint: .notDirectory)
}
@ -103,6 +112,10 @@ struct SecurityBookmark {
// MARK: Read
func size(of relativePath: String) -> Int? {
with(relativePath: relativePath) { $0.size }
}
func hasFile(at relativePath: String) -> Bool {
with(relativePath: relativePath, perform: exists)
}
@ -212,6 +225,7 @@ struct SecurityBookmark {
func deleteFile(at relativePath: String) -> Bool {
with(relativePath: relativePath) { file in
guard exists(file) else {
print("Scope: No file to delete at \(file.path())")
return true
}
do {

View File

@ -183,13 +183,13 @@ final class Storage: ObservableObject {
tagId + ".json"
}
private func tagFilePath(tagId: String) -> String {
private func tagFilePath(tag tagId: String) -> String {
tagsFolderName + "/" + tagFileName(tagId: tagId)
}
func save(tagMetadata: TagFile, for tagId: String) -> Bool {
guard let contentScope else { return false }
let path = tagFilePath(tagId: tagId)
let path = tagFilePath(tag: tagId)
return contentScope.encode(tagMetadata, to: path)
}
@ -211,6 +211,11 @@ final class Storage: ObservableObject {
return true
}
func move(tag tagId: String, to newId: String) -> Bool {
guard let contentScope else { return false }
return contentScope.move(tagFilePath(tag: tagId), to: tagFilePath(tag: newId))
}
// MARK: File descriptions
func loadFileDescriptions() -> [FileDescriptions]? {
@ -235,6 +240,10 @@ final class Storage: ObservableObject {
// MARK: Files
func size(of file: String) -> Int? {
contentScope?.size(of: filePath(file: file))
}
/**
The full path to a resource file in the content folder
- Parameter file: The filename of the file
@ -244,6 +253,16 @@ final class Storage: ObservableObject {
contentScope?.fullPath(to: filePath(file: file))
}
/**
Delete a file resource from the content folder
*/
func delete(file fileId: String) -> Bool {
guard let contentScope else {
return false
}
return contentScope.deleteFile(at: filePath(file: fileId))
}
/**
The full file path to a file in the output folder
- Parameter relativePath: The path of the file relative to the output folder
@ -252,10 +271,20 @@ final class Storage: ObservableObject {
outputScope?.fullPath(to: relativePath)
}
func openFinderWindow(withSelectedFile file: String) {
contentScope?.openFinderWindow(relativePath: filePath(file: file))
}
private func filePath(file fileId: String) -> String {
filesFolderName + "/" + fileId
}
@discardableResult
func deleteInOutputFolder(path: String) -> Bool {
guard let outputScope else { return false }
return outputScope.deleteFile(at: path)
}
/**
Copy an external file to the content folder
*/
@ -264,11 +293,17 @@ final class Storage: ObservableObject {
return contentScope.copy(externalFile: url, to: filePath(file: fileId))
}
/**
Move (rename) a file resource.
*/
func move(file fileId: String, to newId: String) -> Bool {
guard let contentScope else { return false }
return contentScope.move(filePath(file: fileId), to: filePath(file: newId))
}
/**
Copy a file resource to a path relative to the output folder
*/
func copy(file fileId: String, to relativeOutputPath: String) -> Bool {
guard let contentScope, let outputScope else { return false }
return contentScope.transfer(