Browse Source

change file system

master
godo 9 months ago
parent
commit
a3c10148f1
  1. 1
      CHANGELOG.md
  2. 17
      frontend/src/components/setting/SetSystem.vue
  3. 96
      frontend/src/system/config.ts
  4. 35
      frontend/src/system/core/FileOs.ts
  5. 7
      frontend/src/system/index.ts

1
CHANGELOG.md

@ -33,3 +33,4 @@ bug梳理:
1. 优化内网聊天 1. 优化内网聊天
2. 新增 权限管理 文件加密 以及远程存储服务端(企业版本) 2. 新增 权限管理 文件加密 以及远程存储服务端(企业版本)
3. 应用商店重构 陆续会新增php/node/go/java 3. 应用商店重构 陆续会新增php/node/go/java
4. 文档可上传图片

17
frontend/src/components/setting/SetSystem.vue

@ -103,10 +103,9 @@ import { inject, ref } from "vue";
import { Dialog, join, System, t } from "@/system"; import { Dialog, join, System, t } from "@/system";
import JSZip from "jszip"; import JSZip from "jszip";
import FileSaver from "file-saver"; 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 { OpenDirDialog, RestartApp } from "@/util/goutil";
import { notifyError, notifySuccess } from "@/util/msg"; import { notifyError, notifySuccess } from "@/util/msg";
import { md5 } from 'js-md5';
const config = ref(getSystemConfig()); const config = ref(getSystemConfig());
const sys = inject<System>("system")!; const sys = inject<System>("system")!;
let zipFile: File | undefined = undefined; let zipFile: File | undefined = undefined;
@ -268,16 +267,14 @@ async function saveUserInfo() {
}); });
return; return;
} }
const password = md5(saveData.userInfo.password) const password = saveData.userInfo.password
const serverUrl = saveData.userInfo.url + '/api/v1/login' const serverUrl = saveData.userInfo.url + '/member/login'
const res = await fetch(serverUrl, { const res = await fetch(serverUrl, {
method: "POST", method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ body: JSON.stringify({
username: saveData.userInfo.username, username: saveData.userInfo.username,
password: password, password: password,
clientId: getClientId(),
}), }),
}); });
if (res.status === 200) { if (res.status === 200) {
@ -288,10 +285,14 @@ async function saveUserInfo() {
saveData.userInfo = data.data saveData.userInfo = data.data
setSystemConfig(saveData); setSystemConfig(saveData);
notifySuccess("登录成功"); notifySuccess("登录成功");
RestartApp();
return return
}else{
notifyError(data.message)
} }
} }else{
notifyError("登录失败"); notifyError("登录失败");
}
return return
} }
async function exportBackup() { async function exportBackup() {

96
frontend/src/system/config.ts

@ -26,23 +26,30 @@ export const getSystemConfig = (ifset = false) => {
if (!config.apiUrl) { if (!config.apiUrl) {
config.apiUrl = 'http://localhost:56780'; config.apiUrl = 'http://localhost:56780';
} }
if(!config.userType){ if (!config.userType) {
config.userType = 'person' config.userType = 'person'
} }
// 初始化用户信息,若本地存储中已存在则不进行覆盖 // 初始化用户信息,若本地存储中已存在则不进行覆盖
if (!config.userInfo) { if (!config.userInfo) {
config.userInfo = { config.userInfo = {
url:'', url: '',
username: '', username: '',
password: '', password: '',
memberId: 0, id: 0,
nickname: '', nickname: '',
avatar: '', avatar: '',
email: '', email: '',
mobile: '', phone: '',
role: 0, desc: '',
department: 0, job_number: '',
token:'' 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) { if (!config.account) {
config.account = { config.account = {
memberId: '',
username: '', username: '',
password: '', password: '',
}; };
@ -140,17 +146,55 @@ export function getApiUrl() {
} }
export function getFileUrl() { export function getFileUrl() {
const config = getSystemConfig(); const config = getSystemConfig();
if(config.storeType == 'net'){ if (config.userType == 'person') {
if (config.storeType == 'net') {
return config.storenet.url + '/file' return config.storenet.url + '/file'
} }
else if (config.storeType == 'webdav') { else if (config.storeType == 'webdav') {
return config.apiUrl + '/webdav' return config.apiUrl + '/webdav'
}else{ } else {
return config.apiUrl + '/file' return config.apiUrl + '/file'
} }
}else{
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() { export function isWindowsOS() {
return /win64|wow64|win32|win16|wow32/i.test(navigator.userAgent); return /win64|wow64|win32|win16|wow32/i.test(navigator.userAgent);
} }
@ -203,3 +247,33 @@ export const clearSystemConfig = () => {
localStorage.setItem('GodoOS-storeType', storetype) localStorage.setItem('GodoOS-storeType', storetype)
//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("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;
}

35
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() const API_BASE_URL = getFileUrl()
import { OsFileMode } from '../core/FileMode'; import { OsFileMode } from '../core/FileMode';
export async function handleReadDir(path: string): Promise<any> { export async function handleReadDir(path: string): Promise<any> {
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) { if (!res.ok) {
return false; return false;
} }
@ -10,17 +10,14 @@ export async function handleReadDir(path: string): Promise<any> {
} }
export async function handleStat(path: string): Promise<any> { export async function handleStat(path: string): Promise<any> {
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) { if (!res.ok) {
return false; return false;
} }
return await res.json(); return await res.json();
} }
export async function handleChmod(path: string, mode: string): Promise<any> { export async function handleChmod(path: string, mode: string): Promise<any> {
const res = await fetch(`${API_BASE_URL}/chmod`, { const res = await fetchPost(`${API_BASE_URL}/chmod`, JSON.stringify({ path, mode }));
method: 'POST',
body: JSON.stringify({ path, mode }),
});
if (!res.ok) { if (!res.ok) {
return false; return false;
} }
@ -47,7 +44,7 @@ function osFileModeToOctal(mode: OsFileMode): string {
} }
} }
export async function handleExists(path: string): Promise<any> { export async function handleExists(path: string): Promise<any> {
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) { if (!res.ok) {
return false; return false;
} }
@ -55,7 +52,7 @@ export async function handleExists(path: string): Promise<any> {
} }
export async function handleReadFile(path: string): Promise<any> { export async function handleReadFile(path: string): Promise<any> {
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) { if (!res.ok) {
return false; return false;
} }
@ -63,7 +60,7 @@ export async function handleReadFile(path: string): Promise<any> {
} }
export async function handleUnlink(path: string): Promise<any> { export async function handleUnlink(path: string): Promise<any> {
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) { if (!res.ok) {
return false; return false;
} }
@ -71,7 +68,7 @@ export async function handleUnlink(path: string): Promise<any> {
} }
export async function handleClear(): Promise<any> { export async function handleClear(): Promise<any> {
const res = await fetch(`${API_BASE_URL}/clear`); const res = await fetchGet(`${API_BASE_URL}/clear`);
if (!res.ok) { if (!res.ok) {
return false; return false;
} }
@ -79,7 +76,7 @@ export async function handleClear(): Promise<any> {
} }
export async function handleRename(oldPath: string, newPath: string): Promise<any> { export async function handleRename(oldPath: string, newPath: string): Promise<any> {
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) { if (!res.ok) {
return false; return false;
} }
@ -87,7 +84,7 @@ export async function handleRename(oldPath: string, newPath: string): Promise<an
} }
export async function handleMkdir(dirPath: string): Promise<any> { export async function handleMkdir(dirPath: string): Promise<any> {
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) { if (!res.ok) {
return false; return false;
} }
@ -95,7 +92,7 @@ export async function handleMkdir(dirPath: string): Promise<any> {
} }
export async function handleRmdir(dirPath: string): Promise<any> { export async function handleRmdir(dirPath: string): Promise<any> {
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) { if (!res.ok) {
return false; return false;
} }
@ -104,7 +101,7 @@ export async function handleRmdir(dirPath: string): Promise<any> {
export async function handleCopyFile(srcPath: string, dstPath: string): Promise<any> { export async function handleCopyFile(srcPath: string, dstPath: string): Promise<any> {
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) { if (!res.ok) {
return false; return false;
} }
@ -142,7 +139,7 @@ export async function handleWriteFile(filePath: string, content: any): Promise<a
const formData = getFormData(content); const formData = getFormData(content);
const url = `${API_BASE_URL}/writefile?filePath=${encodeURIComponent(filePath)}`; const url = `${API_BASE_URL}/writefile?filePath=${encodeURIComponent(filePath)}`;
const res = await fetch(url, { method: 'POST', body: formData }); const res = await fetchPost(url, formData);
if (!res.ok) { if (!res.ok) {
return false; return false;
} }
@ -152,7 +149,7 @@ export async function handleWriteFile(filePath: string, content: any): Promise<a
export async function handleAppendFile(filePath: string, content: string | Blob): Promise<any> { export async function handleAppendFile(filePath: string, content: string | Blob): Promise<any> {
const formData = getFormData(content); const formData = getFormData(content);
const url = `${API_BASE_URL}/appendfile?filePath=${encodeURIComponent(filePath)}`; 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) { if (!res.ok) {
return false; return false;
} }
@ -179,14 +176,14 @@ export function handleWatch(path: string, callback: any, errback: any) {
} }
} }
export async function handleZip(path: string, ext: string): Promise<any> { export async function handleZip(path: string, ext: string): Promise<any> {
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) { if (!res.ok) {
return false; return false;
} }
return await res.json(); return await res.json();
} }
export async function handleUnZip(path: string): Promise<any> { export async function handleUnZip(path: string): Promise<any> {
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) { if (!res.ok) {
return false; return false;
} }

7
frontend/src/system/index.ts

@ -22,7 +22,7 @@ import { Notify, NotifyConstructorOptions } from './notification/Notification';
import { Dialog } from './window/Dialog'; import { Dialog } from './window/Dialog';
import { pick } from '../util/modash'; import { pick } from '../util/modash';
import { Tray, TrayOptions } from './menu/Tary'; 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 { useUpgradeStore } from '@/stores/upgrade';
import { RestartApp } from '@/util/goutil'; import { RestartApp } from '@/util/goutil';
@ -164,10 +164,9 @@ export class System {
if (!system) return; if (!system) return;
const fileUrl = getFileUrl(); const fileUrl = getFileUrl();
if (!fileUrl) return; 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) { 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.apps.splice(0, system._rootState.apps.length, ...res.data.apps);
system._rootState.menulist.splice(0, system._rootState.menulist.length, ...res.data.menulist); system._rootState.menulist.splice(0, system._rootState.menulist.length, ...res.data.menulist);
} }

Loading…
Cancel
Save