From a114d862ae6dbb90ada7a5d36a4103c8da971a33 Mon Sep 17 00:00:00 2001 From: trisua Date: Sat, 26 Apr 2025 21:55:32 -0400 Subject: [PATCH] fix: video embeds add: listening state api --- crates/app/src/public/js/me.js | 20 +++++++-------- .../routes/api/v1/auth/connections/last_fm.rs | 25 ++++++++++++++++++- crates/app/src/routes/api/v1/mod.rs | 4 +++ crates/shared/src/markdown.rs | 1 + 4 files changed, 39 insertions(+), 11 deletions(-) diff --git a/crates/app/src/public/js/me.js b/crates/app/src/public/js/me.js index 45f27c4..361f826 100644 --- a/crates/app/src/public/js/me.js +++ b/crates/app/src/public/js/me.js @@ -671,22 +671,22 @@ ]); } - if ( - window.localStorage.getItem("atto:connections.last_fm/name") === - playing.name - ) { - // item already pushed to connection, no need right now - return; - } - const mb_info = await $.pull_track_info( playing.artist.name, playing.name, ); + if ( + window.localStorage.getItem("atto:connections.last_fm/name") === + playing.name + mb_info.id + ) { + // item already pushed to connection, no need right now + return; + } + window.localStorage.setItem( "atto:connections.last_fm/name", - playing.name, + playing.name + mb_info.id, ); return await trigger("connections::push_con_state", [ @@ -698,7 +698,7 @@ track_img: playing.image[2]["#text"], }, data: { - id: playing.mbid, + id: mb_info.id, // track track: playing.name, artist: playing.artist.name, diff --git a/crates/app/src/routes/api/v1/auth/connections/last_fm.rs b/crates/app/src/routes/api/v1/auth/connections/last_fm.rs index b4502b5..d8e7c02 100644 --- a/crates/app/src/routes/api/v1/auth/connections/last_fm.rs +++ b/crates/app/src/routes/api/v1/auth/connections/last_fm.rs @@ -1,5 +1,5 @@ use std::collections::HashMap; -use axum::{response::IntoResponse, Extension, Json}; +use axum::{extract::Path, response::IntoResponse, Extension, Json}; use axum_extra::extract::CookieJar; use tetratto_core::{ database::connections::last_fm::LastFmConnection, @@ -49,6 +49,29 @@ pub async fn create_request( }) } +pub async fn get_request( + Extension(data): Extension, + Path(username): Path, +) -> impl IntoResponse { + let data = &(data.read().await).0; + + let profile = match data.get_user_by_username(&username).await { + Ok(ua) => ua, + Err(e) => return Json(e.into()), + }; + + let con = match profile.connections.get(&ConnectionService::LastFm) { + Some(c) => c, + None => return Json(Error::GeneralNotFound("connection".to_string()).into()), + }; + + Json(ApiReturn { + ok: true, + message: "Connection exists".to_string(), + payload: Some(con.1.clone()), + }) +} + pub async fn proxy_request( jar: CookieJar, Extension(data): Extension, diff --git a/crates/app/src/routes/api/v1/mod.rs b/crates/app/src/routes/api/v1/mod.rs index e19d2be..f943601 100644 --- a/crates/app/src/routes/api/v1/mod.rs +++ b/crates/app/src/routes/api/v1/mod.rs @@ -258,6 +258,10 @@ pub fn routes() -> Router { "/auth/user/connections/last_fm", post(auth::connections::last_fm::create_request), ) + .route( + "/auth/user/connections/last_fm/data/{username}", + get(auth::connections::last_fm::get_request), + ) .route( "/auth/user/connections/last_fm/api_proxy", post(auth::connections::last_fm::proxy_request), diff --git a/crates/shared/src/markdown.rs b/crates/shared/src/markdown.rs index d92f551..d6f55d5 100644 --- a/crates/shared/src/markdown.rs +++ b/crates/shared/src/markdown.rs @@ -26,6 +26,7 @@ pub fn render_markdown(input: &str) -> String { allowed_attributes.insert("lang"); allowed_attributes.insert("title"); allowed_attributes.insert("align"); + allowed_attributes.insert("src"); allowed_attributes.insert("data-color"); allowed_attributes.insert("data-font-family");