|
@@ -6,7 +6,7 @@ import { getLocalToken, removeLocalToken, saveLocalToken } from "@/utils";
|
|
import type { AppNotification } from '@/interfaces';
|
|
import type { AppNotification } from '@/interfaces';
|
|
import type { IUserProfile, IUserProfileCreate, IUserProfileUpdate, MainState, Video, VideoCreate } from '@/interfaces';
|
|
import type { IUserProfile, IUserProfileCreate, IUserProfileUpdate, MainState, Video, VideoCreate } from '@/interfaces';
|
|
import i18n from '@/plugins/i18n'
|
|
import i18n from '@/plugins/i18n'
|
|
-import { GoogleLogin } from "vue3-google-login";
|
|
|
|
|
|
+import WS from "@/stores/ws";
|
|
|
|
|
|
const defaultState: MainState = {
|
|
const defaultState: MainState = {
|
|
isLoggedIn: null,
|
|
isLoggedIn: null,
|
|
@@ -256,6 +256,97 @@ export const useMainStore = defineStore("MainStoreId", {
|
|
await mainStore.checkApiError(error);
|
|
await mainStore.checkApiError(error);
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
+ async uploadImage(file: File[]) {
|
|
|
|
+ const mainStore = useMainStore();
|
|
|
|
+ try {
|
|
|
|
+ const loadingNotification = { content: i18n.global.t("sending"), showProgress: true };
|
|
|
|
+ mainStore.addNotification(loadingNotification);
|
|
|
|
+ const response = (
|
|
|
|
+ await Promise.all([
|
|
|
|
+ api.uploadImage(mainStore.token, file),
|
|
|
|
+ await new Promise<void>((resolve, _) => setTimeout(() => resolve(), 0)),
|
|
|
|
+ ]).then(data => {
|
|
|
|
+ for (let i = 0; i < data[0].data.filenames.length; i++) {
|
|
|
|
+ const element = data[0].data.filenames[i];
|
|
|
|
+ const tmpImage: Image = {
|
|
|
|
+ file_name: file[i].name,
|
|
|
|
+ stored_file_name: element,
|
|
|
|
+ content: "sr",
|
|
|
|
+ state: "subscribe"
|
|
|
|
+ };
|
|
|
|
+ this.addImage(tmpImage);
|
|
|
|
+ }
|
|
|
|
+ // localStorage.setItem('imagesList', JSON.stringify(this.images));
|
|
|
|
+ })
|
|
|
|
+ );
|
|
|
|
+ mainStore.removeNotification(loadingNotification);
|
|
|
|
+ mainStore.addNotification({
|
|
|
|
+ content: i18n.global.t("fileReceived"),
|
|
|
|
+ color: "success",
|
|
|
|
+ })
|
|
|
|
+ // this.actionGetVideos();
|
|
|
|
+ } catch (error) {
|
|
|
|
+ await mainStore.checkApiError(error);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ async getImage(data: ImageDownload) {
|
|
|
|
+ const mainStore = useMainStore();
|
|
|
|
+ try {
|
|
|
|
+ const response = (
|
|
|
|
+ await Promise.all([
|
|
|
|
+ api.getImage(mainStore.token, data),
|
|
|
|
+ await new Promise<void>((resolve, _) => setTimeout(() => resolve(), 0)),
|
|
|
|
+ ])
|
|
|
|
+ );
|
|
|
|
+ } catch (error) {
|
|
|
|
+ await mainStore.checkApiError(error);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ addImage(payload: Image) {
|
|
|
|
+ this.images.push(payload);
|
|
|
|
+ },
|
|
|
|
+ finishImage(payload: string) {
|
|
|
|
+ let image = this.images.filter(e => {
|
|
|
|
+ return e.stored_file_name === payload
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ if (image) {
|
|
|
|
+ image.map(e => {
|
|
|
|
+ e.state = "completed";
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 全部完成後關閉 WebSocket
|
|
|
|
+ // let processing = this.images.find(e => e.state !== "completed")
|
|
|
|
+ // if (!processing) {
|
|
|
|
+ // setTimeout(() => {
|
|
|
|
+ // WS.close();
|
|
|
|
+ // }, 1000)
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ return !this.images.some(e => e.state === "completed")
|
|
|
|
+ },
|
|
|
|
+ async uploadArticle(article_data: ArticleCreate) {
|
|
|
|
+ const mainStore = useMainStore();
|
|
|
|
+ try {
|
|
|
|
+ const loadingNotification = { content: i18n.global.t("sending"), showProgress: true };
|
|
|
|
+ mainStore.addNotification(loadingNotification);
|
|
|
|
+ const response = (
|
|
|
|
+ await Promise.all([
|
|
|
|
+ api.uploadArticle(mainStore.token, article_data),
|
|
|
|
+ await new Promise<void>((resolve, _) => setTimeout(() => resolve(), 0)),
|
|
|
|
+ ])
|
|
|
|
+ );
|
|
|
|
+ mainStore.removeNotification(loadingNotification);
|
|
|
|
+ mainStore.addNotification({
|
|
|
|
+ content: i18n.global.t("fileReceived"),
|
|
|
|
+ color: "success",
|
|
|
|
+ })
|
|
|
|
+ // this.actionGetVideos();
|
|
|
|
+ } catch (error) {
|
|
|
|
+ await mainStore.checkApiError(error);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
async actionGetVideos() {
|
|
async actionGetVideos() {
|
|
const mainStore = useMainStore();
|
|
const mainStore = useMainStore();
|
|
try {
|
|
try {
|