mirror of
https://github.com/cranci1/Sora.git
synced 2026-04-19 07:32:08 +00:00
uh?
This commit is contained in:
parent
253383516d
commit
a84bdf6a58
6 changed files with 18 additions and 74 deletions
|
|
@ -92,11 +92,12 @@
|
|||
133D7C7B2D2BE2630075467E /* Views */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
133D7C812D2BE2630075467E /* SettingsView */,
|
||||
133D7C832D2BE2630075467E /* SettingsSubViews */,
|
||||
133D7C7F2D2BE2630075467E /* MediaInfoView */,
|
||||
133D7C7C2D2BE2630075467E /* SearchView.swift */,
|
||||
133D7C7D2D2BE2630075467E /* HomeView.swift */,
|
||||
133D7C7E2D2BE2630075467E /* LibraryView.swift */,
|
||||
133D7C7C2D2BE2630075467E /* SearchView.swift */,
|
||||
133D7C822D2BE2630075467E /* SettingsView.swift */,
|
||||
);
|
||||
path = Views;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -109,21 +110,12 @@
|
|||
path = MediaInfoView;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
133D7C812D2BE2630075467E /* SettingsView */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
133D7C822D2BE2630075467E /* SettingsView.swift */,
|
||||
133D7C832D2BE2630075467E /* SubViews */,
|
||||
);
|
||||
path = SettingsView;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
133D7C832D2BE2630075467E /* SubViews */ = {
|
||||
133D7C832D2BE2630075467E /* SettingsSubViews */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
133D7C842D2BE2630075467E /* SettingsViewModule.swift */,
|
||||
);
|
||||
path = SubViews;
|
||||
path = SettingsSubViews;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
133D7C852D2BE2640075467E /* Utils */ = {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class JSController: ObservableObject {
|
|||
context.evaluateScript(script)
|
||||
}
|
||||
|
||||
func fetchSearchResults(keyword: String, module: ScrapingModule, completion: @escaping ([MediaItem]) -> Void) {
|
||||
func fetchSearchResults(keyword: String, module: ScrapingModule, completion: @escaping ([SearchItem]) -> Void) {
|
||||
let searchUrl = module.metadata.searchBaseUrl.replacingOccurrences(of: "%s", with: keyword.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? "")
|
||||
|
||||
guard let url = URL(string: searchUrl) else {
|
||||
|
|
@ -53,55 +53,15 @@ class JSController: ObservableObject {
|
|||
|
||||
if let parseFunction = self.context.objectForKeyedSubscript("searchResults"),
|
||||
let results = parseFunction.call(withArguments: [html]).toArray() as? [[String: String]] {
|
||||
let mediaItems = results.map { item in
|
||||
MediaItem(
|
||||
let resultItems = results.map { item in
|
||||
SearchItem(
|
||||
title: item["title"] ?? "",
|
||||
imageUrl: item["image"] ?? "",
|
||||
href: item["href"] ?? ""
|
||||
)
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
completion(mediaItems)
|
||||
}
|
||||
} else {
|
||||
print("Failed to parse results")
|
||||
DispatchQueue.main.async { completion([]) }
|
||||
}
|
||||
}.resume()
|
||||
}
|
||||
|
||||
func fetchInfoContent(href: String, module: ScrapingModule, completion: @escaping ([MediaItem]) -> Void) {
|
||||
guard let url = URL(string: href) else {
|
||||
completion([])
|
||||
return
|
||||
}
|
||||
|
||||
URLSession.custom.dataTask(with: url) { [weak self] data, response, error in
|
||||
guard let self = self else { return }
|
||||
|
||||
if let error = error {
|
||||
print("Network error: \(error)")
|
||||
DispatchQueue.main.async { completion([]) }
|
||||
return
|
||||
}
|
||||
|
||||
guard let data = data, let html = String(data: data, encoding: .utf8) else {
|
||||
print("Failed to decode HTML")
|
||||
DispatchQueue.main.async { completion([]) }
|
||||
return
|
||||
}
|
||||
|
||||
if let parseFunction = self.context.objectForKeyedSubscript("fetchInfo"),
|
||||
let results = parseFunction.call(withArguments: [html]).toArray() as? [[String: String]] {
|
||||
let mediaItems = results.map { item in
|
||||
MediaItem(
|
||||
title: item["title"] ?? "",
|
||||
imageUrl: item["image"] ?? "",
|
||||
href: item["href"] ?? ""
|
||||
)
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
completion(mediaItems)
|
||||
completion(resultItems)
|
||||
}
|
||||
} else {
|
||||
print("Failed to parse results")
|
||||
|
|
|
|||
|
|
@ -27,15 +27,7 @@ struct MediaInfoView: View {
|
|||
.padding()
|
||||
|
||||
Button(action: {
|
||||
var finalHref = href
|
||||
if !href.starts(with: "http") {
|
||||
var baseUrl = module.metadata.baseUrl
|
||||
if !baseUrl.hasSuffix("/") && !href.hasPrefix("/") {
|
||||
baseUrl += "/"
|
||||
}
|
||||
finalHref = baseUrl + href
|
||||
}
|
||||
if let url = URL(string: finalHref) {
|
||||
if let url = URL(string: href) {
|
||||
UIApplication.shared.open(url)
|
||||
}
|
||||
}) {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
import SwiftUI
|
||||
import Kingfisher
|
||||
|
||||
struct MediaItem: Identifiable {
|
||||
struct SearchItem: Identifiable {
|
||||
let id = UUID()
|
||||
let title: String
|
||||
let imageUrl: String
|
||||
|
|
@ -20,8 +20,8 @@ struct SearchView: View {
|
|||
@StateObject private var jsController = JSController()
|
||||
@EnvironmentObject var moduleManager: ModuleManager
|
||||
|
||||
@State private var mediaItems: [MediaItem] = []
|
||||
@State private var selectedMediaItem: MediaItem?
|
||||
@State private var searchItems: [SearchItem] = []
|
||||
@State private var selectedSearchItem: SearchItem?
|
||||
@State private var isSearching = false
|
||||
@State private var searchText = ""
|
||||
|
||||
|
|
@ -58,7 +58,7 @@ struct SearchView: View {
|
|||
}
|
||||
|
||||
LazyVGrid(columns: [GridItem(.adaptive(minimum: 150))], spacing: 16) {
|
||||
ForEach(mediaItems) { item in
|
||||
ForEach(searchItems) { item in
|
||||
VStack {
|
||||
KFImage(URL(string: item.imageUrl))
|
||||
.resizable()
|
||||
|
|
@ -73,7 +73,7 @@ struct SearchView: View {
|
|||
.lineLimit(1)
|
||||
}
|
||||
.onTapGesture {
|
||||
selectedMediaItem = item
|
||||
selectedSearchItem = item
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -117,7 +117,7 @@ struct SearchView: View {
|
|||
}
|
||||
}
|
||||
}
|
||||
.sheet(item: $selectedMediaItem) { item in
|
||||
.sheet(item: $selectedSearchItem) { item in
|
||||
MediaInfoView(title: item.title, imageUrl: item.imageUrl, href: item.href, module: selectedModule!)
|
||||
}
|
||||
}
|
||||
|
|
@ -131,7 +131,7 @@ struct SearchView: View {
|
|||
|
||||
private func performSearch() {
|
||||
guard !searchText.isEmpty, let module = selectedModule else {
|
||||
mediaItems = []
|
||||
searchItems = []
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -142,7 +142,7 @@ struct SearchView: View {
|
|||
let jsContent = try moduleManager.getModuleContent(module)
|
||||
jsController.loadScript(jsContent)
|
||||
jsController.fetchSearchResults(keyword: searchText, module: module) { items in
|
||||
mediaItems = items
|
||||
searchItems = items
|
||||
isSearching = false
|
||||
}
|
||||
} catch {
|
||||
|
|
|
|||
Loading…
Reference in a new issue