mirror of
https://github.com/cranci1/Sora.git
synced 2026-03-11 17:45:37 +00:00
test?
This commit is contained in:
parent
0daaf8027f
commit
26957de534
2 changed files with 28 additions and 49 deletions
|
|
@ -78,10 +78,12 @@ extension JSContext {
|
|||
}
|
||||
|
||||
func setupFetchV2() {
|
||||
let fetchV2NativeFunction: @convention(block) (String, [String: String]?, String?, String?, ObjCBool,JSValue, JSValue) -> Void = { urlString, headers, method, body, redirect, resolve, reject in
|
||||
let fetchV2NativeFunction: @convention(block) (String, [String: String]?, String?, String?, ObjCBool, JSValue, JSValue) -> Void = { urlString, headers, method, body, redirect, resolve, reject in
|
||||
guard let url = URL(string: urlString) else {
|
||||
Logger.shared.log("Invalid URL", type: "Error")
|
||||
reject.call(withArguments: ["Invalid URL"])
|
||||
DispatchQueue.main.async {
|
||||
reject.call(withArguments: ["Invalid URL"])
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -93,7 +95,9 @@ extension JSContext {
|
|||
|
||||
if httpMethod == "GET", let body = body, !body.isEmpty, body != "null", body != "undefined" {
|
||||
Logger.shared.log("GET request must not have a body", type: "Error")
|
||||
reject.call(withArguments: ["GET request must not have a body"])
|
||||
DispatchQueue.main.async {
|
||||
reject.call(withArguments: ["GET request must not have a body"])
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -101,27 +105,33 @@ extension JSContext {
|
|||
request.httpBody = body.data(using: .utf8)
|
||||
}
|
||||
|
||||
|
||||
if let headers = headers {
|
||||
for (key, value) in headers {
|
||||
request.setValue(value, forHTTPHeaderField: key)
|
||||
}
|
||||
}
|
||||
Logger.shared.log("Redirect value is \(redirect.boolValue)",type:"Error")
|
||||
Logger.shared.log("Redirect value is \(redirect.boolValue)", type: "Error")
|
||||
let task = URLSession.fetchData(allowRedirects: redirect.boolValue).downloadTask(with: request) { tempFileURL, response, error in
|
||||
let callReject: (String) -> Void = { message in
|
||||
DispatchQueue.main.async {
|
||||
reject.call(withArguments: [message])
|
||||
}
|
||||
}
|
||||
let callResolve: ([String: Any]) -> Void = { dict in
|
||||
DispatchQueue.main.async {
|
||||
resolve.call(withArguments: [dict])
|
||||
}
|
||||
}
|
||||
|
||||
if let error = error {
|
||||
Logger.shared.log("Network error in fetchV2NativeFunction: \(error.localizedDescription)", type: "Error")
|
||||
DispatchQueue.main.async {
|
||||
reject.call(withArguments: [error.localizedDescription])
|
||||
}
|
||||
callReject(error.localizedDescription)
|
||||
return
|
||||
}
|
||||
|
||||
guard let tempFileURL = tempFileURL else {
|
||||
Logger.shared.log("No data in response", type: "Error")
|
||||
DispatchQueue.main.async {
|
||||
reject.call(withArguments: ["No data"])
|
||||
}
|
||||
callReject("No data")
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -146,29 +156,21 @@ extension JSContext {
|
|||
|
||||
if data.count > 10_000_000 {
|
||||
Logger.shared.log("Response exceeds maximum size", type: "Error")
|
||||
DispatchQueue.main.async {
|
||||
reject.call(withArguments: ["Response exceeds maximum size"])
|
||||
}
|
||||
callReject("Response exceeds maximum size")
|
||||
return
|
||||
}
|
||||
|
||||
if let text = String(data: data, encoding: .utf8) {
|
||||
responseDict["body"] = text
|
||||
DispatchQueue.main.async {
|
||||
resolve.call(withArguments: [responseDict])
|
||||
}
|
||||
callResolve(responseDict)
|
||||
} else {
|
||||
Logger.shared.log("Unable to decode data to text", type: "Error")
|
||||
DispatchQueue.main.async {
|
||||
resolve.call(withArguments: [responseDict])
|
||||
}
|
||||
callResolve(responseDict)
|
||||
}
|
||||
|
||||
} catch {
|
||||
Logger.shared.log("Error reading downloaded file: \(error.localizedDescription)", type: "Error")
|
||||
DispatchQueue.main.async {
|
||||
reject.call(withArguments: ["Error reading downloaded file"])
|
||||
}
|
||||
callReject("Error reading downloaded file")
|
||||
}
|
||||
}
|
||||
task.resume()
|
||||
|
|
|
|||
|
|
@ -584,32 +584,9 @@ struct MediaInfoView: View {
|
|||
private var playAndBookmarkSection: some View {
|
||||
HStack(spacing: 12) {
|
||||
ZStack(alignment: .leading) {
|
||||
GeometryReader { geometry in
|
||||
let width = geometry.size.width
|
||||
let progress = latestProgress
|
||||
|
||||
RoundedRectangle(cornerRadius: 25)
|
||||
.fill(Color.accentColor.opacity(0.25))
|
||||
.frame(width: width, height: 48)
|
||||
|
||||
if progress < 0.9 {
|
||||
Capsule()
|
||||
.fill(Color.accentColor)
|
||||
.frame(width: max(width * CGFloat(progress), 8), height: 48)
|
||||
.mask(
|
||||
HStack {
|
||||
if progress < 0.05 && progress != 0 {
|
||||
RoundedRectangle(cornerRadius: 24)
|
||||
.frame(width: 8)
|
||||
} else {
|
||||
RoundedRectangle(cornerRadius: 24)
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
.frame(height: 48)
|
||||
RoundedRectangle(cornerRadius: 25)
|
||||
.fill(Color.accentColor.opacity(0.25))
|
||||
.frame(width: width, height: 48)
|
||||
|
||||
Button(action: {
|
||||
playFirstUnwatchedEpisode()
|
||||
|
|
|
|||
Loading…
Reference in a new issue