Improve tag and images view, save website settings

This commit is contained in:
Christoph Hagen
2024-12-02 13:08:52 +01:00
parent 1261ea534b
commit 4440b2ce0d
22 changed files with 576 additions and 144 deletions

View File

@ -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