sorting for hanime

This commit is contained in:
Simon
2025-06-05 19:59:28 +00:00
parent 175c9b748f
commit df323ec9fd
4 changed files with 60 additions and 13 deletions

View File

@@ -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(),
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();

View File

@@ -1,6 +1,4 @@
use diesel::prelude::*;
use dotenvy::dotenv;
use std::{env, sync::{Arc, Mutex}};
use crate::models::DBVideo;

View File

@@ -198,9 +198,10 @@ impl HanimeProvider {
}
async fn get(&self, cache: VideoCache, pool: DbPool, page: u8, query: String) -> Result<Vec<Video_Item>> {
let index = format!("{}:{}", query, page);
async fn get(&self, cache: VideoCache, pool: DbPool, page: u8, query: String, sort:String) -> Result<Vec<Video_Item>> {
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) {
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<Vec<Video_Item>, Error> = match query {
Some(q) => self.get(cache, pool, page.parse::<u8>().unwrap_or(1), q).await,
None => self.get(cache, pool, page.parse::<u8>().unwrap_or(1), "".to_string()).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(), sort).await,
};
match videos {
Ok(v) => v,