update: allow sheet unknown endpoint if provided
- feat: multi files commit Signed-off-by: Pakin <pakin.t@forth.co.th>
This commit is contained in:
parent
0f857445a4
commit
fa62d9d83f
6 changed files with 108 additions and 21 deletions
36
src/app.rs
36
src/app.rs
|
|
@ -349,6 +349,42 @@ pub async fn invoke_commit_request(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Invoke sending from server to server for committing case multiple files
|
||||
pub async fn invoke_commit_multiple_files_request(
|
||||
config: DevConfig,
|
||||
payloads: Vec<CommitPayload>,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let client = reqwest::Client::new();
|
||||
let commit_path = config.get_post_file_to_recipe_repo();
|
||||
let mut form = multipart::Form::new()
|
||||
.text("message", payloads.first().unwrap().message.clone())
|
||||
.text(
|
||||
"signature_username",
|
||||
payloads.first().unwrap().signature_username.clone(),
|
||||
)
|
||||
.text(
|
||||
"signature_email",
|
||||
payloads.first().unwrap().signature_email.clone(),
|
||||
);
|
||||
|
||||
for (index, payload) in payloads.iter().enumerate() {
|
||||
form = form
|
||||
.text(format!("path{index}"), payload.path.clone())
|
||||
.part(
|
||||
format!("file{index}"),
|
||||
multipart::Part::bytes(payload.file_bytes.clone())
|
||||
.mime_str("application/octet-stream")
|
||||
.unwrap(),
|
||||
);
|
||||
}
|
||||
|
||||
let response = client.post(commit_path).multipart(form).send().await?;
|
||||
|
||||
info!("commit status: {}", response.status());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn invoke_push_request(config: DevConfig) -> Result<String, Box<dyn std::error::Error>> {
|
||||
let client = reqwest::Client::new();
|
||||
|
||||
|
|
|
|||
|
|
@ -102,7 +102,8 @@ pub struct LogReportPayload {
|
|||
/// Message for saving recipe
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct SaveRecipePayload {
|
||||
pub user: String,
|
||||
/// User info expect at least id, token, name
|
||||
pub user_info: serde_json::Value,
|
||||
pub country: String,
|
||||
pub values: serde_json::Value,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -111,15 +111,15 @@ pub async fn read(
|
|||
//
|
||||
let now = Instant::now();
|
||||
}
|
||||
"save_recipe" if let Some(save_recipe_payload) = req.payload => {
|
||||
let save_recipe_payload: SaveRecipePayload =
|
||||
match serde_json::from_value(save_recipe_payload) {
|
||||
Ok(lreq) => lreq,
|
||||
Err(e) => {
|
||||
error!("error deserialize body log request: {e:?} ---> Skip");
|
||||
continue;
|
||||
}
|
||||
};
|
||||
"save_recipe" if req.payload.is_some() => {
|
||||
tasks::recipe::handle_recipe_save_change_request(
|
||||
config.clone(),
|
||||
redis.clone(),
|
||||
tx.clone(),
|
||||
req,
|
||||
uid_clone.clone(),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
"auth" if req.payload.is_some() => {
|
||||
tasks::auth::handle_auth_request(
|
||||
|
|
|
|||
|
|
@ -307,19 +307,20 @@ pub async fn handle_price_request(
|
|||
message: action_message,
|
||||
};
|
||||
|
||||
if invoke_pull_sync_request(config.clone()).await.is_err() {
|
||||
// backup
|
||||
let _ = commit_payload.dump_backup();
|
||||
return Err("Fail to sync repo, backing up ...".into());
|
||||
}
|
||||
// if invoke_pull_sync_request(config.clone()).await.is_err() {
|
||||
// // backup
|
||||
// let _ = commit_payload.dump_backup();
|
||||
// return Err("Fail to sync repo, backing up ...".into());
|
||||
// }
|
||||
|
||||
let _ = invoke_commit_request(config.clone(), commit_payload.clone()).await;
|
||||
// let _ = invoke_commit_request(config.clone(), commit_payload.clone()).await;
|
||||
|
||||
if invoke_push_request(config.clone()).await.is_err() {
|
||||
let _ = commit_payload.dump_backup();
|
||||
return Err("Fail to push repo, backing up ...".into());
|
||||
}
|
||||
// if invoke_push_request(config.clone()).await.is_err() {
|
||||
// let _ = commit_payload.dump_backup();
|
||||
// return Err("Fail to push repo, backing up ...".into());
|
||||
// }
|
||||
|
||||
let _ = commit_payload.dump_backup();
|
||||
// push to git
|
||||
} else {
|
||||
let _ = tx
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use std::{fs::File, io::Read, path::PathBuf, sync::Arc};
|
|||
|
||||
use async_compression::tokio::bufread::BrotliDecoder;
|
||||
use axum::extract::ws::{Message, WebSocket};
|
||||
use chrono::{DateTime, Local, NaiveDateTime};
|
||||
use futures::{
|
||||
SinkExt, StreamExt,
|
||||
stream::{SplitSink, SplitStream},
|
||||
|
|
@ -416,3 +417,51 @@ pub async fn handle_recipe_versions_list_request(
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn handle_recipe_save_change_request(
|
||||
config: DevConfig,
|
||||
redis: redis::Client,
|
||||
tx: Sender<TxControlMessage>,
|
||||
req: WebsocketMessageRequest,
|
||||
uid_clone: Arc<Mutex<String>>,
|
||||
) -> WebsocketMessageResult {
|
||||
let timestamp = Local::now();
|
||||
|
||||
let p = req.payload.unwrap();
|
||||
let save_recipe_param: SaveRecipePayload = serde_json::from_value(p)?;
|
||||
|
||||
let single_recipe = serde_json::to_string_pretty(&save_recipe_param.values)?;
|
||||
|
||||
let display_name = save_recipe_param
|
||||
.user_info
|
||||
.get("displayName")
|
||||
.unwrap_or_default()
|
||||
.as_str()
|
||||
.unwrap_or(&"unknown".to_string())
|
||||
.to_string();
|
||||
|
||||
let email = save_recipe_param
|
||||
.user_info
|
||||
.get("email")
|
||||
.unwrap_or_default()
|
||||
.as_str()
|
||||
.unwrap_or(&"unknown".to_string())
|
||||
.to_string();
|
||||
|
||||
let expected_file_path = format!(
|
||||
"{}/part_coffeethai02_{}_{}.json",
|
||||
save_recipe_param.country,
|
||||
display_name,
|
||||
timestamp.timestamp()
|
||||
);
|
||||
|
||||
let commit_payload = CommitPayload {
|
||||
file_bytes: single_recipe.as_bytes().to_vec(),
|
||||
path: expected_file_path.clone(),
|
||||
signature_username: display_name,
|
||||
signature_email: email,
|
||||
message: format!("resolve-{expected_file_path}"),
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ pub async fn handle_sheet_request(
|
|||
"get_all_catalogs" => "catalogs",
|
||||
"get_catalog" | "enter" => "enter",
|
||||
"heartbeat" => "heartbeat",
|
||||
_ => "junk",
|
||||
_ => pm,
|
||||
}
|
||||
} else {
|
||||
"junk"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue