Skip to content

Commit

Permalink
Merge pull request #84 from center-for-threat-informed-defense/AF-142…
Browse files Browse the repository at this point in the history
…_limit_file_picker

AF-142 Limit File Picker to Configured File Extension
  • Loading branch information
mehaase committed Jul 18, 2023
2 parents ab8eb90 + a14e7b7 commit aee690d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/attack_flow_builder/src/assets/scripts/Browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,19 @@ export class Browser {

/**
* Prompts the user to select a text file from their file system.
* @param fileTypes
* The file dialog's accepted file types.
* @returns
* A Promise that resolves with the chosen text file.
*/
public static openTextFileDialog(): Promise<TextFile> {
public static openTextFileDialog(...fileTypes: string[]): Promise<TextFile> {

// Create file input
let fileInput = document.createElement("input");
fileInput.type = "file";
if(0 < fileTypes.length) {
fileInput.accept = fileTypes.map(o => `.${o}`).join(",");
}

// Configure file input
let result = new Promise<TextFile>((resolve) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export class LoadFile extends AppCommand {
* The {@link LoadFile} command.
*/
public static async fromFileSystem(context: ApplicationStore): Promise<LoadFile> {
let file = (await Browser.openTextFileDialog()).contents as string;
let ext = Configuration.file_type_extension;
let file = (await Browser.openTextFileDialog(ext)).contents as string;
let page = await PageEditor.fromFile(file);
return new LoadFile(context, page);
}
Expand Down

0 comments on commit aee690d

Please sign in to comment.