Skip to content

Commit

Permalink
feat(gui): add profile download button
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Jul 22, 2023
1 parent f14f197 commit a6e0461
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion gui/src/components/Profiles.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { InvalidArgumentError, Maybe, doesExist, mustExist } from '@apextoaster/js-utils';
import { Delete as DeleteIcon, ImageSearch, Save as SaveIcon } from '@mui/icons-material';
import { Delete as DeleteIcon, Download, ImageSearch, Save as SaveIcon } from '@mui/icons-material';
import {
Autocomplete,
Button,
Expand Down Expand Up @@ -153,6 +153,11 @@ export function Profiles(props: ProfilesProps) {
}}
/>
</Button>
<Button component='label' variant='contained' onClick={() => {
downloadParamsAsFile(props.params);
}}>
<Download />
</Button>
</Stack>;
}

Expand All @@ -174,6 +179,21 @@ export async function loadParamsFromFile(file: File): Promise<Partial<Txt2ImgPar
}
}

/**
* from https://stackoverflow.com/a/30800715
*/
export function downloadParamsAsFile(params: Txt2ImgParams): void {
const dataStr = 'data:text/json;charset=utf-8,' + encodeURIComponent(JSON.stringify({
params,
}));
const elem = document.createElement('a');
elem.setAttribute('href', dataStr);
elem.setAttribute('download', 'parameters.json');
document.body.appendChild(elem); // required for firefox
elem.click();
elem.remove();
}

export async function parseImageParams(file: File): Promise<Partial<Txt2ImgParams>> {
const tags = await ExifReader.load(file);

Expand Down

0 comments on commit a6e0461

Please sign in to comment.