diff --git a/frontend/src/system/config.ts b/frontend/src/system/config.ts index 2e0fdaa..392c5d3 100644 --- a/frontend/src/system/config.ts +++ b/frontend/src/system/config.ts @@ -1,7 +1,7 @@ import { generateRandomString } from "../util/common.ts"; export const configStoreType = localStorage.getItem('GodoOS-storeType') || 'local'; import { parseAiConfig } from "./aiconfig.ts"; -import { getClientId } from "../util/clientid.ts"; +import { GetClientId } from "../util/clientid.ts"; /** * 获取系统配置信息。 * 从本地存储中获取或初始化系统配置对象,并根据条件决定是否更新本地存储中的配置。 @@ -224,9 +224,9 @@ export function getUrl(url: string, islast = true) { return config.apiUrl + url } else { if (islast) { - return config.userInfo.url + url + '&uuid=' + getClientId() + '&token=' + config.userInfo.token + return config.userInfo.url + url + '&uuid=' + GetClientId() + '&token=' + config.userInfo.token } else { - return config.userInfo.url + url + '?uuid=' + getClientId() + '&token=' + config.userInfo.token + return config.userInfo.url + url + '?uuid=' + GetClientId() + '&token=' + config.userInfo.token } } @@ -234,7 +234,7 @@ export function getUrl(url: string, islast = true) { export function getWorkflowUrl() { const config = getSystemConfig(); if (config.userType == 'member') { - return config.userInfo.url + '/views/desktop/index.html' + '?uuid=' + getClientId() + '&token=' + config.userInfo.token + return config.userInfo.url + '/views/desktop/index.html' + '?uuid=' + GetClientId() + '&token=' + config.userInfo.token } } export function fetchGet(url: string, headerConfig?: { [key: string]: string }) { @@ -252,7 +252,7 @@ export function fetchGet(url: string, headerConfig?: { [key: string]: string }) credentials: 'include', headers: { //'Content-Type': 'application/json', - 'ClientID': getClientId(), + 'ClientID': GetClientId(), 'Authorization': config.userInfo.token, ...headerConfig } @@ -273,7 +273,7 @@ export function fetchPost(url: string, data: any, headerConfig?: { [key: string] credentials: 'include', body: data, headers: { - 'ClientID': getClientId(), + 'ClientID': GetClientId(), 'Authorization': config.userInfo.token, ...headerConfig } @@ -330,43 +330,3 @@ export const clearSystemConfig = () => { } //localStorage.removeItem('GodoOS-config'); }; -// function bin2hex(s: string) { -// s = encodeURI(s);//只会有0-127的ascii不转化 -// let m: any = s.match(/%[\dA-F]{2}/g), a: any = s.split(/%[\dA-F]{2}/), i, j, n, t; -// m.push("") -// for (i in a) { -// if (a[i] === "") { a[i] = m[i]; continue } -// n = "" -// for (j in a[i]) { -// t = a[i][j].charCodeAt().toString(16).toUpperCase() -// if (t.length === 1) t = "0" + t -// n += "%" + t -// } -// a[i] = n + m[i] -// } -// return a.join("").split("%").join("") -// } -// export const getClientId = () => { -// let uuid: any = localStorage.getItem("ClientID"); -// if (!uuid) { -// let canvas = document.createElement('canvas'); -// let ctx: any = canvas.getContext('2d'); -// ctx.fillStyle = '#FF0000'; -// ctx.fillRect(0, 0, 8, 10); -// let b64 = canvas.toDataURL().replace("data:image/png;base64,", ""); -// let bin = window.atob(b64); -// uuid = bin2hex(bin.slice(-16, -12)); -// localStorage.setItem("ClientID", uuid); -// } -// return uuid; -// } -// export const getClientId = () => { -// let uuid: any = localStorage.getItem("godoosClientId"); -// if (!uuid) { -// const timestamp = new Date().getTime(); -// const random = Math.floor(Math.random() * 1000000); -// uuid = `${timestamp}${random}`; -// localStorage.setItem("godoosClientId", uuid); -// } -// return uuid; -// } \ No newline at end of file diff --git a/frontend/src/system/index.ts b/frontend/src/system/index.ts index 3088488..a23166d 100644 --- a/frontend/src/system/index.ts +++ b/frontend/src/system/index.ts @@ -21,7 +21,8 @@ import { RestartApp } from '@/util/goutil'; import { notifyError } from '@/util/msg'; //import { isShareFile } from '@/util/sharePath'; import { pick } from '../util/modash'; -import { clearSystemConfig, fetchGet, getClientId, getFileUrl, getSystemConfig, getSystemKey, setSystemConfig, setSystemKey } from './config'; +import { GetClientId } from "../util/clientid.ts"; +import { clearSystemConfig, fetchGet, getFileUrl, getSystemConfig, getSystemKey, setSystemConfig, setSystemKey } from './config'; import { OsFileInterface } from './core/FIleInterface'; import { extname } from './core/Path'; import { initBuiltinApp, initBuiltinFileOpener } from './initBuiltin'; @@ -119,11 +120,11 @@ export class System { //console.log(config.userType) if (config.userType == 'person') { upgradeStore.systemMessage(); - }else{ + } else { upgradeStore.onlineMessage() - } + } }, 3000); - + } /** @@ -192,7 +193,7 @@ export class System { password: password, github_code: loginCode?.github_code, gitee_code: loginCode?.gitee_code, - clientId: getClientId(), + clientId: GetClientId(), }), }); if (!res.ok) { @@ -261,7 +262,7 @@ export class System { } catch (error) { console.log(error) } - + } @@ -334,8 +335,8 @@ export class System { } //if(!options.window.content)return //if (typeof options.window.content !== 'string') { - //console.log('index.ts:', options.window.content) - //options.window.content = markRaw(options.window.content); + //console.log('index.ts:', options.window.content) + //options.window.content = markRaw(options.window.content); //} // console.log(options.window) // console.log(options.name) @@ -453,44 +454,44 @@ export class System { } /**打开os 文件系统的文件 */ async openFile(path: string) { - const fileStat = await this.fs.stat(path) - //console.log(fileStat) - if (!fileStat) { - throw new Error('文件不存在'); + const fileStat = await this.fs.stat(path) + //console.log(fileStat) + if (!fileStat) { + throw new Error('文件不存在'); + } + // 如果fileStat为目录 + if (fileStat?.isDirectory) { + // 从_fileOpenerMap中获取'link'对应的函数并调用 + this._flieOpenerMap.get('dir')?.func.call(this, path, ''); + return; + } else { + const header = { + pwd: '' } - // 如果fileStat为目录 - if (fileStat?.isDirectory) { - // 从_fileOpenerMap中获取'link'对应的函数并调用 - this._flieOpenerMap.get('dir')?.func.call(this, path, ''); - return; - } else { - const header = { - pwd: '' + // 读取文件内容 + let fileContent = await this.fs.readFile(path, header); + // 改文件需要输入密码 + if (fileContent && fileContent.code == -1 && fileContent.error == 'needPwd') { + const temp = await Dialog.showInputBox() + if (temp.response !== 1) { + return } - // 读取文件内容 - let fileContent = await this.fs.readFile(path, header); - // 改文件需要输入密码 - if (fileContent && fileContent.code == -1 && fileContent.error == 'needPwd') { - const temp = await Dialog.showInputBox() - if (temp.response !== 1) { - return - } - header.pwd = temp?.inputPwd ? temp?.inputPwd : '' - const reOpen = await this.fs.readFile(path, header); - //console.log(reOpen) - if (reOpen === false || reOpen.code === -1) { - notifyError("文件密码错误") - return - } - fileContent = reOpen + header.pwd = temp?.inputPwd ? temp?.inputPwd : '' + const reOpen = await this.fs.readFile(path, header); + //console.log(reOpen) + if (reOpen === false || reOpen.code === -1) { + notifyError("文件密码错误") + return } - //console.log(fileStat) - // 从_fileOpenerMap中获取文件扩展名对应的函数并调用 - const fileName = extname(fileStat?.name || '') || 'link' - //console.log(fileName,fileContent) - this._flieOpenerMap - .get(fileName) - ?.func.call(this, path, fileContent || ''); + fileContent = reOpen + } + //console.log(fileStat) + // 从_fileOpenerMap中获取文件扩展名对应的函数并调用 + const fileName = extname(fileStat?.name || '') || 'link' + //console.log(fileName,fileContent) + this._flieOpenerMap + .get(fileName) + ?.func.call(this, path, fileContent || ''); } } // 插件系统 diff --git a/frontend/src/util/clientid.ts b/frontend/src/util/clientid.ts index 04f83a4..dd563f7 100644 --- a/frontend/src/util/clientid.ts +++ b/frontend/src/util/clientid.ts @@ -85,7 +85,7 @@ function getOSInfo() { } return hash.toString(36); // Convert to base 36 for shorter string } - export const getClientId = () => { + export function GetClientId(){ let uuid = localStorage.getItem("ClientID"); if (!uuid) { const fingerprint = getBrowserFingerprint();