Adds support for website APIs both complex and simple. This commit only supports GET requests to APIs. POST request support can be added on request. Client IDs and secrets are also supported. They can be added via source settings or automatically set by a website endpoint. Also fetch sources for scraping using the backgroundContext and remove some functions from using the main actor. Signed-off-by: kingbri <bdashore3@gmail.com>
120 lines
5 KiB
Swift
120 lines
5 KiB
Swift
//
|
|
// MagnetChoiceView.swift
|
|
// Ferrite
|
|
//
|
|
// Created by Brian Dashore on 7/20/22.
|
|
//
|
|
|
|
import SwiftUI
|
|
import SwiftUIX
|
|
|
|
struct MagnetChoiceView: View {
|
|
@Environment(\.presentationMode) var presentationMode
|
|
|
|
@EnvironmentObject var scrapingModel: ScrapingViewModel
|
|
@EnvironmentObject var debridManager: DebridManager
|
|
@EnvironmentObject var navModel: NavigationViewModel
|
|
|
|
@AppStorage("RealDebrid.Enabled") var realDebridEnabled = false
|
|
|
|
@State private var showActivityView = false
|
|
@State private var showLinkCopyAlert = false
|
|
@State private var showMagnetCopyAlert = false
|
|
@State private var activityItems: [Any] = []
|
|
|
|
var body: some View {
|
|
NavView {
|
|
Form {
|
|
if realDebridEnabled, debridManager.matchSearchResult(result: scrapingModel.selectedSearchResult) != .none {
|
|
Section(header: "Real Debrid options") {
|
|
ListRowButtonView("Play on Outplayer", systemImage: "arrow.up.forward.app.fill") {
|
|
navModel.runDebridAction(action: .outplayer, urlString: debridManager.realDebridDownloadUrl)
|
|
}
|
|
|
|
ListRowButtonView("Play on VLC", systemImage: "arrow.up.forward.app.fill") {
|
|
navModel.runDebridAction(action: .vlc, urlString: debridManager.realDebridDownloadUrl)
|
|
}
|
|
|
|
ListRowButtonView("Play on Infuse", systemImage: "arrow.up.forward.app.fill") {
|
|
navModel.runDebridAction(action: .infuse, urlString: debridManager.realDebridDownloadUrl)
|
|
}
|
|
|
|
ListRowButtonView("Copy download URL", systemImage: "doc.on.doc.fill") {
|
|
UIPasteboard.general.string = debridManager.realDebridDownloadUrl
|
|
showLinkCopyAlert.toggle()
|
|
}
|
|
.alert(isPresented: $showLinkCopyAlert) {
|
|
Alert(
|
|
title: Text("Copied"),
|
|
message: Text("Download link copied successfully"),
|
|
dismissButton: .cancel(Text("OK"))
|
|
)
|
|
}
|
|
|
|
ListRowButtonView("Share download URL", systemImage: "square.and.arrow.up.fill") {
|
|
if let url = URL(string: debridManager.realDebridDownloadUrl) {
|
|
activityItems = [url]
|
|
navModel.showActivityView.toggle()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Section(header: "Magnet options") {
|
|
ListRowButtonView("Copy magnet", systemImage: "doc.on.doc.fill") {
|
|
UIPasteboard.general.string = scrapingModel.selectedSearchResult?.magnetLink
|
|
showMagnetCopyAlert.toggle()
|
|
}
|
|
.alert(isPresented: $showMagnetCopyAlert) {
|
|
Alert(
|
|
title: Text("Copied"),
|
|
message: Text("Magnet link copied successfully"),
|
|
dismissButton: .cancel(Text("OK"))
|
|
)
|
|
}
|
|
|
|
ListRowButtonView("Share magnet", systemImage: "square.and.arrow.up.fill") {
|
|
if let result = scrapingModel.selectedSearchResult,
|
|
let magnetLink = result.magnetLink,
|
|
let url = URL(string: magnetLink)
|
|
{
|
|
activityItems = [url]
|
|
navModel.showActivityView.toggle()
|
|
}
|
|
}
|
|
|
|
ListRowButtonView("Open in WebTor", systemImage: "arrow.up.forward.app.fill") {
|
|
if let result = scrapingModel.selectedSearchResult {
|
|
navModel.runMagnetAction(action: .webtor, searchResult: result)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.sheet(isPresented: $navModel.showActivityView) {
|
|
if #available(iOS 16, *) {
|
|
AppActivityView(activityItems: activityItems)
|
|
.presentationDetents([.medium])
|
|
} else {
|
|
AppActivityView(activityItems: activityItems)
|
|
}
|
|
}
|
|
.navigationTitle("Link actions")
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.toolbar {
|
|
ToolbarItem(placement: .navigationBarTrailing) {
|
|
Button("Done") {
|
|
debridManager.realDebridDownloadUrl = ""
|
|
|
|
presentationMode.wrappedValue.dismiss()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct MagnetChoiceView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
MagnetChoiceView()
|
|
}
|
|
}
|