Added lastfm statistics
Build and Publish / Build and Publish Docker Image (push) Successful in 2m58s

This commit is contained in:
Ultradesu
2026-05-26 18:16:34 +03:00
parent d425bf3087
commit 4b8797bb2e
18 changed files with 657 additions and 93 deletions
+44 -1
View File
@@ -1,6 +1,6 @@
use std::collections::HashMap;
use cot::db::Database;
use cot::db::{Database, Model};
use cot::html::Html;
use cot::http::StatusCode;
use cot::http::header::CONTENT_TYPE;
@@ -14,6 +14,7 @@ use sqlx::{PgPool, Postgres, QueryBuilder};
use super::BUILD_INFO;
use crate::auth::{self, AuthenticatedUser, Role};
use crate::config::{AppConfig, ConfigEntry};
use crate::i18n::{I18n, Translations};
use crate::scheduler::{JobRegistry, ScheduledJob};
@@ -214,6 +215,17 @@ struct MutationResponse {
affected: u64,
}
#[derive(Debug, Serialize, JsonSchema)]
struct AdminSettingsDto {
lastfm_api_key: String,
lastfm_api_key_configured: bool,
}
#[derive(Debug, Deserialize)]
pub(super) struct UpdateSettingsRequest {
lastfm_api_key: String,
}
#[derive(Debug, Serialize, JsonSchema)]
struct LibraryOverviewDto {
artists: i64,
@@ -458,6 +470,37 @@ pub async fn jobs(
Json(jobs).into_response()
}
pub async fn settings(session: Session, db: Database) -> cot::Result<cot::response::Response> {
if let Err(response) = require_admin_json(&session, &db).await {
return Ok(response);
}
let (config, _) = AppConfig::load_with_db(&db).await;
Json(AdminSettingsDto {
lastfm_api_key_configured: !config.lastfm_api_key.trim().is_empty(),
lastfm_api_key: config.lastfm_api_key,
})
.into_response()
}
pub async fn update_settings(
session: Session,
db: Database,
Json(body): Json<UpdateSettingsRequest>,
) -> cot::Result<cot::response::Response> {
if let Err(response) = require_admin_json(&session, &db).await {
return Ok(response);
}
let mut entry = ConfigEntry::new(
"lastfm_api_key".to_string(),
body.lastfm_api_key.trim().to_string(),
);
entry
.save(&db)
.await
.map_err(|e| cot::Error::internal(e.to_string()))?;
Json(serde_json::json!({ "ok": true })).into_response()
}
pub async fn run_job(
session: Session,
db: Database,