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

This commit is contained in:
JMARyA 2025-02-23 23:39:25 +01:00
parent 240d6cd5ce
commit fb55d396f8
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
12 changed files with 66 additions and 24 deletions

View file

@ -8,5 +8,7 @@ pub struct Config {
#[derive(Debug, Clone, Deserialize)]
pub struct GeneralConfig {
pub private: bool,
pub allow_ogp: bool,
pub root_url: String,
pub video_path: String,
}

View file

@ -1,5 +1,3 @@
use based::auth::User;
use based::get_pg;
use std::path::Path;
use std::path::PathBuf;
use std::str::FromStr;

View file

@ -1,5 +1,6 @@
use crate::yt_meta::{self, get_vid_duration};
use based::{get_pg, request::api::ToAPI};
use chrono::Utc;
use serde::{Deserialize, Serialize};
use serde_json::json;
use sqlx::prelude::FromRow;
@ -75,6 +76,7 @@ pub struct Video {
pub path: String,
pub duration: f64,
pub title: String,
pub date_added: chrono::DateTime<Utc>,
youtube_id: Option<String>,
}

View file

@ -1,9 +1,4 @@
use based::{
asset::AssetRoutes,
auth::User,
get_pg,
ui::components::{AppBar, Shell},
};
use based::{asset::AssetRoutes, auth::User, get_pg, ui::components::prelude::Shell};
use rocket::{http::Method, routes};
use std::path::Path;
mod config;

View file

@ -48,7 +48,7 @@ pub async fn video_thumbnail(
conf: &State<Config>,
user: MaybeUser,
) -> Option<DataResponse> {
if conf.general.private && user.user().is_none() {
if (conf.general.private && user.user().is_none()) && !conf.general.allow_ogp {
return None;
}

View file

@ -1,7 +1,6 @@
use crate::library::Video;
use based::ui::components::prelude::Avatar;
use based::ui::components::prelude::*;
use based::ui::components::{NavBar, Shell};
use based::ui::primitives::flex::Row;
use based::ui::primitives::Optional;
use based::ui::wrapper::HoverWrapper;

View file

@ -1,7 +1,7 @@
use based::page;
use based::request::respond_html;
use based::ui::components::prelude::InfinityScroll;
use based::ui::components::{ColoredSpinner, Shell};
use based::ui::components::prelude::{InfinityScroll, Shell};
use based::ui::components::ColoredSpinner;
use based::ui::prelude::*;
use based::ui::primitives::div::Center;
use based::{
@ -12,7 +12,7 @@ use based::{
},
};
use maud::{html, PreEscaped, Render};
use rocket::{get, uri, State};
use rocket::{get, State};
use serde_json::json;
use crate::config::Config;

View file

@ -3,11 +3,11 @@ use based::auth::{Sessions, User};
use based::page;
use based::request::StringResponse;
use based::ui::components::prelude::Avatar;
use based::ui::components::{prelude::*, Shell};
use based::ui::components::prelude::*;
use based::ui::primitives::flex::Row;
use based::ui::{prelude::*, AttrExtendable};
use based::{auth::MaybeUser, request::RequestContext};
use maud::{html, PreEscaped, Render};
use maud::{html, Render};
use rocket::http::CookieJar;
use rocket::State;
use rocket::{form::Form, get, http::Cookie, post, response::Redirect, FromForm};

View file

@ -1,5 +1,7 @@
use based::format::format_number;
use based::ui::components::Shell;
use based::ogp::{MediaItem, Metadata};
use based::request::respond_html;
use based::ui::components::prelude::Shell;
use based::ui::primitives::space::Fraction;
use based::ui::{prelude::*, AttrExtendable};
use based::{
@ -10,7 +12,6 @@ use based::{
use maud::{html, PreEscaped, Render};
use rocket::{get, State};
use crate::check_private;
use crate::config::Config;
use crate::library::Video;
use crate::{
@ -29,8 +30,6 @@ pub async fn watch_page(
conf: &State<Config>,
shell: &State<Shell>,
) -> StringResponse {
check_private!(conf, user, shell, ctx);
let video = if let Some(video) = library.get_video_by_id(&v).await {
video
} else {
@ -38,6 +37,46 @@ pub async fn watch_page(
library.get_video_by_youtube_id(&v).await.unwrap()
};
let yt_meta = video.youtube_meta().await;
let mut vid_meta =
based::ogp::Video::Other(video.duration as u32, video.date_added.date_naive());
if let Some(yt_meta) = &yt_meta {
for t in yt_meta.tags().await {
vid_meta = vid_meta.tag(&t);
}
}
let meta = Metadata::new(
&format!("{}/watch?v={}", conf.general.root_url, video.id),
&video.title,
MediaItem::Image(
&format!("{}/video/thumbnail?v={}", conf.general.root_url, video.id),
"image/png",
"Video Thumbnail",
),
vid_meta,
)
.site_name("WatchDogs");
if conf.general.private && user.user().is_none() {
return respond_html(
html! {
(maud::DOCTYPE)
html {
head {
(meta.render())
}
body {
}
}
}
.0,
);
}
if let Some(user) = user.user() {
user.insert_history(video.id).await;
}
@ -104,7 +143,7 @@ pub async fn watch_page(
).x(ScreenValue::_10).top(ScreenValue::_6).render();
render_page(
&shell,
&shell.inner().extend().metadata(meta),
ctx,
content,
&format!("{} - WatchDogs", video.title),