handled some warnings
This commit is contained in:
44
src/db.rs
44
src/db.rs
@@ -1,8 +1,10 @@
|
||||
use diesel::prelude::*;
|
||||
use crate::models::DBVideo;
|
||||
use diesel::prelude::*;
|
||||
|
||||
|
||||
pub fn get_video(conn: &mut SqliteConnection, video_id: String) -> Result<Option<String>, diesel::result::Error> {
|
||||
pub fn get_video(
|
||||
conn: &mut SqliteConnection,
|
||||
video_id: String,
|
||||
) -> Result<Option<String>, diesel::result::Error> {
|
||||
use crate::schema::videos::dsl::*;
|
||||
let result = videos
|
||||
.filter(id.eq(video_id))
|
||||
@@ -14,38 +16,54 @@ pub fn get_video(conn: &mut SqliteConnection, video_id: String) -> Result<Option
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn insert_video(conn: &mut SqliteConnection, new_id: &str, new_url: &str) -> Result<usize, diesel::result::Error> {
|
||||
pub fn insert_video(
|
||||
conn: &mut SqliteConnection,
|
||||
new_id: &str,
|
||||
new_url: &str,
|
||||
) -> Result<usize, diesel::result::Error> {
|
||||
use crate::schema::videos::dsl::*;
|
||||
diesel::insert_into(videos).values(DBVideo{
|
||||
diesel::insert_into(videos)
|
||||
.values(DBVideo {
|
||||
id: new_id.to_string(),
|
||||
url: new_url.to_string(),
|
||||
}).execute(conn)
|
||||
})
|
||||
.execute(conn)
|
||||
}
|
||||
|
||||
pub fn delete_video(conn: &mut SqliteConnection, video_id: String) -> Result<usize, diesel::result::Error> {
|
||||
pub fn delete_video(
|
||||
conn: &mut SqliteConnection,
|
||||
video_id: String,
|
||||
) -> Result<usize, diesel::result::Error> {
|
||||
use crate::schema::videos::dsl::*;
|
||||
diesel::delete(videos.filter(id.eq(video_id))).execute(conn)
|
||||
}
|
||||
|
||||
pub fn has_table(conn: &mut SqliteConnection, table_name: &str) -> Result<bool, diesel::result::Error> {
|
||||
pub fn has_table(
|
||||
conn: &mut SqliteConnection,
|
||||
table_name: &str,
|
||||
) -> Result<bool, diesel::result::Error> {
|
||||
use diesel::sql_query;
|
||||
use diesel::sql_types::Text;
|
||||
#[derive(QueryableByName)]
|
||||
struct TableName {
|
||||
#[sql_type = "Text"]
|
||||
#[column_name = "name"]
|
||||
name: String,
|
||||
}
|
||||
|
||||
let query = "SELECT name FROM sqlite_master WHERE type='table' AND name = ?1";
|
||||
let result = sql_query(query)
|
||||
let rows = sql_query(query)
|
||||
.bind::<Text, _>(table_name)
|
||||
.load::<TableName>(conn)?;
|
||||
Ok(!result.is_empty())
|
||||
let exists = rows.first().map(|r| !r.name.is_empty()).unwrap_or(false);
|
||||
Ok(exists)
|
||||
}
|
||||
|
||||
pub fn create_table(conn: &mut SqliteConnection, create_sql: &str) -> Result<(), diesel::result::Error> {
|
||||
pub fn create_table(
|
||||
conn: &mut SqliteConnection,
|
||||
create_sql: &str,
|
||||
) -> Result<(), diesel::result::Error> {
|
||||
use diesel::sql_query;
|
||||
sql_query(create_sql).execute(conn)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@ mod proxies;
|
||||
|
||||
type DbPool = r2d2::Pool<ConnectionManager<SqliteConnection>>;
|
||||
|
||||
#[macro_use(c)]
|
||||
extern crate cute;
|
||||
// #[macro_use(c)]
|
||||
// extern crate cute;
|
||||
|
||||
|
||||
#[ntex::main]
|
||||
|
||||
@@ -8,7 +8,7 @@ use error_chain::error_chain;
|
||||
use htmlentity::entity::{ICodedDataTrait, decode};
|
||||
use std::env;
|
||||
use std::vec;
|
||||
use wreq::{Client, Proxy};
|
||||
use wreq::{Client};
|
||||
use wreq_util::Emulation;
|
||||
|
||||
error_chain! {
|
||||
@@ -54,7 +54,7 @@ impl HomoxxxProvider {
|
||||
}
|
||||
};
|
||||
|
||||
let proxy = Proxy::all("http://192.168.0.103:8081").unwrap();
|
||||
// let proxy = Proxy::all("http://192.168.0.103:8081").unwrap();
|
||||
let client = Client::builder().cert_verification(false).emulation(Emulation::Firefox136).build()?;
|
||||
|
||||
let mut response = client.get(video_url.clone())
|
||||
@@ -133,7 +133,7 @@ impl HomoxxxProvider {
|
||||
}
|
||||
};
|
||||
|
||||
let proxy = Proxy::all("http://192.168.0.103:8081").unwrap();
|
||||
// let proxy = Proxy::all("http://192.168.0.103:8081").unwrap();
|
||||
let client = Client::builder().cert_verification(false).emulation(Emulation::Firefox136).build()?;
|
||||
|
||||
let mut response = client.get(video_url.clone())
|
||||
|
||||
@@ -67,7 +67,6 @@ impl MissavProvider {
|
||||
async fn query(&self, cache: VideoCache, pool:DbPool, page: u8, query: &str, sort: String, options: ServerOptions) -> Result<Vec<VideoItem>> {
|
||||
// Extract needed fields from options at the start
|
||||
let language = options.language.clone().unwrap();
|
||||
let filter = options.filter.clone().unwrap();
|
||||
let mut requester = options.requester.clone().unwrap();
|
||||
let search_string = query.replace(" ", "%20");
|
||||
let url_str = format!(
|
||||
|
||||
@@ -8,7 +8,7 @@ use error_chain::error_chain;
|
||||
use htmlentity::entity::{ICodedDataTrait, decode};
|
||||
use std::env;
|
||||
use std::vec;
|
||||
use wreq::{Client, Proxy};
|
||||
use wreq::{Client};
|
||||
use wreq_util::Emulation;
|
||||
|
||||
error_chain! {
|
||||
@@ -54,7 +54,7 @@ impl OkpornProvider {
|
||||
}
|
||||
};
|
||||
|
||||
let proxy = Proxy::all("http://192.168.0.103:8081").unwrap();
|
||||
// let proxy = Proxy::all("http://192.168.0.103:8081").unwrap();
|
||||
let client = Client::builder().cert_verification(false).emulation(Emulation::Firefox136).build()?;
|
||||
|
||||
let mut response = client.get(video_url.clone())
|
||||
@@ -129,7 +129,7 @@ impl OkpornProvider {
|
||||
}
|
||||
};
|
||||
|
||||
let proxy = Proxy::all("http://192.168.0.103:8081").unwrap();
|
||||
// let proxy = Proxy::all("http://192.168.0.103:8081").unwrap();
|
||||
let client = Client::builder().cert_verification(false).emulation(Emulation::Firefox136).build()?;
|
||||
|
||||
let mut response = client.get(video_url.clone())
|
||||
|
||||
@@ -9,7 +9,7 @@ use error_chain::error_chain;
|
||||
use htmlentity::entity::{ICodedDataTrait, decode};
|
||||
use std::env;
|
||||
use std::vec;
|
||||
use wreq::{Client, Proxy};
|
||||
use wreq::{Client};
|
||||
use wreq_util::Emulation;
|
||||
|
||||
error_chain! {
|
||||
@@ -55,7 +55,7 @@ impl OkxxxProvider {
|
||||
}
|
||||
};
|
||||
|
||||
let proxy = Proxy::all("http://192.168.0.103:8081").unwrap();
|
||||
// let proxy = Proxy::all("http://192.168.0.103:8081").unwrap();
|
||||
let client = Client::builder().cert_verification(false).emulation(Emulation::Firefox136).build()?;
|
||||
|
||||
let mut response = client.get(video_url.clone())
|
||||
@@ -134,7 +134,7 @@ impl OkxxxProvider {
|
||||
}
|
||||
};
|
||||
|
||||
let proxy = Proxy::all("http://192.168.0.103:8081").unwrap();
|
||||
// let proxy = Proxy::all("http://192.168.0.103:8081").unwrap();
|
||||
let client = Client::builder().cert_verification(false).emulation(Emulation::Firefox136).build()?;
|
||||
|
||||
let mut response = client.get(video_url.clone())
|
||||
|
||||
@@ -9,7 +9,7 @@ use error_chain::error_chain;
|
||||
use htmlentity::entity::{ICodedDataTrait, decode};
|
||||
use std::env;
|
||||
use std::vec;
|
||||
use wreq::{Client, Proxy};
|
||||
use wreq::{Client};
|
||||
use wreq_util::Emulation;
|
||||
|
||||
error_chain! {
|
||||
@@ -55,7 +55,7 @@ impl PerfectgirlsProvider {
|
||||
}
|
||||
};
|
||||
|
||||
let proxy = Proxy::all("http://192.168.0.103:8081").unwrap();
|
||||
// let proxy = Proxy::all("http://192.168.0.103:8081").unwrap();
|
||||
let client = Client::builder().cert_verification(false).emulation(Emulation::Firefox136).build()?;
|
||||
|
||||
let mut response = client.get(video_url.clone())
|
||||
@@ -134,7 +134,7 @@ impl PerfectgirlsProvider {
|
||||
}
|
||||
};
|
||||
|
||||
let proxy = Proxy::all("http://192.168.0.103:8081").unwrap();
|
||||
// let proxy = Proxy::all("http://192.168.0.103:8081").unwrap();
|
||||
let client = Client::builder().cert_verification(false).emulation(Emulation::Firefox136).build()?;
|
||||
|
||||
let mut response = client.get(video_url.clone())
|
||||
|
||||
@@ -270,7 +270,7 @@ impl PmvhavenProvider {
|
||||
}
|
||||
};
|
||||
|
||||
let proxy = Proxy::all("http://192.168.0.103:8081").unwrap();
|
||||
// let proxy = Proxy::all("http://192.168.0.103:8081").unwrap();
|
||||
let client = Client::builder()
|
||||
.cert_verification(false)
|
||||
.emulation(Emulation::Firefox136)
|
||||
@@ -300,34 +300,6 @@ impl PmvhavenProvider {
|
||||
}
|
||||
return Ok(video_items);
|
||||
}
|
||||
// else {
|
||||
// let flare_url = env::var("FLARE_URL").expect("FLARE_URL not set");
|
||||
// let flare = Flaresolverr::new(flare_url);
|
||||
// let result = flare
|
||||
// .solve(FlareSolverrRequest {
|
||||
// cmd: "request.get".to_string(),
|
||||
// url: url.clone(),
|
||||
// maxTimeout: 60000,
|
||||
// })
|
||||
// .await;
|
||||
// let video_items = match result {
|
||||
// Ok(res) => {
|
||||
// // println!("FlareSolverr response: {}", res);
|
||||
// self.get_video_items_from_html(res.solution.response)
|
||||
// }
|
||||
// Err(e) => {
|
||||
// println!("Error solving FlareSolverr: {}", e);
|
||||
// return Err("Failed to solve FlareSolverr".into());
|
||||
// }
|
||||
// };
|
||||
// if !video_items.is_empty() {
|
||||
// cache.remove(&url);
|
||||
// cache.insert(url.clone(), video_items.clone());
|
||||
// } else {
|
||||
// return Ok(old_items);
|
||||
// }
|
||||
// Ok(video_items)
|
||||
// }
|
||||
Err("Failed to get Videos".into())
|
||||
}
|
||||
async fn query(&self, cache: VideoCache, page: u8, query: &str) -> Result<Vec<VideoItem>> {
|
||||
@@ -349,7 +321,7 @@ impl PmvhavenProvider {
|
||||
}
|
||||
};
|
||||
|
||||
let proxy = Proxy::all("http://192.168.0.103:8081").unwrap();
|
||||
// let proxy = Proxy::all("http://192.168.0.103:8081").unwrap();
|
||||
let client = Client::builder()
|
||||
.cert_verification(false)
|
||||
.emulation(Emulation::Firefox136)
|
||||
|
||||
Reference in New Issue
Block a user