diff options
Diffstat (limited to 'g4f/gui/client/js')
-rw-r--r-- | g4f/gui/client/js/chat.v1.js | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/g4f/gui/client/js/chat.v1.js b/g4f/gui/client/js/chat.v1.js index 59d0351a..24253b2b 100644 --- a/g4f/gui/client/js/chat.v1.js +++ b/g4f/gui/client/js/chat.v1.js @@ -913,8 +913,21 @@ fileInput.addEventListener('change', async (event) => { } fileInput.dataset.type = type const reader = new FileReader(); - reader.addEventListener('load', (event) => { + reader.addEventListener('load', async (event) => { fileInput.dataset.text = event.target.result; + if (type == "json") { + const data = JSON.parse(event.target.result); + if ("g4f" in data.options) { + Object.keys(data).forEach(key => { + if (key != "options" && !localStorage.getItem(key)) { + appStorage.setItem(key, JSON.stringify(data[key])); + } + }); + fileInput.value = ""; + delete fileInput.dataset.text; + await load_conversations(); + } + } }); reader.readAsText(fileInput.files[0]); } else { @@ -953,4 +966,31 @@ async function load_provider_models() { modelSelect.classList.remove("hidden"); } }; -providerSelect.addEventListener("change", load_provider_models)
\ No newline at end of file +providerSelect.addEventListener("change", load_provider_models) + +function save_storage() { + let filename = new Date().toLocaleString() + filename += ".json" + let data = {"options": {"g4f": ""}}; + for (let i = 0; i < appStorage.length; i++){ + let key = appStorage.key(i); + let item = appStorage.getItem(key); + if (key.startsWith("conversation:")) { + data[key] = JSON.parse(item); + } else { + data["options"][key] = item; + } + } + data = JSON.stringify(data, null, 4); + const blob = new Blob([data], {type: 'text/csv'}); + if(window.navigator.msSaveOrOpenBlob) { + window.navigator.msSaveBlob(blob, filename); + } else{ + const elem = window.document.createElement('a'); + elem.href = window.URL.createObjectURL(blob); + elem.download = filename; + document.body.appendChild(elem); + elem.click(); + document.body.removeChild(elem); + } +}
\ No newline at end of file |