From a3c10148f138eb10fb874c0435ae78c9048ac8ce Mon Sep 17 00:00:00 2001 From: godo Date: Sun, 1 Sep 2024 17:43:56 +0800 Subject: [PATCH] change file system --- CHANGELOG.md | 1 + frontend/src/components/setting/SetSystem.vue | 17 +-- frontend/src/system/config.ts | 110 +++++++++++++++--- frontend/src/system/core/FileOs.ts | 35 +++--- frontend/src/system/index.ts | 7 +- 5 files changed, 121 insertions(+), 49 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 194ab21..65a1300 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,3 +33,4 @@ bug梳理: 1. 优化内网聊天 2. 新增 权限管理 文件加密 以及远程存储服务端(企业版本) 3. 应用商店重构 陆续会新增php/node/go/java +4. 文档可上传图片 diff --git a/frontend/src/components/setting/SetSystem.vue b/frontend/src/components/setting/SetSystem.vue index fb28474..9d3f25c 100644 --- a/frontend/src/components/setting/SetSystem.vue +++ b/frontend/src/components/setting/SetSystem.vue @@ -103,10 +103,9 @@ import { inject, ref } from "vue"; import { Dialog, join, System, t } from "@/system"; import JSZip from "jszip"; import FileSaver from "file-saver"; -import { getSystemConfig, setSystemConfig } from "@/system/config"; +import { getSystemConfig, setSystemConfig,getClientId } from "@/system/config"; import { OpenDirDialog, RestartApp } from "@/util/goutil"; import { notifyError, notifySuccess } from "@/util/msg"; -import { md5 } from 'js-md5'; const config = ref(getSystemConfig()); const sys = inject("system")!; let zipFile: File | undefined = undefined; @@ -268,16 +267,14 @@ async function saveUserInfo() { }); return; } - const password = md5(saveData.userInfo.password) - const serverUrl = saveData.userInfo.url + '/api/v1/login' + const password = saveData.userInfo.password + const serverUrl = saveData.userInfo.url + '/member/login' const res = await fetch(serverUrl, { method: "POST", - headers: { - "Content-Type": "application/json", - }, body: JSON.stringify({ username: saveData.userInfo.username, password: password, + clientId: getClientId(), }), }); if (res.status === 200) { @@ -288,10 +285,14 @@ async function saveUserInfo() { saveData.userInfo = data.data setSystemConfig(saveData); notifySuccess("登录成功"); + RestartApp(); return + }else{ + notifyError(data.message) } + }else{ + notifyError("登录失败"); } - notifyError("登录失败"); return } async function exportBackup() { diff --git a/frontend/src/system/config.ts b/frontend/src/system/config.ts index f9dc740..6cc66f2 100644 --- a/frontend/src/system/config.ts +++ b/frontend/src/system/config.ts @@ -26,23 +26,30 @@ export const getSystemConfig = (ifset = false) => { if (!config.apiUrl) { config.apiUrl = 'http://localhost:56780'; } - if(!config.userType){ + if (!config.userType) { config.userType = 'person' } // 初始化用户信息,若本地存储中已存在则不进行覆盖 if (!config.userInfo) { config.userInfo = { - url:'', + url: '', username: '', password: '', - memberId: 0, + id: 0, nickname: '', avatar: '', email: '', - mobile: '', - role: 0, - department: 0, - token:'' + phone: '', + desc: '', + job_number: '', + work_place: '', + hired_date: '', + ding_id: '', + role_id: 0, + roleName: '', + dept_id: 0, + deptName: '', + token: '' }; } @@ -87,7 +94,6 @@ export const getSystemConfig = (ifset = false) => { // 初始化账户信息,若本地存储中已存在则不进行覆盖 if (!config.account) { config.account = { - memberId: '', username: '', password: '', }; @@ -114,7 +120,7 @@ export const getSystemConfig = (ifset = false) => { dbname: '' }; } - + // 初始化桌面快捷方式列表,若本地存储中已存在则不进行覆盖 if (!config.desktopList) { config.desktopList = []; @@ -140,17 +146,55 @@ export function getApiUrl() { } export function getFileUrl() { const config = getSystemConfig(); - if(config.storeType == 'net'){ - return config.storenet.url + '/file' - } - else if (config.storeType == 'webdav') { - return config.apiUrl + '/webdav' + if (config.userType == 'person') { + if (config.storeType == 'net') { + return config.storenet.url + '/file' + } + else if (config.storeType == 'webdav') { + return config.apiUrl + '/webdav' + } else { + return config.apiUrl + '/file' + } }else{ - return config.apiUrl + '/file' + return config.userInfo.url + '/files' } - -} +} +export function fetchGet(url: string) { + const config = getSystemConfig(); + if (config.userType == 'person') { + return fetch(url) + } else { + return fetch(url, { + method: 'GET', + credentials: 'include', + headers: { + //'Content-Type': 'application/json', + 'ClientID': getClientId(), + 'Authorization': config.userInfo.token + } + }) + } +} +export function fetchPost(url: string, data: any) { + const config = getSystemConfig(); + if (config.userType == 'person') { + return fetch(url, { + method: 'POST', + body: data, + }) + } else { + return fetch(url, { + method: 'POST', + credentials: 'include', + body: data, + headers: { + 'ClientID': getClientId(), + 'Authorization': config.userInfo.token + } + }) + } +} export function isWindowsOS() { return /win64|wow64|win32|win16|wow32/i.test(navigator.userAgent); } @@ -202,4 +246,34 @@ export const clearSystemConfig = () => { localStorage.clear() localStorage.setItem('GodoOS-storeType', storetype) //localStorage.removeItem('GodoOS-config'); -}; \ No newline at end of file +}; +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("godoosClientId"); + 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("godoosClientId", uuid); + } + return uuid; + } \ No newline at end of file diff --git a/frontend/src/system/core/FileOs.ts b/frontend/src/system/core/FileOs.ts index 2205ec2..88ccc6b 100644 --- a/frontend/src/system/core/FileOs.ts +++ b/frontend/src/system/core/FileOs.ts @@ -1,8 +1,8 @@ -import { getFileUrl } from "../config.ts"; +import { getFileUrl,fetchGet,fetchPost } from "../config.ts"; const API_BASE_URL = getFileUrl() import { OsFileMode } from '../core/FileMode'; export async function handleReadDir(path: string): Promise { - const res = await fetch(`${API_BASE_URL}/read?path=${encodeURIComponent(path)}`); + const res = await fetchGet(`${API_BASE_URL}/read?path=${encodeURIComponent(path)}`); if (!res.ok) { return false; } @@ -10,17 +10,14 @@ export async function handleReadDir(path: string): Promise { } export async function handleStat(path: string): Promise { - const res = await fetch(`${API_BASE_URL}/stat?path=${encodeURIComponent(path)}`); + const res = await fetchGet(`${API_BASE_URL}/stat?path=${encodeURIComponent(path)}`); if (!res.ok) { return false; } return await res.json(); } export async function handleChmod(path: string, mode: string): Promise { - const res = await fetch(`${API_BASE_URL}/chmod`, { - method: 'POST', - body: JSON.stringify({ path, mode }), - }); + const res = await fetchPost(`${API_BASE_URL}/chmod`, JSON.stringify({ path, mode })); if (!res.ok) { return false; } @@ -47,7 +44,7 @@ function osFileModeToOctal(mode: OsFileMode): string { } } export async function handleExists(path: string): Promise { - const res = await fetch(`${API_BASE_URL}/exists?path=${encodeURIComponent(path)}`); + const res = await fetchGet(`${API_BASE_URL}/exists?path=${encodeURIComponent(path)}`); if (!res.ok) { return false; } @@ -55,7 +52,7 @@ export async function handleExists(path: string): Promise { } export async function handleReadFile(path: string): Promise { - const res = await fetch(`${API_BASE_URL}/readfile?path=${encodeURIComponent(path)}`); + const res = await fetchGet(`${API_BASE_URL}/readfile?path=${encodeURIComponent(path)}`); if (!res.ok) { return false; } @@ -63,7 +60,7 @@ export async function handleReadFile(path: string): Promise { } export async function handleUnlink(path: string): Promise { - const res = await fetch(`${API_BASE_URL}/unlink?path=${encodeURIComponent(path)}`); + const res = await fetchGet(`${API_BASE_URL}/unlink?path=${encodeURIComponent(path)}`); if (!res.ok) { return false; } @@ -71,7 +68,7 @@ export async function handleUnlink(path: string): Promise { } export async function handleClear(): Promise { - const res = await fetch(`${API_BASE_URL}/clear`); + const res = await fetchGet(`${API_BASE_URL}/clear`); if (!res.ok) { return false; } @@ -79,7 +76,7 @@ export async function handleClear(): Promise { } export async function handleRename(oldPath: string, newPath: string): Promise { - const res = await fetch(`${API_BASE_URL}/rename?oldPath=${encodeURIComponent(oldPath)}&newPath=${encodeURIComponent(newPath)}`); + const res = await fetchGet(`${API_BASE_URL}/rename?oldPath=${encodeURIComponent(oldPath)}&newPath=${encodeURIComponent(newPath)}`); if (!res.ok) { return false; } @@ -87,7 +84,7 @@ export async function handleRename(oldPath: string, newPath: string): Promise { - const res = await fetch(`${API_BASE_URL}/mkdir?dirPath=${encodeURIComponent(dirPath)}`, { method: 'POST' }); + const res = await fetchPost(`${API_BASE_URL}/mkdir?dirPath=${encodeURIComponent(dirPath)}`, {}); if (!res.ok) { return false; } @@ -95,7 +92,7 @@ export async function handleMkdir(dirPath: string): Promise { } export async function handleRmdir(dirPath: string): Promise { - const res = await fetch(`${API_BASE_URL}/rmdir?dirPath=${encodeURIComponent(dirPath)}`); + const res = await fetchGet(`${API_BASE_URL}/rmdir?dirPath=${encodeURIComponent(dirPath)}`); if (!res.ok) { return false; } @@ -104,7 +101,7 @@ export async function handleRmdir(dirPath: string): Promise { export async function handleCopyFile(srcPath: string, dstPath: string): Promise { - const res = await fetch(`${API_BASE_URL}/copyfile?srcPath=${encodeURIComponent(srcPath)}&dstPath=${encodeURIComponent(dstPath)}`); + const res = await fetchGet(`${API_BASE_URL}/copyfile?srcPath=${encodeURIComponent(srcPath)}&dstPath=${encodeURIComponent(dstPath)}`); if (!res.ok) { return false; } @@ -142,7 +139,7 @@ export async function handleWriteFile(filePath: string, content: any): Promise { const formData = getFormData(content); const url = `${API_BASE_URL}/appendfile?filePath=${encodeURIComponent(filePath)}`; - const res = await fetch(url, { method: 'POST', body: formData }); + const res = await fetchPost(url, formData); if (!res.ok) { return false; } @@ -179,14 +176,14 @@ export function handleWatch(path: string, callback: any, errback: any) { } } export async function handleZip(path: string, ext: string): Promise { - const res = await fetch(`${API_BASE_URL}/zip?path=${encodeURIComponent(path)}&ext=${ext}`); + const res = await fetchGet(`${API_BASE_URL}/zip?path=${encodeURIComponent(path)}&ext=${ext}`); if (!res.ok) { return false; } return await res.json(); } export async function handleUnZip(path: string): Promise { - const res = await fetch(`${API_BASE_URL}/unzip?path=${encodeURIComponent(path)}`); + const res = await fetchGet(`${API_BASE_URL}/unzip?path=${encodeURIComponent(path)}`); if (!res.ok) { return false; } diff --git a/frontend/src/system/index.ts b/frontend/src/system/index.ts index 4e8cee6..2cce232 100644 --- a/frontend/src/system/index.ts +++ b/frontend/src/system/index.ts @@ -22,7 +22,7 @@ import { Notify, NotifyConstructorOptions } from './notification/Notification'; import { Dialog } from './window/Dialog'; import { pick } from '../util/modash'; import { Tray, TrayOptions } from './menu/Tary'; -import { getSystemConfig, getSystemKey, setSystemKey, setSystemConfig, clearSystemConfig, getFileUrl } from './config' +import { getSystemConfig, getSystemKey, setSystemKey, setSystemConfig, clearSystemConfig, getFileUrl,fetchGet } from './config' import { useUpgradeStore } from '@/stores/upgrade'; import { RestartApp } from '@/util/goutil'; @@ -164,10 +164,9 @@ export class System { if (!system) return; const fileUrl = getFileUrl(); if (!fileUrl) return; - fetch(`${fileUrl}/desktop`).then(res => res.json()).then(res => { + + fetchGet(`${fileUrl}/desktop`).then(res => res.json()).then(res => { if (res && res.code == 0) { - // system._rootState.apps = res.data.apps; - // system._rootState.menulist = res.data.menulist; system._rootState.apps.splice(0, system._rootState.apps.length, ...res.data.apps); system._rootState.menulist.splice(0, system._rootState.menulist.length, ...res.data.menulist); }