Compare commits

..

No commits in common. "a0e7c5d3c17a466c95941b3bffa3650ea73830de" and "e8dcb1dc77e60f655a979b8819848b88f96c371a" have entirely different histories.

8 changed files with 47 additions and 277 deletions

191
Cargo.lock generated
View file

@ -137,12 +137,6 @@ dependencies = [
"windows-targets 0.52.6",
]
[[package]]
name = "base64"
version = "0.21.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
[[package]]
name = "base64"
version = "0.22.1"
@ -158,7 +152,7 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b"
[[package]]
name = "based"
version = "0.1.0"
source = "git+https://git.hydrar.de/jmarya/based#a89c5661208585b2a9f09d5ee337ad1c60ea9a49"
source = "git+https://git.hydrar.de/jmarya/based#40d69b61e1a36d934c0c611e15a8fa26ec86fa83"
dependencies = [
"bcrypt",
"chrono",
@ -172,7 +166,6 @@ dependencies = [
"rand",
"rayon",
"regex",
"reqwest",
"ring",
"rocket",
"rocket_cors",
@ -190,7 +183,7 @@ version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b1866ecef4f2d06a0bb77880015fdf2b89e25a1c2e5addacb87e459c86dc67e"
dependencies = [
"base64 0.22.1",
"base64",
"blowfish",
"getrandom",
"subtle",
@ -203,12 +196,6 @@ version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "383d29d513d8764dcdc42ea295d979eb99c3c9f00607b3692cf68a431f7dca72"
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitflags"
version = "2.6.0"
@ -245,9 +232,9 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
[[package]]
name = "bytemuck"
version = "1.21.0"
version = "1.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef657dfab802224e671f5818e9a4935f9b1957ed18e58292690cc39e7a4092a3"
checksum = "8b37c88a63ffd85d15b406896cc343916d7cf57838a847b3a6f2ca5d39a5695a"
[[package]]
name = "byteorder"
@ -263,9 +250,9 @@ checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b"
[[package]]
name = "cc"
version = "1.2.5"
version = "1.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c31a0499c1dc64f458ad13872de75c0eb7e3fdb0e67964610c914b034fc5956e"
checksum = "9157bbaa6b165880c27a4293a474c91cdcf265cc68cc829bf10be0964a391caf"
dependencies = [
"shlex",
]
@ -477,7 +464,7 @@ version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b035a542cf7abf01f2e3c4d5a7acbaebfefe120ae4efc7bde3df98186e4b8af7"
dependencies = [
"bitflags 2.6.0",
"bitflags",
"proc-macro2",
"proc-macro2-diagnostics",
"quote",
@ -959,19 +946,6 @@ dependencies = [
"want",
]
[[package]]
name = "hyper-tls"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905"
dependencies = [
"bytes",
"hyper",
"native-tls",
"tokio",
"tokio-native-tls",
]
[[package]]
name = "iana-time-zone"
version = "0.1.61"
@ -1160,12 +1134,6 @@ dependencies = [
"generic-array",
]
[[package]]
name = "ipnet"
version = "2.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708"
[[package]]
name = "is-terminal"
version = "0.4.13"
@ -1204,9 +1172,9 @@ dependencies = [
[[package]]
name = "libc"
version = "0.2.169"
version = "0.2.168"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
checksum = "5aaeb2981e0606ca11d79718f8bb01164f1d6ed75080182d3abf017e6d244b6d"
[[package]]
name = "libm"
@ -1468,9 +1436,9 @@ dependencies = [
[[package]]
name = "object"
version = "0.36.7"
version = "0.36.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87"
checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e"
dependencies = [
"memchr",
]
@ -1487,7 +1455,7 @@ version = "0.10.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6174bc48f102d208783c2c84bf931bb75927a617866870de8a4ea85597f871f5"
dependencies = [
"bitflags 2.6.0",
"bitflags",
"cfg-if",
"foreign-types",
"libc",
@ -1768,7 +1736,7 @@ version = "0.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03a862b389f93e68874fbf580b9de08dd02facb9a788ebadaf4a3fd33cf58834"
dependencies = [
"bitflags 2.6.0",
"bitflags",
]
[[package]]
@ -1835,46 +1803,6 @@ version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
[[package]]
name = "reqwest"
version = "0.11.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62"
dependencies = [
"base64 0.21.7",
"bytes",
"encoding_rs",
"futures-core",
"futures-util",
"h2",
"http 0.2.12",
"http-body",
"hyper",
"hyper-tls",
"ipnet",
"js-sys",
"log",
"mime",
"native-tls",
"once_cell",
"percent-encoding",
"pin-project-lite",
"rustls-pemfile",
"serde",
"serde_json",
"serde_urlencoded",
"sync_wrapper",
"system-configuration",
"tokio",
"tokio-native-tls",
"tower-service",
"url",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
"winreg",
]
[[package]]
name = "ring"
version = "0.16.20"
@ -2021,22 +1949,13 @@ version = "0.38.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f93dc38ecbab2eb790ff964bb77fa94faf256fd3e73285fd7ba0903b76bedb85"
dependencies = [
"bitflags 2.6.0",
"bitflags",
"errno",
"libc",
"linux-raw-sys",
"windows-sys 0.59.0",
]
[[package]]
name = "rustls-pemfile"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c"
dependencies = [
"base64 0.21.7",
]
[[package]]
name = "rustversion"
version = "1.0.18"
@ -2085,7 +2004,7 @@ version = "2.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02"
dependencies = [
"bitflags 2.6.0",
"bitflags",
"core-foundation",
"core-foundation-sys",
"libc",
@ -2124,9 +2043,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.134"
version = "1.0.133"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d00f4175c42ee48b15416f6193a959ba3a0d67fc699a0db9ad12df9f83991c7d"
checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377"
dependencies = [
"itoa",
"memchr",
@ -2375,8 +2294,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64bb4714269afa44aef2755150a0fc19d756fb580a67db8885608cf02f47d06a"
dependencies = [
"atoi",
"base64 0.22.1",
"bitflags 2.6.0",
"base64",
"bitflags",
"byteorder",
"bytes",
"chrono",
@ -2419,8 +2338,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fa91a732d854c5d7726349bb4bb879bb9478993ceb764247660aee25f67c2f8"
dependencies = [
"atoi",
"base64 0.22.1",
"bitflags 2.6.0",
"base64",
"bitflags",
"byteorder",
"chrono",
"crc",
@ -2520,21 +2439,15 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]]
name = "syn"
version = "2.0.91"
version = "2.0.90"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d53cbcb5a243bd33b7858b1d7f4aca2153490815872d86d955d6ea29f743c035"
checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "sync_wrapper"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160"
[[package]]
name = "synstructure"
version = "0.13.1"
@ -2546,27 +2459,6 @@ dependencies = [
"syn",
]
[[package]]
name = "system-configuration"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7"
dependencies = [
"bitflags 1.3.2",
"core-foundation",
"system-configuration-sys",
]
[[package]]
name = "system-configuration-sys"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9"
dependencies = [
"core-foundation-sys",
"libc",
]
[[package]]
name = "tempfile"
version = "3.14.0"
@ -2662,9 +2554,9 @@ dependencies = [
[[package]]
name = "tinyvec"
version = "1.8.1"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "022db8904dfa342efe721985167e9fcd16c29b226db4397ed752a761cfce81e8"
checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938"
dependencies = [
"tinyvec_macros",
]
@ -2704,16 +2596,6 @@ dependencies = [
"syn",
]
[[package]]
name = "tokio-native-tls"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2"
dependencies = [
"native-tls",
"tokio",
]
[[package]]
name = "tokio-stream"
version = "0.1.17"
@ -3039,19 +2921,6 @@ dependencies = [
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-futures"
version = "0.4.49"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38176d9b44ea84e9184eff0bc34cc167ed044f816accfe5922e54d84cf48eca2"
dependencies = [
"cfg-if",
"js-sys",
"once_cell",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.99"
@ -3334,16 +3203,6 @@ dependencies = [
"memchr",
]
[[package]]
name = "winreg"
version = "0.50.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1"
dependencies = [
"cfg-if",
"windows-sys 0.48.0",
]
[[package]]
name = "write16"
version = "1.0.0"

View file

@ -1,9 +0,0 @@
CREATE TABLE IF NOT EXISTS video_history (
id BIGSERIAL PRIMARY KEY,
username VARCHAR(255) NOT NULL,
video_id UUID NOT NULL,
timestamp TIMESTAMPTZ NOT NULL DEFAULT NOW(),
FOREIGN KEY (username) REFERENCES users (username) ON DELETE CASCADE,
FOREIGN KEY (video_id) REFERENCES videos (id) ON DELETE CASCADE
);

View file

@ -1,43 +0,0 @@
use based::{auth::User, get_pg};
use super::Video;
pub trait VideoHistory {
async fn last_video(&self) -> Option<uuid::Uuid>;
async fn insert_history(&self, vid: uuid::Uuid);
async fn history_of(&self, n: i64) -> Vec<Video>;
}
impl VideoHistory for User {
async fn last_video(&self) -> Option<uuid::Uuid> {
let res: Option<(uuid::Uuid,)> = sqlx::query_as("SELECT video_id FROM video_history WHERE username = $1 ORDER BY timestamp DESC LIMIT 1")
.bind(&self.username)
.fetch_optional(get_pg!())
.await.unwrap();
res.map(|x| x.0)
}
async fn insert_history(&self, vid: uuid::Uuid) {
if let Some(prev) = self.last_video().await {
if prev == vid {
return;
}
}
sqlx::query("INSERT INTO video_history (username, video_id) VALUES ($1, $2)")
.bind(&self.username)
.bind(vid)
.execute(get_pg!())
.await
.unwrap();
}
async fn history_of(&self, n: i64) -> Vec<Video> {
sqlx::query_as("SELECT v.* FROM video_history vh JOIN videos v ON vh.video_id = v.id WHERE vh.username = $1 ORDER BY vh.timestamp DESC LIMIT $2")
.bind(&self.username)
.bind(n)
.fetch_all(get_pg!())
.await.unwrap()
}
}

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;
@ -11,7 +9,6 @@ pub use video::Video;
use crate::meta;
mod func;
pub mod history;
mod video;
#[derive(Debug, Clone)]

View file

@ -54,7 +54,6 @@ async fn launch() -> _ {
.mount(
"/",
routes![
based::htmx::htmx_script_route,
pages::assets::video_file,
pages::assets::video_thumbnail,
pages::assets::fav_icon,
@ -66,8 +65,7 @@ async fn launch() -> _ {
pages::index::index_page,
pages::watch::watch_page,
pages::user::login,
pages::user::login_post,
pages::user::history_page
pages::user::login_post
],
)
.attach(cors)

View file

@ -13,14 +13,10 @@ pub async fn render_page(
title: &str,
user: Option<User>,
) -> StringResponse {
based::page::render_page(
content,
title,
ctx,
&based::page::Shell::new(
based::page::render_page(content, title, ctx, &based::page::Shell::new(
html! {
script src="https://cdn.tailwindcss.com" {};
script src="/assets/htmx.min.js" {};
script src="https://unpkg.com/htmx.org@2.0.3" integrity="sha384-0895/pl2MU10Hqc6jd4RvrthNlDiE9U1tWmX7WRESftEDRosgxNsQG/Ze9YMRzHq" crossorigin="anonymous" {};
meta name="viewport" content="width=device-width, initial-scale=1.0";
},
html! {
@ -40,11 +36,7 @@ pub async fn render_page(
};
};
},
Some(String::from("bg-black text-white")),
),
)
.await
}, Some(String::from("bg-black text-white")))).await
}
pub fn loading_spinner() -> PreEscaped<String> {

View file

@ -5,9 +5,6 @@ use maud::html;
use rocket::http::CookieJar;
use rocket::{form::Form, get, http::Cookie, post, response::Redirect, FromForm};
use crate::library::history::VideoHistory;
use crate::pages::components::video_element_wide;
use super::components::render_page;
#[get("/login")]
@ -46,17 +43,3 @@ pub async fn login_post(login_form: Form<LoginForm>, cookies: &CookieJar<'_>) ->
Some(Redirect::to("/"))
}
#[get("/history")]
pub async fn history_page(ctx: RequestContext, user: User) -> StringResponse {
let content = html! {
h1 class="text-center text-4xl font-extrabold leading-tight mt-4 mb-2" { "History" };
div class="p-6" {
@for mut vid in user.history_of(10).await {
( video_element_wide(&mut vid).await );
};
};
};
render_page(ctx, content, "History", Some(user)).await
}

View file

@ -6,10 +6,7 @@ use based::{
use maud::html;
use rocket::{get, State};
use crate::{
library::{history::VideoHistory, Library},
pages::components::video_element_wide,
};
use crate::{library::Library, pages::components::video_element_wide};
use super::components::render_page;
@ -27,10 +24,6 @@ pub async fn watch_page(
library.get_video_by_youtube_id(&v).await.unwrap()
};
if let Some(user) = user.user() {
user.insert_history(video.id).await;
}
let content = html!(
main class="container mx-auto mt-6 flex flex-col lg:flex-row gap-6" {
div class="lg:w-10/12 mt-10" {