Browse Source

change client Id

master
godo 5 months ago
parent
commit
175d5409b5
  1. 52
      frontend/src/system/config.ts
  2. 87
      frontend/src/system/index.ts
  3. 2
      frontend/src/util/clientid.ts

52
frontend/src/system/config.ts

@ -1,7 +1,7 @@
import { generateRandomString } from "../util/common.ts"; import { generateRandomString } from "../util/common.ts";
export const configStoreType = localStorage.getItem('GodoOS-storeType') || 'local'; export const configStoreType = localStorage.getItem('GodoOS-storeType') || 'local';
import { parseAiConfig } from "./aiconfig.ts"; 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 return config.apiUrl + url
} else { } else {
if (islast) { 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 { } 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() { export function getWorkflowUrl() {
const config = getSystemConfig(); const config = getSystemConfig();
if (config.userType == 'member') { 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 }) { export function fetchGet(url: string, headerConfig?: { [key: string]: string }) {
@ -252,7 +252,7 @@ export function fetchGet(url: string, headerConfig?: { [key: string]: string })
credentials: 'include', credentials: 'include',
headers: { headers: {
//'Content-Type': 'application/json', //'Content-Type': 'application/json',
'ClientID': getClientId(), 'ClientID': GetClientId(),
'Authorization': config.userInfo.token, 'Authorization': config.userInfo.token,
...headerConfig ...headerConfig
} }
@ -273,7 +273,7 @@ export function fetchPost(url: string, data: any, headerConfig?: { [key: string]
credentials: 'include', credentials: 'include',
body: data, body: data,
headers: { headers: {
'ClientID': getClientId(), 'ClientID': GetClientId(),
'Authorization': config.userInfo.token, 'Authorization': config.userInfo.token,
...headerConfig ...headerConfig
} }
@ -330,43 +330,3 @@ export const clearSystemConfig = () => {
} }
//localStorage.removeItem('GodoOS-config'); //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;
// }

87
frontend/src/system/index.ts

@ -21,7 +21,8 @@ import { RestartApp } from '@/util/goutil';
import { notifyError } from '@/util/msg'; import { notifyError } from '@/util/msg';
//import { isShareFile } from '@/util/sharePath'; //import { isShareFile } from '@/util/sharePath';
import { pick } from '../util/modash'; 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 { OsFileInterface } from './core/FIleInterface';
import { extname } from './core/Path'; import { extname } from './core/Path';
import { initBuiltinApp, initBuiltinFileOpener } from './initBuiltin'; import { initBuiltinApp, initBuiltinFileOpener } from './initBuiltin';
@ -119,11 +120,11 @@ export class System {
//console.log(config.userType) //console.log(config.userType)
if (config.userType == 'person') { if (config.userType == 'person') {
upgradeStore.systemMessage(); upgradeStore.systemMessage();
}else{ } else {
upgradeStore.onlineMessage() upgradeStore.onlineMessage()
} }
}, 3000); }, 3000);
} }
/** /**
@ -192,7 +193,7 @@ export class System {
password: password, password: password,
github_code: loginCode?.github_code, github_code: loginCode?.github_code,
gitee_code: loginCode?.gitee_code, gitee_code: loginCode?.gitee_code,
clientId: getClientId(), clientId: GetClientId(),
}), }),
}); });
if (!res.ok) { if (!res.ok) {
@ -261,7 +262,7 @@ export class System {
} catch (error) { } catch (error) {
console.log(error) console.log(error)
} }
} }
@ -334,8 +335,8 @@ export class System {
} }
//if(!options.window.content)return //if(!options.window.content)return
//if (typeof options.window.content !== 'string') { //if (typeof options.window.content !== 'string') {
//console.log('index.ts:', options.window.content) //console.log('index.ts:', options.window.content)
//options.window.content = markRaw(options.window.content); //options.window.content = markRaw(options.window.content);
//} //}
// console.log(options.window) // console.log(options.window)
// console.log(options.name) // console.log(options.name)
@ -453,44 +454,44 @@ export class System {
} }
/**打开os 文件系统的文件 */ /**打开os 文件系统的文件 */
async openFile(path: string) { async openFile(path: string) {
const fileStat = await this.fs.stat(path) const fileStat = await this.fs.stat(path)
//console.log(fileStat) //console.log(fileStat)
if (!fileStat) { if (!fileStat) {
throw new Error('文件不存在'); 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) { let fileContent = await this.fs.readFile(path, header);
// 从_fileOpenerMap中获取'link'对应的函数并调用 // 改文件需要输入密码
this._flieOpenerMap.get('dir')?.func.call(this, path, ''); if (fileContent && fileContent.code == -1 && fileContent.error == 'needPwd') {
return; const temp = await Dialog.showInputBox()
} else { if (temp.response !== 1) {
const header = { return
pwd: ''
} }
// 读取文件内容 header.pwd = temp?.inputPwd ? temp?.inputPwd : ''
let fileContent = await this.fs.readFile(path, header); const reOpen = await this.fs.readFile(path, header);
// 改文件需要输入密码 //console.log(reOpen)
if (fileContent && fileContent.code == -1 && fileContent.error == 'needPwd') { if (reOpen === false || reOpen.code === -1) {
const temp = await Dialog.showInputBox() notifyError("文件密码错误")
if (temp.response !== 1) { return
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
} }
//console.log(fileStat) fileContent = reOpen
// 从_fileOpenerMap中获取文件扩展名对应的函数并调用 }
const fileName = extname(fileStat?.name || '') || 'link' //console.log(fileStat)
//console.log(fileName,fileContent) // 从_fileOpenerMap中获取文件扩展名对应的函数并调用
this._flieOpenerMap const fileName = extname(fileStat?.name || '') || 'link'
.get(fileName) //console.log(fileName,fileContent)
?.func.call(this, path, fileContent || ''); this._flieOpenerMap
.get(fileName)
?.func.call(this, path, fileContent || '');
} }
} }
// 插件系统 // 插件系统

2
frontend/src/util/clientid.ts

@ -85,7 +85,7 @@ function getOSInfo() {
} }
return hash.toString(36); // Convert to base 36 for shorter string return hash.toString(36); // Convert to base 36 for shorter string
} }
export const getClientId = () => { export function GetClientId(){
let uuid = localStorage.getItem("ClientID"); let uuid = localStorage.getItem("ClientID");
if (!uuid) { if (!uuid) {
const fingerprint = getBrowserFingerprint(); const fingerprint = getBrowserFingerprint();

Loading…
Cancel
Save