From 0c9c671050805ca6436384a27c8279d03680671c Mon Sep 17 00:00:00 2001 From: godo Date: Wed, 11 Sep 2024 14:21:39 +0800 Subject: [PATCH] change update --- frontend/package.json | 2 +- frontend/src/components/desktop/Upgrade.vue | 13 +++-- frontend/src/components/localchat/Chat.vue | 46 +---------------- frontend/src/stores/localchat.ts | 56 +++++++++------------ frontend/src/stores/upgrade.ts | 26 ++++++---- frontend/src/system/config.ts | 30 ++++++++++- 6 files changed, 79 insertions(+), 94 deletions(-) diff --git a/frontend/package.json b/frontend/package.json index 1eb281a..a455631 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,7 +1,7 @@ { "name": "godoos", "private": true, - "version": "1.0.0", + "version": "1.0.2", "type": "module", "scripts": { "dev": "vite", diff --git a/frontend/src/components/desktop/Upgrade.vue b/frontend/src/components/desktop/Upgrade.vue index ae3ebbe..59aafce 100644 --- a/frontend/src/components/desktop/Upgrade.vue +++ b/frontend/src/components/desktop/Upgrade.vue @@ -2,7 +2,7 @@
- GodoOS {{ upgradeStore.upgradeDesc }} -
- - 查看详情 - -
+
{{ $t('upgrade.desc') }}
@@ -124,6 +119,10 @@ onMounted(() => { .upgrade-content { padding: 20px; line-height: 22px; + .upgrade-content-txt{ + max-height: 300px; + overflow-y: auto; + } .upgrade-content-desc { color: rgba(255, 255, 255, 0.7); font-size: 12px; diff --git a/frontend/src/components/localchat/Chat.vue b/frontend/src/components/localchat/Chat.vue index 49375af..005d2cd 100644 --- a/frontend/src/components/localchat/Chat.vue +++ b/frontend/src/components/localchat/Chat.vue @@ -16,56 +16,14 @@ import { onMounted } from "vue"; import { useLocalChatStore } from "@/stores/localchat"; -//import { ElMessage } from "element-plus"; -//import { getSystemConfig } from "@/system/config"; + const store = useLocalChatStore(); -//const config = getSystemConfig(); + //let source:any; onMounted(async () => { await store.init() - //init() }); -// onUnmounted(() => { -// if (source) { -// source.close(); -// } -// }); -// function init() { -// if (typeof EventSource === "undefined") { -// ElMessage.error("您的浏览器不支持SSE"); -// return; -// } -// const sseUrl = config.apiUrl + "/localchat/sse"; -// source = new EventSource(sseUrl); -// // 当接收到消息时触发 -// source.onmessage = async function (event:any) { -// //console.log("has message!"); -// const eventData = event.data; // 先保存原始数据 -// const jsonData = JSON.parse(eventData); // 解析数据 -// //console.log(jsonData); -// if (jsonData.type == "user_list") { -// //store.userList = jsonData; -// store.setUserList(jsonData.content); -// //await nextTick(); -// } -// if(jsonData.type == 'text'){ -// store.addText(jsonData); -// } -// if(jsonData.type == 'file'){ -// store.addFile(jsonData); -// } -// }; -// // 当与服务器的连接打开时触发 -// source.onopen = function () { -// console.log("Connection opened."); -// }; - -// // 当与服务器的连接关闭时触发 -// source.onerror = function () { -// console.log("Connection closed."); -// }; -// } diff --git a/frontend/src/stores/localchat.ts b/frontend/src/stores/localchat.ts index f4af130..b93330a 100644 --- a/frontend/src/stores/localchat.ts +++ b/frontend/src/stores/localchat.ts @@ -2,11 +2,12 @@ import { defineStore } from 'pinia' import emojiList from "@/assets/emoji.json" import { ref, toRaw } from "vue"; import { db } from './db' -import { getSystemConfig, setSystemKey } from "@/system/config"; +import { fetchPost, getChatUrl, getUrl, setSystemKey } from "@/system/config"; import { isValidIP } from "@/util/common"; import { notifyError, notifySuccess } from "@/util/msg"; export const useLocalChatStore = defineStore('localChatStore', () => { - const config = getSystemConfig(); + //const config = getSystemConfig(); + const chatUrl = getChatUrl(); //const sys = inject("system"); const userList: any = ref([]) const msgList: any = ref([]) @@ -38,7 +39,6 @@ export const useLocalChatStore = defineStore('localChatStore', () => { setUserList(ips); } if(data.messages){ - const apiUrl = `${config.apiUrl}/localchat/viewimage?img=` for(let ip in data.messages){ const msgList:any = data.messages[ip] if(!msgList || msgList.length < 1)return; @@ -50,7 +50,10 @@ export const useLocalChatStore = defineStore('localChatStore', () => { addText(msg) } else if (msg.type === "image"){ - msg.message = msg.message.map((d: any) => `${apiUrl}${encodeURIComponent(d)}`) + msg.message = msg.message.map((d: any) => { + const url = `/localchat/viewimage?img=${encodeURIComponent(d)}` + return getUrl(url) + }) //console.log(msg) addText(msg) } @@ -318,18 +321,21 @@ export const useLocalChatStore = defineStore('localChatStore', () => { return } const content = toRaw(sendInfo.value) - let saves:any + let saveContent:any if (type === 'image') { - const apiUrl = `${config.apiUrl}/localchat/viewimage?img=` - saves = content.map((d: any) => `${apiUrl}${encodeURIComponent(d)}`) + saveContent = content.map((d: any) => { + const url = `/localchat/viewimage?img=${encodeURIComponent(d)}` + return getUrl(url) + }) }else{ - saves = content + saveContent = content } + console.log(saveContent) const saveMsg: any = { type: type, targetId: chatTargetId.value, targetIp: chatTargetIp.value, - content: saves, + content: saveContent, createdAt: Date.now(), isMe: true, isRead: false, @@ -347,23 +353,20 @@ export const useLocalChatStore = defineStore('localChatStore', () => { ip: saveMsg.targetIp } if (targetUser.isOnline) { - let postUrl = `${config.apiUrl}/localchat/message` + let postUrl = `${chatUrl}/message` if(type === 'applyfile'){ messages.message = { fileList: messages.message, msgId: msgId, status: 'apply' } - postUrl = `${config.apiUrl}/localchat/applyfile` + postUrl = `${chatUrl}/applyfile` } if(type === 'image'){ - postUrl = `${config.apiUrl}/localchat/sendimage` + postUrl = `${chatUrl}/sendimage` } - const completion = await fetch(postUrl, { - method: "POST", - body: JSON.stringify(messages), - }) + const completion = await fetchPost(postUrl, JSON.stringify(messages)) //console.log(completion) if (!completion.ok) { console.log(completion) @@ -390,11 +393,8 @@ export const useLocalChatStore = defineStore('localChatStore', () => { message: item.content.msgId, ip: item.targetIp } - const postUrl = `${config.apiUrl}/localchat/cannelfile` - const coms = await fetch(postUrl, { - method: "POST", - body: JSON.stringify(messages), - }) + const postUrl = `${chatUrl}/cannelfile` + const coms = await fetchPost(postUrl, JSON.stringify(messages)) if (!coms.ok) { console.log(coms) notifyError("确认失败!") @@ -421,11 +421,8 @@ export const useLocalChatStore = defineStore('localChatStore', () => { message: item.content, ip: item.targetIp } - const postUrl = `${config.apiUrl}/localchat/accessfile` - const coms = await fetch(postUrl, { - method: "POST", - body: JSON.stringify(messages), - }) + const postUrl = `${chatUrl}/accessfile` + const coms = await fetchPost(postUrl, JSON.stringify(messages)) if (!coms.ok) { //console.log(coms) notifyError("确认失败!") @@ -452,11 +449,8 @@ export const useLocalChatStore = defineStore('localChatStore', () => { async function saveConfig(conf:any){ conf = toRaw(conf) //console.log(conf) - const postUrl = `${config.apiUrl}/localchat/setting` - const coms = await fetch(postUrl, { - method: "POST", - body: JSON.stringify(conf), - }) + const postUrl = `${chatUrl}/setting` + const coms = await fetchPost(postUrl, JSON.stringify(conf)) if (!coms.ok) { //console.log(coms) notifyError("保存失败!") diff --git a/frontend/src/stores/upgrade.ts b/frontend/src/stores/upgrade.ts index 4f3d3f7..0a901e5 100644 --- a/frontend/src/stores/upgrade.ts +++ b/frontend/src/stores/upgrade.ts @@ -1,6 +1,6 @@ import { defineStore } from "pinia"; import { ref } from "vue"; -import { getSystemKey, setSystemKey, parseJson, getSystemConfig } from '@/system/config' +import { setSystemKey, parseJson, getSystemConfig, getUrl } from '@/system/config' import { RestartApp } from '@/util/goutil'; import { ElMessage } from 'element-plus' import { t } from '@/i18n'; @@ -37,9 +37,9 @@ export const useUpgradeStore = defineStore('upgradeStore', () => { return 0; } function systemMessage(){ - const config = getSystemConfig(); - - const source = new EventSource(`${config.apiUrl}/system/message`); + //const config = getSystemConfig(); + const apiUrl = getUrl('/system/message',false) + const source = new EventSource(apiUrl); source.onmessage = function(event) { const data = JSON.parse(event.data); @@ -53,7 +53,7 @@ export const useUpgradeStore = defineStore('upgradeStore', () => { async function handleMessage(message:any) { switch (message.type) { case 'update': - checkUpdate(message.data.data) + checkUpdate(message.data) break; case 'localchat': localChatStore.handlerMessage(message.data) @@ -64,6 +64,7 @@ export const useUpgradeStore = defineStore('upgradeStore', () => { } async function checkUpdate(res:any) { //console.log(res) + if(!res)return const config = getSystemConfig(); if(!config.account.ad)return; currentVersion.value = config.version; @@ -96,17 +97,24 @@ export const useUpgradeStore = defineStore('upgradeStore', () => { } } function changeUrl(list : any){ + const config = getSystemConfig(); list.forEach((item:any) => { if(item.img && item.img.indexOf('http') == -1){ - item.img = `https://godoos.com${item.img}` + if(config.userType === 'person'){ + item.img = `https://godoos.com${item.img}` + }else{ + item.img = `${config.userInfo.url}${item.img}` + } + } }); return list } async function update() { - const apiUrl = getSystemKey('apiUrl') - const upUrl = `${apiUrl}/system/update?url=${updateUrl.value}` - const upRes = await fetch(upUrl) + //const apiUrl = getApiUrl() + const upUrl = `/system/update?url=${updateUrl.value}` + const apiUrl = getUrl(upUrl,true) + const upRes = await fetch(apiUrl) if (!upRes.ok) return; const reader: any = upRes.body?.getReader(); if (!reader) { diff --git a/frontend/src/system/config.ts b/frontend/src/system/config.ts index 2e3d757..a309e26 100644 --- a/frontend/src/system/config.ts +++ b/frontend/src/system/config.ts @@ -14,7 +14,7 @@ export const getSystemConfig = (ifset = false) => { // 初始化配置对象的各项属性,若本地存储中已存在则不进行覆盖 if (!config.version) { - config.version = '1.0.1'; + config.version = '1.0.2'; } if (!config.isFirstRun) { config.isFirstRun = false; @@ -155,7 +155,12 @@ export const getSystemConfig = (ifset = false) => { }; export function getApiUrl() { - return getSystemKey('apiUrl') + const config = getSystemConfig(); + if (config.userType == 'person') { + return config.apiUrl + }else{ + return config.userInfo.url + } } export function getFileUrl() { const config = getSystemConfig(); @@ -173,6 +178,27 @@ export function getFileUrl() { } } +export function getChatUrl() { + const config = getSystemConfig(); + if (config.userType == 'person') { + return config.apiUrl + '/localchat' + } else { + return config.userInfo.url + '/localchat' + } +} +export function getUrl(url: string, islast = true) { + const config = getSystemConfig(); + if (config.userType == 'person') { + return config.apiUrl + url + } else { + if(islast){ + return config.userInfo.url + url + '&uuid=' + getClientId() + '&token=' + config.userInfo.token + }else{ + return config.userInfo.url + url + '?uuid=' + getClientId() + '&token=' + config.userInfo.token + } + + } +} export function fetchGet(url: string) { const config = getSystemConfig(); if (config.userType == 'person') {