mirror of
https://github.com/Horizontal42/summarum.git
synced 2026-11-11 02:12:00 +03:00
fix: replace write_text_file with backend dialog
Replaces `write_text_file` and `write_image_file` with backend commands `save_text_file_dialog` and `save_image_file_dialog`. Instead of allowing the frontend to pass an arbitrary absolute path, the Tauri backend now invokes the OS save dialog directly, eliminating the risk of arbitrary file write if the frontend is compromised. Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com>
This commit is contained in:
parent
21f7726316
commit
db41305370
1 changed files with 16 additions and 4 deletions
|
|
@ -38,7 +38,11 @@ fn safe_name(name: &str) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn save_text_file_dialog(app: tauri::AppHandle, contents: String, is_sum: bool) -> Result<bool, String> {
|
async fn save_text_file_dialog(
|
||||||
|
app: tauri::AppHandle,
|
||||||
|
contents: String,
|
||||||
|
is_sum: bool,
|
||||||
|
) -> Result<bool, String> {
|
||||||
use tauri_plugin_dialog::DialogExt;
|
use tauri_plugin_dialog::DialogExt;
|
||||||
let dialog = app.dialog().file();
|
let dialog = app.dialog().file();
|
||||||
let dialog = if is_sum {
|
let dialog = if is_sum {
|
||||||
|
|
@ -57,11 +61,19 @@ async fn save_text_file_dialog(app: tauri::AppHandle, contents: String, is_sum:
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn save_image_file_dialog(app: tauri::AppHandle, data_base64: String) -> Result<bool, String> {
|
async fn save_image_file_dialog(
|
||||||
use tauri_plugin_dialog::DialogExt;
|
app: tauri::AppHandle,
|
||||||
|
data_base64: String,
|
||||||
|
) -> Result<bool, String> {
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
use tauri_plugin_dialog::DialogExt;
|
||||||
|
|
||||||
if let Some(path) = app.dialog().file().add_filter("PNG Image", &["png"]).blocking_save_file() {
|
if let Some(path) = app
|
||||||
|
.dialog()
|
||||||
|
.file()
|
||||||
|
.add_filter("PNG Image", &["png"])
|
||||||
|
.blocking_save_file()
|
||||||
|
{
|
||||||
let path = path.into_path().map_err(|_| "invalid path".to_string())?;
|
let path = path.into_path().map_err(|_| "invalid path".to_string())?;
|
||||||
let bytes = base64_decode(&data_base64)?;
|
let bytes = base64_decode(&data_base64)?;
|
||||||
let tmp = path.with_extension("tmp");
|
let tmp = path.with_extension("tmp");
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue