Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

1.4 KB
Raw Blame
use std::sync::Arc;

use axum::{extract::Query, extract::State, Json};
use dbx_core::{changelog, update};

use crate::error::AppError;
use crate::state::WebState;

pub async fn get_version(State(state): State<Arc<WebState>>) -> Json<serde_json::Value> {
    Json(serde_json::json!({ "version": env!("CARGO_PKG_VERSION"), "demoMode": state.demo_mode }))
}

#[derive(serde::Deserialize)]
pub struct UpdateCheckParams {
    #[serde(default)]
    pub locale: Option<String>,
    #[serde(default)]
    pub source: Option<dbx_core::DownloadSource>,
}

pub async fn check_for_updates(Query(params): Query<UpdateCheckParams>) -> Result<Json<serde_json::Value>, AppError> {
    let locale = params.locale.unwrap_or_else(|| "zh-CN".to_string());
    let release =
        update::fetch_latest_release(&locale, params.source.unwrap_or_default()).await.map_err(AppError::from)?;
    let info = update::build_update_info(release, env!("CARGO_PKG_VERSION"));
    Ok(Json(serde_json::to_value(info).map_err(|e| AppError::from(e.to_string()))?))
}

#[derive(serde::Deserialize)]
pub struct ChangelogParams {
    #[serde(default)]
    pub lang: Option<String>,
}

pub async fn fetch_changelog(
    Query(params): Query<ChangelogParams>,
) -> Result<Json<changelog::ChangelogData>, AppError> {
    let lang = params.lang.unwrap_or_else(|| "en".to_string());
    let data = changelog::fetch_changelog(&lang).await.map_err(AppError::from)?;
    Ok(Json(data))
}