1
0
Fork 0

feat(gui): add profile download button

This commit is contained in:
Sean Sube 2023-07-21 19:33:16 -05:00
parent f14f197264
commit a6e04611f2
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
1 changed files with 21 additions and 1 deletions

View File

@ -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,
@ -153,6 +153,11 @@ export function Profiles(props: ProfilesProps) {
}}
/>
</Button>
<Button component='label' variant='contained' onClick={() => {
downloadParamsAsFile(props.params);
}}>
<Download />
</Button>
</Stack>;
}
@ -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);