fix
Some checks failed
ci/woodpecker/push/build Pipeline failed

This commit is contained in:
JMARyA 2024-12-12 20:28:11 +01:00
parent 4d32422bd6
commit ce9351d9a6
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
4 changed files with 574 additions and 271 deletions

811
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -12,6 +12,7 @@ use std::path::PathBuf;
pub struct YouTubeMeta {
pub id: String,
pub title: String,
pub description: String,
pub uploader_name: String,
pub uploader_id: String,
pub views: i64,
@ -70,6 +71,13 @@ impl Video {
.unwrap()
}
pub async fn youtube_meta(&self) -> Option<YouTubeMeta> {
if let Some(meta) = self.youtube_id.as_ref().map(|id| YouTubeMeta::get(id)) {
return meta.await;
}
None
}
pub async fn has_path(path: &str) -> bool {
sqlx::query("SELECT id FROM videos WHERE path = $1")
.bind(path)

View file

@ -1,10 +1,12 @@
use maud::{html, PreEscaped};
use crate::library::Video;
pub fn shell(content: PreEscaped<String>, title: &str) -> PreEscaped<String> {
html! {
html {
head {
title=(title)
title { (title) };
};
body {
(content)
@ -34,17 +36,17 @@ pub fn search_bar(query: &str) -> PreEscaped<String> {
}
}
pub fn video_element(video: &mut Video) -> PreEscaped<String> {
pub async fn video_element(video: &mut Video) -> PreEscaped<String> {
html!(
@let desc = video.description().unwrap_or_default().to_owned();
@let video_hash = video.hash();
@let desc = video.youtube_meta().await.map(|x| x.description);
@let video_id = video.id;
article class="container-fluid" style="margin: 50px; cursor: pointer;" {
a href=(format!("/watch?v={video_hash}")) style="text-decoration:none !important;" {
img style="width: 350px;" width="480" src=(format!("/video/thumbnail?v={video_hash}"));
a href=(format!("/watch?v={video_id}")) style="text-decoration:none !important;" {
img style="width: 350px;" width="480" src=(format!("/video/thumbnail?v={video_id}"));
div style="padding: 10px;" {
h2 style="margin: 0; font-size: 18px;" { (video.title().unwrap()) };
@if !desc.is_empty() {
p style="margin: 0; color: grey; font-size: 14px;margin-top: 10px;" { (desc.chars().take(200).chain("...".to_string().chars()).take(203).collect::<String>()) };
h2 style="margin: 0; font-size: 18px;" { (video.title) };
@if !desc.as_ref().map(|x| x.is_empty()).unwrap_or(true) {
p style="margin: 0; color: grey; font-size: 14px;margin-top: 10px;" { (desc.unwrap().chars().take(200).chain("...".to_string().chars()).take(203).collect::<String>()) };
};
};
};

View file

@ -1,3 +1,4 @@
use maud::html;
use rocket::{get, State};
use serde_json::json;
@ -27,3 +28,8 @@ pub async fn channel_page(dir: &str, library: &State<Library>) -> Option<serde_j
Some(json!(vec_to_api(&mut dir_videos).await))
}
#[get("/")]
pub async fn index_page(library: &State<Library>) -> String {
unimplemented!()
}