mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-09-16 23:01:31 +02:00
Export a workspace without needing a filesystem (#685)
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
a8c845b091
commit
77b18d3477
@@ -1,18 +1,20 @@
|
||||
use crate::Result;
|
||||
use std::fs::File;
|
||||
use std::path::Path;
|
||||
use yaak_models::query_manager::QueryManager;
|
||||
use yaak_models::util::get_workspace_export_resources;
|
||||
|
||||
pub struct ExportDataParams<'a> {
|
||||
pub query_manager: &'a QueryManager,
|
||||
pub yaak_version: &'a str,
|
||||
pub export_path: &'a Path,
|
||||
pub workspace_ids: Vec<&'a str>,
|
||||
pub include_private_environments: bool,
|
||||
}
|
||||
|
||||
pub fn export_data(params: ExportDataParams<'_>) -> Result<()> {
|
||||
/// The export document, as JSON.
|
||||
///
|
||||
/// Returned rather than written: where an export goes is the host's to decide, and a browser
|
||||
/// tab has no path to be handed. The desktop hands the bytes to its save dialog; a tab hands
|
||||
/// them to a download. Neither needs this function to know which.
|
||||
pub fn export_data(params: ExportDataParams<'_>) -> Result<String> {
|
||||
let db = params.query_manager.connect();
|
||||
let export_data = get_workspace_export_resources(
|
||||
&db,
|
||||
@@ -21,9 +23,5 @@ pub fn export_data(params: ExportDataParams<'_>) -> Result<()> {
|
||||
params.include_private_environments,
|
||||
)?;
|
||||
|
||||
let file = File::options().create(true).truncate(true).write(true).open(params.export_path)?;
|
||||
serde_json::to_writer_pretty(&file, &export_data)?;
|
||||
file.sync_all()?;
|
||||
|
||||
Ok(())
|
||||
Ok(serde_json::to_string_pretty(&export_data)?)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user