|
@@ -6,7 +6,7 @@ import { getLocalToken, removeLocalToken, saveLocalToken } from "@/utils";
|
|
|
import type { AppNotification } from '@/interfaces';
|
|
|
import type { IUserProfile, IUserProfileCreate, IUserProfileUpdate, MainState, Video, VideoCreate, ArticleCreate, Image, ImageDownload } from '@/interfaces';
|
|
|
import i18n from '@/plugins/i18n'
|
|
|
-import WS from "@/stores/ws";
|
|
|
+import { wsUrl } from "@/env";
|
|
|
|
|
|
const defaultState: MainState = {
|
|
|
isLoggedIn: null,
|
|
@@ -259,8 +259,8 @@ export const useMainStore = defineStore("MainStoreId", {
|
|
|
async uploadImage(file: File[]) {
|
|
|
const mainStore = useMainStore();
|
|
|
try {
|
|
|
- const loadingNotification = { content: i18n.global.t("sending"), showProgress: true };
|
|
|
- mainStore.addNotification(loadingNotification);
|
|
|
+ // const loadingNotification = { content: i18n.global.t("sending"), showProgress: true };
|
|
|
+ // mainStore.addNotification(loadingNotification);
|
|
|
const response = (
|
|
|
await Promise.all([
|
|
|
api.uploadImage(mainStore.token, file),
|
|
@@ -279,7 +279,7 @@ export const useMainStore = defineStore("MainStoreId", {
|
|
|
// localStorage.setItem('imagesList', JSON.stringify(this.images));
|
|
|
})
|
|
|
);
|
|
|
- mainStore.removeNotification(loadingNotification);
|
|
|
+ // mainStore.removeNotification(loadingNotification);
|
|
|
mainStore.addNotification({
|
|
|
content: i18n.global.t("fileReceived"),
|
|
|
color: "success",
|
|
@@ -306,8 +306,9 @@ export const useMainStore = defineStore("MainStoreId", {
|
|
|
this.images.push(payload);
|
|
|
},
|
|
|
finishImage(payload: string) {
|
|
|
+ const WS = new WebSocket(`${wsUrl}/api/v1/images/sr`);
|
|
|
let image = this.images.filter(e => {
|
|
|
- return e.stored_file_name === payload
|
|
|
+ return payload.includes(e.stored_file_name)
|
|
|
});
|
|
|
|
|
|
if (image) {
|
|
@@ -316,13 +317,16 @@ export const useMainStore = defineStore("MainStoreId", {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- // 全部完成後關閉 WebSocket
|
|
|
- // let processing = this.images.find(e => e.state !== "completed")
|
|
|
- // if (!processing) {
|
|
|
- // setTimeout(() => {
|
|
|
- // WS.close();
|
|
|
- // }, 1000)
|
|
|
- // }
|
|
|
+ // 全部完成後回傳 WebSocket
|
|
|
+ let processing = this.images.find(e => e.state !== "completed");
|
|
|
+ console.log('processing', processing);
|
|
|
+
|
|
|
+ if (!processing) {
|
|
|
+ setTimeout(() => {
|
|
|
+ // WS.close();
|
|
|
+ WS.send("unsubscribe");
|
|
|
+ }, 1000)
|
|
|
+ }
|
|
|
|
|
|
return !this.images.some(e => e.state === "completed")
|
|
|
},
|