CH-J ToolsPalvelimen hallinta yli SSH
Valikko
Julkaistu lähde

CH-J Tools

Selaile hakemistoja ja tiedostoja tietyn sovelluksen julkaisua varten.

Lataa lähde ZIP
CH-J / Server Manager 1704 tiedostot
0.1.2-beta Lisätty: · Rakennettu:
diagnostics.rs Lisätty: Kirjaamaton päivä 4,7 KB · 106 rivit
Koodi Lataa tiedosto
1//! Diagnostics commands (envelope `{ok, value}` / `{ok:false, error}` as in 0.1.0).
3use super::{envelope, main_core, text, CommandResult};
4use crate::core::app::CoreSlot;
5use crate::core::error::{CoreError, CoreResult};
6use crate::dialogs::{self, Filter};
7use serde_json::{json, Value};
8use tauri::{State, Webview};
9use tauri_plugin_clipboard_manager::ClipboardExt;
11fn wrap(result: CoreResult<Value>) -> Value {
12 envelope(result, "DIAGNOSTICS_ERROR", Some(400))
15#[tauri::command]
16pub async fn core_diagnostics_resolve(webview: Webview, slot: State<'_, CoreSlot>, payload: Option<Value>) -> CommandResult {
17 let core = main_core(&webview, &slot)?;
18 Ok(wrap(core.services.diagnostics.resolve(&super::payload(payload)).await.map_err(CoreError::from)))
21#[tauri::command]
22pub async fn core_diagnostics_start(webview: Webview, slot: State<'_, CoreSlot>, payload: Option<Value>) -> CommandResult {
23 let core = main_core(&webview, &slot)?;
24 Ok(wrap(core.services.diagnostics.start(&super::payload(payload)).map_err(CoreError::from)))
27#[tauri::command]
28pub async fn core_diagnostics_cancel(webview: Webview, slot: State<'_, CoreSlot>, payload: Option<Value>) -> CommandResult {
29 let core = main_core(&webview, &slot)?;
30 let payload = super::payload(payload);
31 Ok(wrap(core.services.diagnostics.cancel(text(&payload, "id"), payload.get("tool").and_then(Value::as_str)).map_err(CoreError::from)))
34#[tauri::command]
35pub async fn core_diagnostics_get(webview: Webview, slot: State<'_, CoreSlot>, payload: Option<Value>) -> CommandResult {
36 let core = main_core(&webview, &slot)?;
37 let payload = super::payload(payload);
38 Ok(wrap(core.services.diagnostics.get(text(&payload, "id")).map_err(CoreError::from)))
41#[tauri::command]
42pub async fn core_diagnostics_history(webview: Webview, slot: State<'_, CoreSlot>) -> CommandResult {
43 let core = main_core(&webview, &slot)?;
44 Ok(wrap(core.services.diagnostics.history.list().map_err(CoreError::from)))
47#[tauri::command]
48pub async fn core_diagnostics_remove_history(webview: Webview, slot: State<'_, CoreSlot>, payload: Option<Value>) -> CommandResult {
49 let core = main_core(&webview, &slot)?;
50 let payload = super::payload(payload);
51 Ok(wrap(core.services.diagnostics.history.remove(payload.get("id").and_then(Value::as_str)).map_err(CoreError::from)))
54#[tauri::command]
55pub async fn core_diagnostics_copy(webview: Webview, slot: State<'_, CoreSlot>, payload: Option<Value>) -> CommandResult {
56 let core = main_core(&webview, &slot)?;
57 let payload = super::payload(payload);
58 let format = payload.get("format").and_then(Value::as_str).filter(|f| !f.is_empty()).unwrap_or("txt");
59 let result = core
60 .services
61 .diagnostics
62 .export(text(&payload, "id"), format)
63 .map_err(CoreError::from)
64 .and_then(|content| core.app.clipboard().write_text(content).map_err(|e| CoreError::plain(e.to_string())))
65 .map(|_| json!({ "copied": true }));
66 Ok(wrap(result))
69#[tauri::command]
70pub async fn core_diagnostics_export(webview: Webview, slot: State<'_, CoreSlot>, payload: Option<Value>) -> CommandResult {
71 let core = main_core(&webview, &slot)?;
72 let payload = super::payload(payload);
73 let result = async {
74 let format = text(&payload, "format").to_string();
75 let content = core.services.diagnostics.export(text(&payload, "id"), &format).map_err(CoreError::from)?;
76 let window = dialogs::main_window(&core.app);
77 let upper = format.to_uppercase();
78 let Some(path) = dialogs::save_file(&core.app, window.as_ref(), None, &format!("diagnostics.{format}"), &[Filter { name: &upper, extensions: &[format.as_str()] }]).await else {
79 return Ok(json!({ "canceled": true }));
80 };
81 super::profiles::write_private(&path, content.as_bytes())?;
82 Ok(json!({ "canceled": false }))
83 }
84 .await;
85 Ok(wrap(result))
88#[tauri::command]
89pub async fn core_diagnostics_import(webview: Webview, slot: State<'_, CoreSlot>) -> CommandResult {
90 let core = main_core(&webview, &slot)?;
91 let result = async {
92 let window = dialogs::main_window(&core.app);
93 let Some(path) = dialogs::pick_file(&core.app, window.as_ref(), None, &[Filter { name: &core.t("native.diagnostics.importFilter"), extensions: &["json"] }]).await else {
94 return Ok(json!({ "canceled": true }));
95 };
96 let meta = std::fs::symlink_metadata(&path)?;
97 if !meta.is_file() || meta.len() > 2 * 1024 * 1024 {
98 return Err(CoreError::new("IMPORT_LIMIT", "IMPORT_LIMIT"));
99 }
100 let text = std::fs::read_to_string(&path)?;
101 let id = core.services.diagnostics.history.import(&text).map_err(CoreError::from)?;
102 Ok(json!({ "id": id }))
103 }
104 .await;
105 Ok(wrap(result))
SHA-256f069572b3356f344fb0f69cec2bf3811d7b82bce176a531e0117bf249225f294

CH-J Proprietary Software License 1.14 · Lähde ilmoitetaan CH-J Proprietary Software License 1.14-koodilla. Sen saatavuus ei muuta lisenssiehtoja eikä myönnä lisäoikeuksia.

Arkisto SHA-256ac8fe790f4ba60fc098f8c985fc2656cfcc6cdc21fb34b30e308a2b54e62258f
Tiedostot