This commit is contained in:
fengchuanhn@gmail.com
2026-05-21 01:47:16 +08:00
parent 3b0a8d777c
commit 54f080fbc1
22 changed files with 1106 additions and 36 deletions

View File

@@ -8,3 +8,4 @@ pub mod fs_util;
pub mod nodejs;
pub mod publish;
pub mod quickjs;
pub mod software_info;

View File

@@ -0,0 +1,71 @@
//! 按本地 oem 文件中的 ID 拉取公开品牌信息。
use std::collections::HashMap;
use serde::Serialize;
use serde_json::Value;
use tauri::State;
use crate::api_client;
use crate::oem_context::OemContext;
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SoftwareInfo {
pub oem_id: i64,
pub software_name: String,
pub logo_url: Option<String>,
pub wechat: Option<String>,
}
fn empty_info(oem_id: i64) -> SoftwareInfo {
SoftwareInfo {
oem_id,
software_name: String::new(),
logo_url: None,
wechat: None,
}
}
fn parse_software_info(oem_id: i64, value: &Value) -> SoftwareInfo {
let data = value.get("data").unwrap_or(value);
SoftwareInfo {
oem_id: data
.get("oem_id")
.and_then(|v| v.as_i64())
.unwrap_or(oem_id),
software_name: data
.get("software_name")
.and_then(|v| v.as_str())
.unwrap_or("")
.to_string(),
logo_url: data
.get("logo_url")
.and_then(|v| v.as_str())
.filter(|s| !s.is_empty())
.map(str::to_string),
wechat: data
.get("wechat")
.and_then(|v| v.as_str())
.filter(|s| !s.is_empty())
.map(str::to_string),
}
}
#[tauri::command]
pub async fn get_software_info(ctx: State<'_, OemContext>) -> Result<SoftwareInfo, String> {
let oem_id = ctx.oem_id;
let path = format!("/public/oem-branding/{oem_id}");
let (status, value) =
api_client::request_json("GET", &path, None, HashMap::new()).await?;
if status >= 400 {
return Ok(empty_info(oem_id));
}
if value.get("ok").and_then(|v| v.as_bool()) == Some(false) {
return Ok(empty_info(oem_id));
}
Ok(parse_software_info(oem_id, &value))
}