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

6
Cargo.lock generated
View file

@ -146,7 +146,7 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b"
[[package]] [[package]]
name = "based" name = "based"
version = "0.1.0" version = "0.1.0"
source = "git+https://git.hydrar.de/jmarya/based?branch=ui#f2cfcf27bbe7668caf95a99e7b8f7698e023fdec" source = "git+https://git.hydrar.de/jmarya/based#696b34f2f17ef2d86f0bc77993f9b0b8b652c0f6"
dependencies = [ dependencies = [
"bcrypt", "bcrypt",
"chrono", "chrono",
@ -503,9 +503,9 @@ checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"
[[package]] [[package]]
name = "either" name = "either"
version = "1.13.0" version = "1.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" checksum = "b7914353092ddf589ad78f25c5c1c21b7f80b0ff8621e7c814c3485b5306da9d"
dependencies = [ dependencies = [
"serde", "serde",
] ]

View file

@ -24,5 +24,5 @@ maud = "0.26.0"
rand = "0.8.5" rand = "0.8.5"
data-encoding = "2.6.0" data-encoding = "2.6.0"
bcrypt = "0.16.0" bcrypt = "0.16.0"
based = { git = "https://git.hydrar.de/jmarya/based", features = ["cache"], branch = "ui" } based = { git = "https://git.hydrar.de/jmarya/based", features = ["cache"] }
toml = "0.8.20" toml = "0.8.20"

View file

@ -3,5 +3,12 @@
# Private Instance (Login required for watching content) # Private Instance (Login required for watching content)
private = true private = true
# Allow OGP (Open Graph Protocol)
# This might expose metadata and thumbnails of videos (even if private)
allow_ogp = true
# Root URL
root_url = "http://127.0.0.1:8080"
# Path to videos # Path to videos
video_path = "./videos" video_path = "./videos"

View file

@ -8,5 +8,7 @@ pub struct Config {
#[derive(Debug, Clone, Deserialize)] #[derive(Debug, Clone, Deserialize)]
pub struct GeneralConfig { pub struct GeneralConfig {
pub private: bool, pub private: bool,
pub allow_ogp: bool,
pub root_url: String,
pub video_path: 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::Path;
use std::path::PathBuf; use std::path::PathBuf;
use std::str::FromStr; use std::str::FromStr;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,5 +1,7 @@
use based::format::format_number; 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::primitives::space::Fraction;
use based::ui::{prelude::*, AttrExtendable}; use based::ui::{prelude::*, AttrExtendable};
use based::{ use based::{
@ -10,7 +12,6 @@ use based::{
use maud::{html, PreEscaped, Render}; use maud::{html, PreEscaped, Render};
use rocket::{get, State}; use rocket::{get, State};
use crate::check_private;
use crate::config::Config; use crate::config::Config;
use crate::library::Video; use crate::library::Video;
use crate::{ use crate::{
@ -29,8 +30,6 @@ pub async fn watch_page(
conf: &State<Config>, conf: &State<Config>,
shell: &State<Shell>, shell: &State<Shell>,
) -> StringResponse { ) -> StringResponse {
check_private!(conf, user, shell, ctx);
let video = if let Some(video) = library.get_video_by_id(&v).await { let video = if let Some(video) = library.get_video_by_id(&v).await {
video video
} else { } else {
@ -38,6 +37,46 @@ pub async fn watch_page(
library.get_video_by_youtube_id(&v).await.unwrap() 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() { if let Some(user) = user.user() {
user.insert_history(video.id).await; user.insert_history(video.id).await;
} }
@ -104,7 +143,7 @@ pub async fn watch_page(
).x(ScreenValue::_10).top(ScreenValue::_6).render(); ).x(ScreenValue::_10).top(ScreenValue::_6).render();
render_page( render_page(
&shell, &shell.inner().extend().metadata(meta),
ctx, ctx,
content, content,
&format!("{} - WatchDogs", video.title), &format!("{} - WatchDogs", video.title),