Save automatically, improve mocks
This commit is contained in:
@ -43,6 +43,8 @@ final class Storage: ObservableObject {
|
||||
@Published
|
||||
var outputScope: SecurityBookmark?
|
||||
|
||||
var errorNotification: StorageErrorCallback?
|
||||
|
||||
/**
|
||||
Create the storage.
|
||||
*/
|
||||
@ -75,10 +77,10 @@ final class Storage: ObservableObject {
|
||||
return contentScope.write(pageContent, to: path)
|
||||
}
|
||||
|
||||
func save(pageMetadata: Page.Data, for pageId: String) -> Bool {
|
||||
func save(page: Page.Data, for pageId: String) -> Bool {
|
||||
guard let contentScope else { return false }
|
||||
let path = pageMetadataPath(page: pageId)
|
||||
return contentScope.encode(pageMetadata, to: path)
|
||||
return contentScope.encode(page, to: path)
|
||||
}
|
||||
|
||||
func loadAllPages() -> [String : Page.Data]? {
|
||||
@ -186,10 +188,10 @@ final class Storage: ObservableObject {
|
||||
tagsFolderName + "/" + tagFileName(tagId: tagId)
|
||||
}
|
||||
|
||||
func save(tagMetadata: Tag.Data, for tagId: String) -> Bool {
|
||||
func save(tag: Tag.Data, for tagId: String) -> Bool {
|
||||
guard let contentScope else { return false }
|
||||
let path = tagFilePath(tag: tagId)
|
||||
return contentScope.encode(tagMetadata, to: path)
|
||||
return contentScope.encode(tag, to: path)
|
||||
}
|
||||
|
||||
func loadAllTags() -> [String : Tag.Data]? {
|
||||
@ -338,10 +340,10 @@ final class Storage: ObservableObject {
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
func save(fileInfo: FileResource.Data, for fileId: String) -> Bool {
|
||||
func save(fileResource: FileResource.Data, for fileId: String) -> Bool {
|
||||
guard let contentScope else { return false }
|
||||
let path = fileInfoPath(file: fileId)
|
||||
return contentScope.encode(fileInfo, to: path)
|
||||
return contentScope.encode(fileResource, to: path)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -503,6 +505,10 @@ final class Storage: ObservableObject {
|
||||
return false
|
||||
}
|
||||
contentScope = decode(bookmark: bookmarkData)
|
||||
// Propagate errors
|
||||
contentScope?.errorNotification = { [weak self] error in
|
||||
self?.errorNotification?(error)
|
||||
}
|
||||
return contentScope != nil
|
||||
}
|
||||
|
||||
@ -513,6 +519,10 @@ final class Storage: ObservableObject {
|
||||
return false
|
||||
}
|
||||
outputScope = decode(bookmark: data)
|
||||
// Propagate errors
|
||||
outputScope?.errorNotification = { [weak self] error in
|
||||
self?.errorNotification?(error)
|
||||
}
|
||||
return outputScope != nil
|
||||
}
|
||||
|
||||
@ -562,6 +572,10 @@ final class Storage: ObservableObject {
|
||||
}
|
||||
// TODO: Check if stale
|
||||
outputScope = SecurityBookmark(url: outputPath, isStale: false)
|
||||
// Propagate errors
|
||||
outputScope?.errorNotification = { [weak self] error in
|
||||
self?.errorNotification?(error)
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user