Improve storage
This commit is contained in:
@ -90,6 +90,8 @@ struct PageIssueView: View {
|
||||
return [.init(name: "Retry", action: retryPageCheck)]
|
||||
case .failedToLoadContent:
|
||||
return [.init(name: "Retry", action: retryPageCheck)]
|
||||
case .failedToParseContent:
|
||||
return [.init(name: "Retry", action: retryPageCheck)]
|
||||
case .missingFile(let missing, _):
|
||||
return [
|
||||
.init(name: "Select file", action: { selectFile(missingFile: missing) }),
|
||||
@ -284,23 +286,22 @@ struct PageIssueView: View {
|
||||
}
|
||||
|
||||
private func replace(_ oldString: String, with newString: String, in page: Page, language: ContentLanguage) {
|
||||
do {
|
||||
let pageContent = try content.storage.pageContent(for: page.id, language: language)
|
||||
.replacingOccurrences(of: oldString, with: newString)
|
||||
try content.storage.save(pageContent: pageContent, for: page.id, language: language)
|
||||
guard let pageContent = content.storage.pageContent(for: page.id, language: language) else {
|
||||
print("Failed to replace in page \(page.id) (\(language)), no content")
|
||||
return
|
||||
}
|
||||
let modified = pageContent.replacingOccurrences(of: oldString, with: newString)
|
||||
|
||||
guard content.storage.save(pageContent: modified, for: page.id, language: language) else {
|
||||
print("Replaced \(oldString) with \(newString) in page \(page.id) (\(language))")
|
||||
} catch {
|
||||
print("Failed to replace in page \(page.id) (\(language)): \(error)")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
private func findOccurrences(of searchString: String, in page: Page, language: ContentLanguage) -> [String] {
|
||||
let parts: [String]
|
||||
do {
|
||||
parts = try content.storage.pageContent(for: page.id, language: language)
|
||||
.components(separatedBy: searchString)
|
||||
} catch {
|
||||
print("Failed to get page content to find occurrences: \(error.localizedDescription)")
|
||||
guard let parts = content.storage.pageContent(for: page.id, language: language)?
|
||||
.components(separatedBy: searchString) else {
|
||||
print("Failed to get page content to find occurrences, no content")
|
||||
return []
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user