test
Some checks are pending
Build and Release IPA / Build IPA and Mac Catalyst (push) Waiting to run

This commit is contained in:
cranci1 2024-12-30 15:32:33 +01:00
parent dc3033b78c
commit e8b3d09172
3 changed files with 40 additions and 26 deletions

View file

@ -55,6 +55,12 @@ struct EpisodeCell: View {
}
func fetchEpisodeDetails() {
let cacheKey = "episodeDetails_\(itemID)_\(episodeID)"
if let cachedData = UserDefaults.standard.data(forKey: cacheKey) {
parseEpisodeDetails(data: cachedData)
}
guard let url = URL(string: "https://api.ani.zip/mappings?anilist_id=\(itemID)") else {
isLoading = false
return
@ -63,6 +69,7 @@ struct EpisodeCell: View {
URLSession.custom.dataTask(with: url) { data, response, error in
if let error = error {
print("Failed to fetch episode details: \(error)")
Logger.shared.log("Failed to fetch episode details: \(error)")
DispatchQueue.main.async {
self.isLoading = false
}
@ -71,12 +78,19 @@ struct EpisodeCell: View {
guard let data = data else {
print("No data received")
Logger.shared.log("No data received")
DispatchQueue.main.async {
self.isLoading = false
}
return
}
UserDefaults.standard.set(data, forKey: cacheKey)
self.parseEpisodeDetails(data: data)
}.resume()
}
func parseEpisodeDetails(data: Data) {
do {
let jsonObject = try JSONSerialization.jsonObject(with: data, options: [])
guard let json = jsonObject as? [String: Any],
@ -85,6 +99,7 @@ struct EpisodeCell: View {
let title = episodeDetails["title"] as? [String: String],
let image = episodeDetails["image"] as? String else {
print("Invalid response format")
Logger.shared.log("Invalid response format")
DispatchQueue.main.async {
self.isLoading = false
}
@ -98,10 +113,10 @@ struct EpisodeCell: View {
}
} catch {
print("Failed to parse JSON: \(error)")
Logger.shared.log("Failed to parse JSON: \(error)")
DispatchQueue.main.async {
self.isLoading = false
}
}
}.resume()
}
}

View file

@ -12,7 +12,6 @@ extension MediaView {
func fetchItemDetails() {
guard let url = URL(string: item.href.hasPrefix("https") ? item.href : "\(module.module[0].details.baseURL.hasSuffix("/") ? module.module[0].details.baseURL : "\(module.module[0].details.baseURL)/")\(item.href.hasPrefix("/") ? String(item.href.dropFirst()) : item.href)") else { return }
print(url)
URLSession.custom.dataTask(with: url) { data, response, error in
defer { isLoading = false }
guard let data = data, error == nil else { return }