sorting for hanime
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
-- Your SQL goes here
|
-- Your SQL goes here
|
||||||
CREATE TABLE videos (
|
CREATE TABLE videos (
|
||||||
id TEXT NOT NULL PRIMARY KEY, -- like url parts to uniquely identify a video
|
id TEXT NOT NULL PRIMARY KEY, -- like url parts to uniquely identify a video
|
||||||
url TEXT NOT NULL,
|
url TEXT NOT NULL--,
|
||||||
views INTEGER,
|
--views INTEGER,
|
||||||
rating INTEGER,
|
--rating INTEGER,
|
||||||
uploader TEXT
|
--uploader TEXT
|
||||||
)
|
)
|
||||||
45
src/api.rs
45
src/api.rs
@@ -186,7 +186,50 @@ async fn status(req: HttpRequest) -> Result<impl web::Responder, web::Error> {
|
|||||||
favicon: "https://www.google.com/s2/favicons?sz=64&domain=hanime.tv".to_string(),
|
favicon: "https://www.google.com/s2/favicons?sz=64&domain=hanime.tv".to_string(),
|
||||||
status: "active".to_string(),
|
status: "active".to_string(),
|
||||||
categories: vec![],
|
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,
|
nsfw: true,
|
||||||
});
|
});
|
||||||
status.iconUrl = format!("http://{}/favicon.ico", host).to_string();
|
status.iconUrl = format!("http://{}/favicon.ico", host).to_string();
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
use dotenvy::dotenv;
|
|
||||||
use std::{env, sync::{Arc, Mutex}};
|
|
||||||
use crate::models::DBVideo;
|
use crate::models::DBVideo;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -198,9 +198,10 @@ impl HanimeProvider {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get(&self, cache: VideoCache, pool: DbPool, page: u8, query: String) -> Result<Vec<Video_Item>> {
|
async fn get(&self, cache: VideoCache, pool: DbPool, page: u8, query: String, sort:String) -> Result<Vec<Video_Item>> {
|
||||||
let index = format!("{}:{}", query, page);
|
let index = format!("{}:{}:{}", query, page, sort);
|
||||||
|
let order_by = sort.split(".").collect::<Vec<&str>>()[0].to_string();
|
||||||
|
let ordering = sort.split(".").collect::<Vec<&str>>()[1].to_string();
|
||||||
let old_items = match cache.get(&index) {
|
let old_items = match cache.get(&index) {
|
||||||
Some((time, items)) => {
|
Some((time, items)) => {
|
||||||
if time.elapsed().unwrap_or_default().as_secs() < 60 * 60 * 12 {
|
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() {
|
let client = match env::var("BURP_URL").as_deref() {
|
||||||
Ok(burp_url) =>
|
Ok(burp_url) =>
|
||||||
reqwest::Client::builder()
|
reqwest::Client::builder()
|
||||||
@@ -277,9 +282,10 @@ impl Provider for HanimeProvider {
|
|||||||
let _ = featured;
|
let _ = featured;
|
||||||
let _ = per_page;
|
let _ = per_page;
|
||||||
let _ = sort;
|
let _ = sort;
|
||||||
|
println!("Sort: {:?}", sort);
|
||||||
let videos: std::result::Result<Vec<Video_Item>, Error> = match query {
|
let videos: std::result::Result<Vec<Video_Item>, Error> = match query {
|
||||||
Some(q) => self.get(cache, pool, page.parse::<u8>().unwrap_or(1), q).await,
|
Some(q) => self.get(cache, pool, page.parse::<u8>().unwrap_or(1), q, sort).await,
|
||||||
None => self.get(cache, pool, page.parse::<u8>().unwrap_or(1), "".to_string()).await,
|
None => self.get(cache, pool, page.parse::<u8>().unwrap_or(1), "".to_string(), sort).await,
|
||||||
};
|
};
|
||||||
match videos {
|
match videos {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
|
|||||||
Reference in New Issue
Block a user