Improve tag and images view, save website settings
This commit is contained in:
@ -242,8 +242,26 @@ final class Storage {
|
||||
try fileNames(in: videosFolder)
|
||||
}
|
||||
|
||||
// MARK: Website data
|
||||
|
||||
private var websiteDataUrl: URL {
|
||||
baseFolder.appending(path: "website-data.json", directoryHint: .notDirectory)
|
||||
}
|
||||
|
||||
func loadWebsiteData() throws -> WebsiteDataFile {
|
||||
try read(at: websiteDataUrl)
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
func save(websiteData: WebsiteDataFile) -> Bool {
|
||||
write(websiteData, type: "Website Data", id: "-", to: websiteDataUrl)
|
||||
}
|
||||
|
||||
// MARK: Writing files
|
||||
|
||||
/**
|
||||
Encode a value and write it to a file, if the content changed
|
||||
*/
|
||||
private func write<T>(_ value: T, type: String, id: String, to file: URL) -> Bool where T: Encodable {
|
||||
let content: Data
|
||||
do {
|
||||
@ -255,6 +273,9 @@ final class Storage {
|
||||
return write(data: content, type: type, id: id, to: file)
|
||||
}
|
||||
|
||||
/**
|
||||
Write data to a file if the content changed
|
||||
*/
|
||||
private func write(data: Data, type: String, id: String, to file: URL) -> Bool {
|
||||
if fm.fileExists(atPath: file.path()) {
|
||||
// Check if content is the same, to prevent unnecessary writes
|
||||
|
Reference in New Issue
Block a user