mirror of
https://github.com/cranci1/Sora.git
synced 2026-04-21 00:22:12 +00:00
test
Some checks are pending
Build and Release IPA / Build IPA and Mac Catalyst (push) Waiting to run
Some checks are pending
Build and Release IPA / Build IPA and Mac Catalyst (push) Waiting to run
This commit is contained in:
parent
dc3033b78c
commit
e8b3d09172
3 changed files with 40 additions and 26 deletions
Binary file not shown.
|
|
@ -55,6 +55,12 @@ struct EpisodeCell: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchEpisodeDetails() {
|
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 {
|
guard let url = URL(string: "https://api.ani.zip/mappings?anilist_id=\(itemID)") else {
|
||||||
isLoading = false
|
isLoading = false
|
||||||
return
|
return
|
||||||
|
|
@ -63,6 +69,7 @@ struct EpisodeCell: View {
|
||||||
URLSession.custom.dataTask(with: url) { data, response, error in
|
URLSession.custom.dataTask(with: url) { data, response, error in
|
||||||
if let error = error {
|
if let error = error {
|
||||||
print("Failed to fetch episode details: \(error)")
|
print("Failed to fetch episode details: \(error)")
|
||||||
|
Logger.shared.log("Failed to fetch episode details: \(error)")
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.isLoading = false
|
self.isLoading = false
|
||||||
}
|
}
|
||||||
|
|
@ -71,37 +78,45 @@ struct EpisodeCell: View {
|
||||||
|
|
||||||
guard let data = data else {
|
guard let data = data else {
|
||||||
print("No data received")
|
print("No data received")
|
||||||
|
Logger.shared.log("No data received")
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.isLoading = false
|
self.isLoading = false
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
UserDefaults.standard.set(data, forKey: cacheKey)
|
||||||
let jsonObject = try JSONSerialization.jsonObject(with: data, options: [])
|
self.parseEpisodeDetails(data: data)
|
||||||
guard let json = jsonObject as? [String: Any],
|
|
||||||
let episodes = json["episodes"] as? [String: Any],
|
|
||||||
let episodeDetails = episodes["\(episodeID + 1)"] as? [String: Any],
|
|
||||||
let title = episodeDetails["title"] as? [String: String],
|
|
||||||
let image = episodeDetails["image"] as? String else {
|
|
||||||
print("Invalid response format")
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
self.isLoading = false
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
self.episodeTitle = title["en"] ?? ""
|
|
||||||
self.episodeImageUrl = image
|
|
||||||
self.isLoading = false
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
print("Failed to parse JSON: \(error)")
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
self.isLoading = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.resume()
|
}.resume()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseEpisodeDetails(data: Data) {
|
||||||
|
do {
|
||||||
|
let jsonObject = try JSONSerialization.jsonObject(with: data, options: [])
|
||||||
|
guard let json = jsonObject as? [String: Any],
|
||||||
|
let episodes = json["episodes"] as? [String: Any],
|
||||||
|
let episodeDetails = episodes["\(episodeID + 1)"] as? [String: Any],
|
||||||
|
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
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.episodeTitle = title["en"] ?? ""
|
||||||
|
self.episodeImageUrl = image
|
||||||
|
self.isLoading = false
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
print("Failed to parse JSON: \(error)")
|
||||||
|
Logger.shared.log("Failed to parse JSON: \(error)")
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.isLoading = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ extension MediaView {
|
||||||
func fetchItemDetails() {
|
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 }
|
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
|
URLSession.custom.dataTask(with: url) { data, response, error in
|
||||||
defer { isLoading = false }
|
defer { isLoading = false }
|
||||||
guard let data = data, error == nil else { return }
|
guard let data = data, error == nil else { return }
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue