diff --git a/migrations/create_videos/up.sql b/migrations/create_videos/up.sql index e8d1826..781ca1b 100644 --- a/migrations/create_videos/up.sql +++ b/migrations/create_videos/up.sql @@ -1,8 +1,8 @@ -- Your SQL goes here CREATE TABLE videos ( id TEXT NOT NULL PRIMARY KEY, -- like url parts to uniquely identify a video - url TEXT NOT NULL, - views INTEGER, - rating INTEGER, - uploader TEXT + url TEXT NOT NULL--, + --views INTEGER, + --rating INTEGER, + --uploader TEXT ) \ No newline at end of file diff --git a/src/api.rs b/src/api.rs index a183469..a95578b 100644 --- a/src/api.rs +++ b/src/api.rs @@ -186,7 +186,50 @@ async fn status(req: HttpRequest) -> Result { favicon: "https://www.google.com/s2/favicons?sz=64&domain=hanime.tv".to_string(), status: "active".to_string(), categories: vec![], - options: vec![], + options: vec![ + ChannelOption{ + id: "sort".to_string(), + title: "Sort".to_string(), + description: "Sort the Videos".to_string(), //"Sort the videos by Date or Name.".to_string(), + systemImage: "list.number".to_string(), + colorName: "blue".to_string(), + options: vec![ + FilterOption { + id: "created_at_unix.desc".to_string(), + title: "Recent Upload".to_string(), + }, + FilterOption { + id: "created_at_unix.asc".to_string(), + title: "Old Upload".to_string(), + }, + FilterOption { + id: "views.desc".to_string(), + title: "Most Views".to_string(), + }, + FilterOption { + id: "views.asc".to_string(), + title: "Least Views".to_string(), + }, + FilterOption { + id: "likes.desc".to_string(), + title: "Most Likes".to_string(), + }, + FilterOption { + id: "likes.asc".to_string(), + title: "Least Likes".to_string(), + }, + FilterOption { + id: "title_sortable.asc".to_string(), + title: "A - Z".to_string(), + }, + FilterOption { + id: "title_sortable.desc".to_string(), + title: "Z - A".to_string(), + }, + ], + multiSelect: false, + } + ], nsfw: true, }); status.iconUrl = format!("http://{}/favicon.ico", host).to_string(); diff --git a/src/db.rs b/src/db.rs index 836717b..31d4f97 100644 --- a/src/db.rs +++ b/src/db.rs @@ -1,6 +1,4 @@ use diesel::prelude::*; -use dotenvy::dotenv; -use std::{env, sync::{Arc, Mutex}}; use crate::models::DBVideo; diff --git a/src/providers/hanime.rs b/src/providers/hanime.rs index d758342..a913b98 100644 --- a/src/providers/hanime.rs +++ b/src/providers/hanime.rs @@ -198,9 +198,10 @@ impl HanimeProvider { } - async fn get(&self, cache: VideoCache, pool: DbPool, page: u8, query: String) -> Result> { - let index = format!("{}:{}", query, page); - + async fn get(&self, cache: VideoCache, pool: DbPool, page: u8, query: String, sort:String) -> Result> { + let index = format!("{}:{}:{}", query, page, sort); + let order_by = sort.split(".").collect::>()[0].to_string(); + let ordering = sort.split(".").collect::>()[1].to_string(); let old_items = match cache.get(&index) { Some((time, items)) => { if time.elapsed().unwrap_or_default().as_secs() < 60 * 60 * 12 { @@ -216,7 +217,11 @@ impl HanimeProvider { } }; - let search = HanimeSearchRequest::new().page(page-1).search_text(query.clone()); + let search = HanimeSearchRequest::new() + .page(page-1) + .search_text(query.clone()) + .order_by(order_by) + .ordering(ordering); let client = match env::var("BURP_URL").as_deref() { Ok(burp_url) => reqwest::Client::builder() @@ -277,9 +282,10 @@ impl Provider for HanimeProvider { let _ = featured; let _ = per_page; let _ = sort; + println!("Sort: {:?}", sort); let videos: std::result::Result, Error> = match query { - Some(q) => self.get(cache, pool, page.parse::().unwrap_or(1), q).await, - None => self.get(cache, pool, page.parse::().unwrap_or(1), "".to_string()).await, + Some(q) => self.get(cache, pool, page.parse::().unwrap_or(1), q, sort).await, + None => self.get(cache, pool, page.parse::().unwrap_or(1), "".to_string(), sort).await, }; match videos { Ok(v) => v,