summaryrefslogtreecommitdiffstats
path: root/g4f/gui/client/js
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-03-14 18:49:41 +0100
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-03-14 18:49:41 +0100
commit95b1b8c02574faacd520d8fd539a1e1d93035aa2 (patch)
tree86df2f5121e611ac910c71ddc79704118b9b4a93 /g4f/gui/client/js
parentFilter not working provider from RetryProvider (diff)
downloadgpt4free-95b1b8c02574faacd520d8fd539a1e1d93035aa2.tar
gpt4free-95b1b8c02574faacd520d8fd539a1e1d93035aa2.tar.gz
gpt4free-95b1b8c02574faacd520d8fd539a1e1d93035aa2.tar.bz2
gpt4free-95b1b8c02574faacd520d8fd539a1e1d93035aa2.tar.lz
gpt4free-95b1b8c02574faacd520d8fd539a1e1d93035aa2.tar.xz
gpt4free-95b1b8c02574faacd520d8fd539a1e1d93035aa2.tar.zst
gpt4free-95b1b8c02574faacd520d8fd539a1e1d93035aa2.zip
Diffstat (limited to 'g4f/gui/client/js')
-rw-r--r--g4f/gui/client/js/chat.v1.js44
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