11
This commit is contained in:
@@ -262,24 +262,11 @@ fn api_base() -> String {
|
||||
}
|
||||
|
||||
async fn fetch_node_script_source(script_name: &str) -> Result<String, NodeError> {
|
||||
let base = api_base().trim_end_matches('/').to_string();
|
||||
let q = urlencoding::encode(script_name);
|
||||
let url = format!("{base}/api/v1/nodejs-scripts?name={q}");
|
||||
let client = reqwest::Client::builder()
|
||||
.timeout(std::time::Duration::from_secs(120))
|
||||
.build()
|
||||
.map_err(|e| NodeError::FetchScript(e.to_string()))?;
|
||||
let res = client
|
||||
.get(&url)
|
||||
.send()
|
||||
let path = format!("/nodejs-scripts?name={q}");
|
||||
let (_status, v) = crate::api_client::request_json("GET", &path, None, HashMap::new())
|
||||
.await
|
||||
.map_err(|e| NodeError::FetchScript(e.to_string()))?;
|
||||
let body = res
|
||||
.text()
|
||||
.await
|
||||
.map_err(|e| NodeError::FetchScript(e.to_string()))?;
|
||||
let v: Value = serde_json::from_str(&body)
|
||||
.map_err(|e| NodeError::FetchScript(format!("响应非 JSON: {e}")))?;
|
||||
.map_err(|e| NodeError::FetchScript(e))?;
|
||||
if !v.get("ok").and_then(|x| x.as_bool()).unwrap_or(false) {
|
||||
let msg = v
|
||||
.get("message")
|
||||
@@ -297,23 +284,10 @@ async fn fetch_node_script_source(script_name: &str) -> Result<String, NodeError
|
||||
|
||||
/// 后端 `scripts/nodejs` 目录下的 `.js` 文件名列表。
|
||||
pub async fn list_scripts() -> Result<Vec<String>, NodeError> {
|
||||
let base = api_base().trim_end_matches('/').to_string();
|
||||
let url = format!("{base}/api/v1/nodejs-scripts/list");
|
||||
let client = reqwest::Client::builder()
|
||||
.timeout(std::time::Duration::from_secs(30))
|
||||
.build()
|
||||
.map_err(|e| NodeError::FetchScript(e.to_string()))?;
|
||||
let res = client
|
||||
.get(&url)
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| NodeError::FetchScript(e.to_string()))?;
|
||||
let body = res
|
||||
.text()
|
||||
.await
|
||||
.map_err(|e| NodeError::FetchScript(e.to_string()))?;
|
||||
let v: Value = serde_json::from_str(&body)
|
||||
.map_err(|e| NodeError::FetchScript(format!("响应非 JSON: {e}")))?;
|
||||
let (_status, v) =
|
||||
crate::api_client::request_json("GET", "/nodejs-scripts/list", None, HashMap::new())
|
||||
.await
|
||||
.map_err(|e| NodeError::FetchScript(e))?;
|
||||
if !v.get("ok").and_then(|x| x.as_bool()).unwrap_or(false) {
|
||||
let msg = v
|
||||
.get("message")
|
||||
|
||||
Reference in New Issue
Block a user