Skip to content

Commit 0adcdc0

Browse files
committed
handle promise and prompt success
1 parent ad34c9b commit 0adcdc0

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

src/background.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,23 @@ ipcMain.handle("upload", async (event, { MongoDB_URL, data }) => {
316316
// eslint-disable-next-line no-debugger
317317
// debugger;
318318
const client = new MongoClient(MongoDB_URL);
319-
320-
client.connect();
321-
322-
const collection = client.db("test").collection("dialogs");
323-
// const chunks = chunkify(data); // 将大对象拆分成块
324-
collection.insertOne(data);
319+
return client
320+
.connect()
321+
.then(() => {
322+
// eslint-disable-next-line no-debugger
323+
// debugger;
324+
const collection = client.db("test").collection("dialogs");
325+
// const chunks = chunkify(data); // 将大对象拆分成块
326+
return collection.insertOne(data);
327+
})
328+
.then(() => {
329+
// eslint-disable-next-line no-debugger
330+
// debugger;
331+
return true;
332+
})
333+
.catch(() => {
334+
return false;
335+
});
325336
});
326337
ipcMain.handle("download", async (event, MongoDB_URL) => {
327338
// eslint-disable-next-line no-debugger

src/components/ChatSetting.vue

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,17 @@
5555
</v-btn>
5656
</v-list-item>
5757
<ConfirmModal ref="confirmModal" />
58+
<v-snackbar
59+
v-model="snackbar.show"
60+
:timeout="snackbar.timeout"
61+
:color="snackbar.color"
62+
>
63+
{{ snackbar.text }}
64+
</v-snackbar>
5865
</template>
5966

6067
<script setup>
61-
import { ref } from "vue";
68+
import { ref, reactive } from "vue";
6269
import { useStore } from "vuex";
6370
import i18n from "@/i18n";
6471
const electron = window.require("electron");
@@ -71,7 +78,12 @@ const confirmModal = ref();
7178
const store = useStore();
7279
const jsonData = ref(null);
7380
const MongoDB_URL = ref(store.state.MongoDB_URL);
74-
81+
const snackbar = reactive({
82+
show: false,
83+
text: "",
84+
timeout: 1500,
85+
color: "success",
86+
});
7587
const setMongoDBURL = (url) => {
7688
store.commit("setMongoDBURL", url);
7789
};
@@ -82,10 +94,18 @@ async function upload() {
8294
);
8395
if (result) {
8496
const data = JSON.parse(JSON.stringify(localStorage, null, 2));
85-
await ipcRenderer.invoke("upload", {
97+
// don't know why there's _id prop in localStorage that would lead to duplicate key error
98+
delete data._id;
99+
const is_success = await ipcRenderer.invoke("upload", {
86100
MongoDB_URL: MongoDB_URL.value,
87101
data,
88102
});
103+
if (is_success) {
104+
snackbar.text = i18n.global.t("proxy.saveSuccess");
105+
snackbar.color = "success";
106+
snackbar.timeout = 1000;
107+
snackbar.show = true;
108+
}
89109
}
90110
}
91111
async function download() {

0 commit comments

Comments
 (0)