Skip to content

Commit

Permalink
add flag for BOS Web Engine compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
mpeterdev committed Nov 2, 2023
1 parent b590e87 commit 5f9e07b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ struct Args {
/// Use config file in current dir (./.bos-loader.toml) to set account_id and path, causes other args to be ignored
#[arg(short = 'c')]
use_config: bool,
/// Run in BOS Web Engine mode
#[arg(short = 'w')]
web_engine: bool,
/// Path to file with replacements map
#[clap(short, long, value_hint = clap::ValueHint::DirPath)]
replacements: Option<PathBuf>,
Expand All @@ -54,6 +57,7 @@ fn handle_request(
account_id: &str,
path: PathBuf,
replacements_map: &HashMap<String, String>,
web_engine: &bool,
) -> HashMap<String, ComponentCode> {
let mut components = HashMap::new();
get_file_list(
Expand All @@ -62,6 +66,7 @@ fn handle_request(
&mut components,
String::from(""),
replacements_map,
web_engine,
);
components
}
Expand Down Expand Up @@ -120,6 +125,7 @@ fn get_file_list(
components: &mut HashMap<String, ComponentCode>,
prefix: String,
replacements_map: &HashMap<String, String>,
web_engine: &bool,
) {
let paths = fs::read_dir(path).unwrap();
for path_res in paths {
Expand All @@ -133,6 +139,7 @@ fn get_file_list(
components,
prefix.to_owned() + &file_name + ".",
replacements_map,
web_engine,
);
continue;
}
Expand All @@ -146,7 +153,8 @@ fn get_file_list(
}

let fkey = file_key.join(".");
let key = format!("{account_id}/widget/{prefix}{fkey}");
let join_string = if *web_engine { "/" } else { "/widget/" };
let key = format!("{account_id}{join_string}{prefix}{fkey}");
let mut file = fs::File::open(&file_path).unwrap();
let mut contents = String::new();
file.read_to_string(&mut contents).unwrap();
Expand Down Expand Up @@ -199,6 +207,7 @@ async fn main() {
&account_path.account,
account_path.path.to_owned(),
&replacements_map,
&args.web_engine,
));
}
warp::reply::json(&FileList { components })
Expand Down

0 comments on commit 5f9e07b

Please sign in to comment.