mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-17 07:30:41 +09:00
* Move saveJson to util file * Add button to download ctl config * Add icon and tooltip to describe what the button does --------- Co-authored-by: Danielv123 <danielv@danielv.no>
26 lines
865 B
TypeScript
26 lines
865 B
TypeScript
|
|
/**
|
|
* Downloads a file to the users PC, should only be used following direct user input.
|
|
* @param name Name of the file to save
|
|
* @param blob Content to save
|
|
*/
|
|
export function saveFile(name: string, blob: Blob) {
|
|
// This is the most common and best supported method, for full support we should consider using npm:file-saver
|
|
const a = document.createElement("a");
|
|
a.href = URL.createObjectURL(blob);
|
|
a.download = name;
|
|
a.addEventListener("click", (e) => {
|
|
setTimeout(() => URL.revokeObjectURL(a.href), 30 * 1000);
|
|
});
|
|
a.click();
|
|
};
|
|
|
|
/**
|
|
* Downloads a json file to the users PC
|
|
* @param name Name of the file to save, should include .json
|
|
* @param json The object to save as a formated json string
|
|
*/
|
|
export function saveJson(name: string, json: object) {
|
|
saveFile(name, new Blob([JSON.stringify(json, null, 2)], { type: "application/json" }));
|
|
}
|