fix: video embeds

add: listening state api
This commit is contained in:
trisua 2025-04-26 21:55:32 -04:00
parent 498884291e
commit a114d862ae
4 changed files with 39 additions and 11 deletions

View file

@ -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,

View file

@ -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<State>,
Path(username): Path<String>,
) -> 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<State>,

View file

@ -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),