This commit is contained in:
parent
198994a99c
commit
14483ceec4
3 changed files with 52 additions and 4 deletions
|
@ -159,6 +159,14 @@ impl Library {
|
|||
.unwrap()
|
||||
}
|
||||
|
||||
pub async fn get_newly_added(&self, n: i64) -> Vec<Video> {
|
||||
sqlx::query_as("SELECT * FROM videos ORDER BY date_added DESC LIMIT $1;")
|
||||
.bind(n)
|
||||
.fetch_all(&self.conn)
|
||||
.await
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub async fn get_video_by_id(&self, id: &str) -> Option<Video> {
|
||||
sqlx::query_as("SELECT * FROM videos WHERE id = $1")
|
||||
.bind(uuid::Uuid::from_str(id).unwrap_or(uuid::Uuid::nil()))
|
||||
|
|
|
@ -67,7 +67,9 @@ async fn launch() -> _ {
|
|||
pages::watch::watch_page,
|
||||
pages::user::login,
|
||||
pages::user::login_post,
|
||||
pages::user::history_page
|
||||
pages::user::history_page,
|
||||
pages::index::latest_page,
|
||||
pages::index::latest_api
|
||||
],
|
||||
)
|
||||
.attach(cors)
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
use based::{
|
||||
auth::MaybeUser,
|
||||
page::htmx_link,
|
||||
request::{api::vec_to_api, RequestContext, StringResponse},
|
||||
request::{
|
||||
api::{vec_to_api, FallibleApiResponse},
|
||||
RequestContext, StringResponse,
|
||||
},
|
||||
};
|
||||
use maud::html;
|
||||
use rocket::{get, State};
|
||||
|
@ -30,6 +33,33 @@ pub async fn search(
|
|||
Some(json!(vec_to_api(&mut video_matches).await))
|
||||
}
|
||||
|
||||
#[get("/latest.json")]
|
||||
pub async fn latest_api(library: &State<Library>) -> FallibleApiResponse {
|
||||
let videos = library.get_newly_added(20).await;
|
||||
let vid_api = vec_to_api(&videos).await;
|
||||
return Ok(serde_json::json!(vid_api));
|
||||
}
|
||||
|
||||
#[get("/latest")]
|
||||
pub async fn latest_page(
|
||||
ctx: RequestContext,
|
||||
library: &State<Library>,
|
||||
user: MaybeUser,
|
||||
) -> StringResponse {
|
||||
let videos = library.get_newly_added(20).await;
|
||||
|
||||
let content = html!(
|
||||
h1 class="text-center text-4xl font-extrabold leading-tight mt-6 mb-2" { "Recent videos" };
|
||||
div class="p-6" {
|
||||
@for mut vid in videos {
|
||||
( video_element_wide(&mut vid).await );
|
||||
};
|
||||
};
|
||||
);
|
||||
|
||||
render_page(ctx, content, "Recent videos", user.into()).await
|
||||
}
|
||||
|
||||
#[get("/d/<dir>")]
|
||||
pub async fn channel_page(
|
||||
ctx: RequestContext,
|
||||
|
@ -65,12 +95,20 @@ pub async fn index_page(
|
|||
user: MaybeUser,
|
||||
) -> StringResponse {
|
||||
let content = html!(
|
||||
h1 class="text-center text-4xl font-extrabold leading-tight mt-4" { "Random Videos" };
|
||||
div class="lg:grid grid-cols-3 gap-6 p-6" {
|
||||
h1 class="text-center text-4xl font-extrabold leading-tight mt-8" { "Random Videos" };
|
||||
div class="lg:grid grid-cols-3 gap-6 p-6 mb-4" {
|
||||
@for mut vid in library.get_random_videos(3).await {
|
||||
( video_element(&mut vid).await );
|
||||
};
|
||||
};
|
||||
|
||||
h1 class="text-center text-4xl font-extrabold leading-tight mt-10" { a href="/latest" { "Latest Videos" };};
|
||||
div class="lg:grid grid-cols-3 gap-6 p-6 mb-4" {
|
||||
@for mut vid in library.get_newly_added(3).await {
|
||||
( video_element(&mut vid).await );
|
||||
};
|
||||
};
|
||||
|
||||
h1 class="text-center text-4xl font-extrabold leading-tight mt-8" { "Directories:" };
|
||||
div class="flex flex-wrap p-10" {
|
||||
@for dir in library.get_directories().await {
|
||||
|
|
Loading…
Add table
Reference in a new issue