mirror of
https://gitee.com/godoos/godoos.git
synced 2026-11-20 07:49:34 +08:00
change pwd
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
<template>
|
||||
<iframe class="setiframe" allow="fullscreen" ref="storeRef" :src="src"></iframe>
|
||||
<iframe class="setiframe" allow="fullscreen" ref="storeRef" :src="src"></iframe>
|
||||
</template>
|
||||
<script lang="ts" setup name="IframeFile">
|
||||
//@ts-ignore
|
||||
import { BrowserWindow, Dialog, Notify, System } from "@/system";
|
||||
import { getSplit, getSystemConfig, setSystemKey } from "@/system/config";
|
||||
import { notifyError } from "@/util/msg";
|
||||
import { getSplit } from "@/system/config";
|
||||
import { base64ToBuffer, isBase64 } from "@/util/file";
|
||||
import { generateRandomString } from "@/util/common";
|
||||
import { isShareFile } from "@/util/sharePath.ts";
|
||||
import { inject, onMounted, onUnmounted, ref, toRaw } from "vue";
|
||||
import { askAi } from "@/hook/useAi";
|
||||
import { useChooseStore } from "@/stores/choose";
|
||||
@@ -47,11 +47,11 @@ const saveFile = async (e: any) => {
|
||||
ext = data.ext;
|
||||
}
|
||||
const fileName = e.fileName == '' ? data.title : e.fileName
|
||||
let path:string
|
||||
let path: string
|
||||
e.filePath !== ""
|
||||
? (path = `${e.filePath}/${fileName}.${ext}`)
|
||||
: (path = `${SP}C${SP}Users${SP}Desktop${SP}${fileName}.${ext}`);
|
||||
// console.log('路径:',path);
|
||||
// console.log('路径:',path);
|
||||
await writeFile(path, data, e.fileName, true);
|
||||
};
|
||||
eventBus.on("saveFile", saveFile);
|
||||
@@ -78,7 +78,20 @@ const writeFile = async (path: string, data: any, title: string, isNewFile: bool
|
||||
//console.log(data.content)
|
||||
}
|
||||
}
|
||||
const res = await sys?.fs.writeFile(path, data.content);
|
||||
let res = await sys?.fs.writeFile(path, data.content);
|
||||
if (res.code === -1 && res.error == "needPwd") {
|
||||
const temp = await Dialog.showInputBox()
|
||||
if (temp.response !== 1) {
|
||||
return
|
||||
}
|
||||
const header:any = {}
|
||||
header.pwd = temp?.inputPwd ? temp?.inputPwd : ''
|
||||
res = await sys?.fs.writeFile(path, data.content, header);
|
||||
if (res.code === -1) {
|
||||
notifyError(res.message)
|
||||
return
|
||||
}
|
||||
}
|
||||
// console.log("编写文件:", res, isShare);
|
||||
new Notify({
|
||||
title: "提示",
|
||||
@@ -131,24 +144,11 @@ const eventHandler = async (e: MessageEvent) => {
|
||||
hasInit = true;
|
||||
let content = win?.config?.content;
|
||||
let title = win.getTitle();
|
||||
// console.log("win.config;", win?.config);
|
||||
//console.log("win.config;", win?.config);
|
||||
// console.log(title);
|
||||
title = title.split(SP).pop();
|
||||
|
||||
// if (!content && win?.config.path) {
|
||||
// const header = {
|
||||
// pwd: ''
|
||||
// };
|
||||
// const filePwd = getSystemConfig().fileInputPwd
|
||||
// const pos = filePwd.findIndex((item: any) => item.path == win?.config.path)
|
||||
// //console.log('路径:', win?.config.path, pos, filePwd);
|
||||
// const userType = getSystemConfig().userType
|
||||
// if (pos !== -1) {
|
||||
// header.pwd = userType == 'person' ? md5(filePwd[pos].pwd) : filePwd[pos].pwd
|
||||
// }
|
||||
// content = await sys?.fs.readFile(win?.config.path, header);
|
||||
// }
|
||||
content = toRaw(content);
|
||||
|
||||
if (content && content !== "") {
|
||||
storeRef.value?.contentWindow?.postMessage(
|
||||
{
|
||||
@@ -220,21 +220,11 @@ const eventHandler = async (e: MessageEvent) => {
|
||||
);
|
||||
}
|
||||
};
|
||||
//删除本地暂存的文件密码
|
||||
const delFileInputPwd = async () => {
|
||||
let fileInputPwd = getSystemConfig().fileInputPwd;
|
||||
const currentPath = win.config.path;
|
||||
const temp = fileInputPwd.filter(
|
||||
(item: any) => item.path !== currentPath
|
||||
);
|
||||
setSystemKey("fileInputPwd", temp);
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
window.addEventListener("message", eventHandler);
|
||||
});
|
||||
|
||||
onUnmounted(async () => {
|
||||
await delFileInputPwd();
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener("message", eventHandler);
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -13,16 +13,6 @@ export async function handleReadDir(path: any): Promise<any> {
|
||||
}
|
||||
return await res.json();
|
||||
}
|
||||
// 查看分享文件
|
||||
export async function handleReadShareDir(path: string): Promise<any> {
|
||||
// const url = path.indexOf('/F/myshare') !== -1 ? 'sharemylist' : 'sharelist'
|
||||
const url = 'sharelist'
|
||||
const res = await fetchGet(`${API_BASE_URL}/${url}`);
|
||||
if (!res.ok) {
|
||||
return false;
|
||||
}
|
||||
return await res.json();
|
||||
}
|
||||
export async function handleStat(path: string): Promise<any> {
|
||||
const res = await fetchGet(`${API_BASE_URL}/stat?path=${encodeURIComponent(path)}`);
|
||||
if (!res.ok) {
|
||||
@@ -74,7 +64,7 @@ export async function handleReadFile(path: string, header?: any): Promise<any> {
|
||||
pwd: header.pwd !== '' ? md5(header.pwd) : ''
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const res = await fetchGet(`${API_BASE_URL}/readfile?path=${encodeURIComponent(path)}`, head);
|
||||
if (!res.ok) {
|
||||
return false;
|
||||
@@ -99,17 +89,8 @@ export async function handleClear(): Promise<any> {
|
||||
}
|
||||
|
||||
export async function handleRename(oldPath: string, newPath: string): Promise<any> {
|
||||
const url = isShareFile(oldPath) ? 'sharerename' : 'rename'
|
||||
let params = ''
|
||||
if (isShareFile(oldPath)) {
|
||||
const optionID = oldPath.indexOf('/F/myshare') === 0 ? 0 : 1
|
||||
oldPath = turnServePath(oldPath)
|
||||
newPath = turnServePath(newPath)
|
||||
params = `oldpath=${encodeURIComponent(oldPath)}&newpath=${encodeURIComponent(newPath)}&userID=${getSystemConfig()?.userInfo.id}&optionID=${optionID}`
|
||||
} else {
|
||||
params = `oldPath=${encodeURIComponent(oldPath)}&newPath=${encodeURIComponent(newPath)}`
|
||||
}
|
||||
const res = await fetchGet(`${API_BASE_URL}/${url}?${params}`);
|
||||
let params = `oldPath=${encodeURIComponent(oldPath)}&newPath=${encodeURIComponent(newPath)}`
|
||||
const res = await fetchGet(`${API_BASE_URL}/rename?${params}`);
|
||||
if (!res.ok) {
|
||||
return false;
|
||||
}
|
||||
@@ -170,8 +151,8 @@ export function getFormData(content: any) {
|
||||
export async function handleWriteFile(filePath: string, content: any, header?: { [key: string]: any }): Promise<any> {
|
||||
//console.log(content)
|
||||
const formData = getFormData(content);
|
||||
const head:any = header ? { ...header } : {}
|
||||
if(head.pwd && head.pwd !== ''){
|
||||
const head: any = header ? { ...header } : {}
|
||||
if (head.pwd && head.pwd !== '') {
|
||||
head.pwd = md5(head.pwd)
|
||||
}
|
||||
const url = `${API_BASE_URL}/writefile?path=${encodeURIComponent(filePath)}`;
|
||||
@@ -228,22 +209,6 @@ export async function handleUnZip(path: string): Promise<any> {
|
||||
}
|
||||
export const useOsFile = () => {
|
||||
return {
|
||||
// 分享
|
||||
async sharedir(path: string) {
|
||||
// const fun = isRootShare(path) ? handleReadShareDir : handleShareDir
|
||||
const response = await handleReadShareDir(path);
|
||||
if (response && response.data) {
|
||||
const result = response.data.map((item: { [key: string]: OsFile }) => {
|
||||
item.fi.isShare = true
|
||||
item.fi.parentPath = turnLocalPath(item.fi.parentPath, path)
|
||||
item.fi.path = turnLocalPath(item.fi.path, path)
|
||||
//item.fi.titleName = turnLocalPath(item.fi.titleName, path)
|
||||
return item.fi
|
||||
})
|
||||
return result
|
||||
}
|
||||
return [];
|
||||
},
|
||||
|
||||
async readdir(path: string) {
|
||||
const response = await handleReadDir(path);
|
||||
@@ -253,8 +218,6 @@ export const useOsFile = () => {
|
||||
return [];
|
||||
},
|
||||
async stat(path: string) {
|
||||
path.indexOf('/F/myshare') == 0 ? (path = turnServePath(path)) : ''
|
||||
|
||||
const response = await handleStat(path);
|
||||
if (response && response.data) {
|
||||
return response.data;
|
||||
@@ -281,8 +244,8 @@ export const useOsFile = () => {
|
||||
const response = await handleReadFile(path, header);
|
||||
if (response && response.code === 0) {
|
||||
return response.data;
|
||||
}
|
||||
if (response && response.code == -1 && response.message == '加密文件,需要密码') {
|
||||
}
|
||||
if (response && response.code == -1) {
|
||||
return response
|
||||
}
|
||||
return false;
|
||||
@@ -325,22 +288,11 @@ export const useOsFile = () => {
|
||||
return false;
|
||||
},
|
||||
async writeFile(path: string, content: string | Blob, header?: { [key: string]: any }) {
|
||||
let head = {}
|
||||
|
||||
if (header) {
|
||||
head = { ...header }
|
||||
} else {
|
||||
const filePwd = getSystemConfig().fileInputPwd
|
||||
const pos = filePwd.findIndex((item: any) => item.path == path)
|
||||
//console.log('路径:', path, pos, filePwd);
|
||||
const userType = getSystemConfig().userType
|
||||
if (pos !== -1) {
|
||||
head = {
|
||||
pwd: userType == 'person' ? md5(filePwd[pos].pwd) : filePwd[pos].pwd
|
||||
}
|
||||
}
|
||||
}
|
||||
const response = await handleWriteFile(path, content, head);
|
||||
// const head: any = header ? { ...header } : {}
|
||||
// if (head.pwd && head.pwd !== '') {
|
||||
// head.pwd = md5(head.pwd)
|
||||
// }
|
||||
const response = await handleWriteFile(path, content, header);
|
||||
if (response) {
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -454,6 +454,7 @@ export class System {
|
||||
/**打开os 文件系统的文件 */
|
||||
async openFile(path: string) {
|
||||
const fileStat = await this.fs.stat(path)
|
||||
//console.log(fileStat)
|
||||
if (!fileStat) {
|
||||
throw new Error('文件不存在');
|
||||
}
|
||||
@@ -469,36 +470,24 @@ export class System {
|
||||
// 读取文件内容
|
||||
let fileContent = await this.fs.readFile(path, header);
|
||||
// 改文件需要输入密码
|
||||
if (fileContent && fileContent.code == -1 && fileContent.message == '加密文件,需要密码') {
|
||||
if (fileContent && fileContent.code == -1 && fileContent.error == 'needPwd') {
|
||||
const temp = await Dialog.showInputBox()
|
||||
if (temp.response !== 1) {
|
||||
return
|
||||
}
|
||||
// header.salt = filePwd.file.salt || 'vIf_wIUedciAd0nTm6qjJA=='
|
||||
header.pwd = temp?.inputPwd ? temp?.inputPwd : ''
|
||||
const reOpen = await this.fs.readFile(path, header);
|
||||
if (reOpen == false) {
|
||||
//console.log(reOpen)
|
||||
if (reOpen === false || reOpen.code === -1) {
|
||||
notifyError("文件密码错误")
|
||||
return
|
||||
}
|
||||
fileContent = reOpen
|
||||
}
|
||||
//用户文件加密密码存储
|
||||
if (fileStat.isPwd) {
|
||||
let fileInputPwd = getSystemConfig().fileInputPwd
|
||||
const pos = fileInputPwd.findIndex((item: any) => item.path == path)
|
||||
if (pos !== -1) {
|
||||
fileInputPwd[pos].pwd = header.pwd
|
||||
} else {
|
||||
fileInputPwd.push({
|
||||
path: path,
|
||||
pwd: header.pwd
|
||||
})
|
||||
}
|
||||
setSystemKey('fileInputPwd', fileInputPwd)
|
||||
}
|
||||
//console.log(fileStat)
|
||||
// 从_fileOpenerMap中获取文件扩展名对应的函数并调用
|
||||
const fileName = extname(fileStat?.name || '') || 'link'
|
||||
//console.log(fileName,fileContent)
|
||||
this._flieOpenerMap
|
||||
.get(fileName)
|
||||
?.func.call(this, path, fileContent || '');
|
||||
|
||||
Reference in New Issue
Block a user