mirror of
https://github.com/cranci1/Sora.git
synced 2026-04-20 08:02:16 +00:00
added duplicate module prevention
This commit is contained in:
parent
24793e1310
commit
e74b9d8c78
2 changed files with 11 additions and 4 deletions
|
|
@ -42,6 +42,10 @@ class ModuleManager: ObservableObject {
|
|||
throw NSError(domain: "Invalid metadata URL", code: -1)
|
||||
}
|
||||
|
||||
if modules.contains(where: { $0.metadataUrl == metadataUrl }) {
|
||||
throw NSError(domain: "Module already exists", code: -1)
|
||||
}
|
||||
|
||||
let (metadataData, _) = try await URLSession.custom.data(from: url)
|
||||
let metadata = try JSONDecoder().decode(ModuleMetadata.self, from: metadataData)
|
||||
|
||||
|
|
@ -72,7 +76,7 @@ class ModuleManager: ObservableObject {
|
|||
|
||||
return module
|
||||
}
|
||||
|
||||
|
||||
func deleteModule(_ module: ScrapingModule) {
|
||||
let localUrl = getDocumentsDirectory().appendingPathComponent(module.localPath)
|
||||
try? fileManager.removeItem(at: localUrl)
|
||||
|
|
@ -81,10 +85,9 @@ class ModuleManager: ObservableObject {
|
|||
saveModules()
|
||||
Logger.shared.log("Deleted module: \(module.metadata.sourceName)")
|
||||
}
|
||||
|
||||
|
||||
func getModuleContent(_ module: ScrapingModule) throws -> String {
|
||||
let localUrl = getDocumentsDirectory().appendingPathComponent(module.localPath)
|
||||
return try String(contentsOf: localUrl, encoding: .utf8)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -153,7 +153,11 @@ struct SettingsViewModule: View {
|
|||
} catch {
|
||||
DispatchQueue.main.async {
|
||||
isLoading = false
|
||||
errorMessage = "Failed to add module: \(error.localizedDescription)"
|
||||
if (error as NSError).domain == "Module already exists" {
|
||||
errorMessage = "Module already exists"
|
||||
} else {
|
||||
errorMessage = "Failed to add module: \(error.localizedDescription)"
|
||||
}
|
||||
Logger.shared.log("Failed to add module: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue