mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-03 10:11:15 +02:00
* fix(core): fix raw invoke body for isolation pattern The `isolation` pattern requests are made using JSON but the payload could be raw bytes, so we send the original `Content-Type` from frontend and make sure to deserialize the payload using that one instead of `Content-Type` from request headers * clippy * disable plist embed in generate_context in tests * change file * docs [skip ci] * move unused_variables [skip ci] * last commit regression [skip ci] * fix test * add example, do not text encode raw request * check type instead of contenttype --------- Co-authored-by: Lucas Nogueira <lucas@tauri.app>
53 lines
1.2 KiB
Rust
53 lines
1.2 KiB
Rust
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
use tauri::{command, ipc::CommandScope};
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
#[allow(unused)]
|
|
pub struct RequestBody {
|
|
id: i32,
|
|
name: String,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
pub struct LogScope {
|
|
event: String,
|
|
}
|
|
|
|
#[command]
|
|
pub fn log_operation(
|
|
event: String,
|
|
payload: Option<String>,
|
|
command_scope: CommandScope<LogScope>,
|
|
) -> Result<(), &'static str> {
|
|
if command_scope.denies().iter().any(|s| s.event == event) {
|
|
Err("denied")
|
|
} else if !command_scope.allows().iter().any(|s| s.event == event) {
|
|
Err("not allowed")
|
|
} else {
|
|
log::info!("{} {:?}", event, payload);
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
#[derive(Serialize)]
|
|
pub struct ApiResponse {
|
|
message: String,
|
|
}
|
|
|
|
#[command]
|
|
pub fn perform_request(endpoint: String, body: RequestBody) -> ApiResponse {
|
|
println!("{} {:?}", endpoint, body);
|
|
ApiResponse {
|
|
message: "message response".into(),
|
|
}
|
|
}
|
|
|
|
#[command]
|
|
pub fn echo(request: tauri::ipc::Request<'_>) -> tauri::ipc::Response {
|
|
tauri::ipc::Response::new(request.body().clone())
|
|
}
|