mirror of
https://gitee.com/godoos/godoos.git
synced 2026-11-20 07:49:34 +08:00
fix:文件分享接口删除
This commit is contained in:
@@ -440,11 +440,6 @@
|
||||
});
|
||||
}
|
||||
const userType = sys.getConfig("userType");
|
||||
interface UserInfo {
|
||||
isPwd?: boolean
|
||||
}
|
||||
const userInfo = sys.getConfig("userInfo") as UserInfo
|
||||
const isPwd = userInfo?.isPwd || false;
|
||||
if (userType == "member" && !item.isShare && !item.isDirectory) {
|
||||
menuArr.push({
|
||||
label: "分享给...",
|
||||
@@ -462,24 +457,22 @@
|
||||
win.show();
|
||||
},
|
||||
});
|
||||
if (isPwd) {
|
||||
menuArr.push({
|
||||
label: "文件加密",
|
||||
click: () => {
|
||||
const win = new BrowserWindow({
|
||||
title: "文件加密",
|
||||
content: "FilePwd",
|
||||
config: {
|
||||
path: item.path,
|
||||
},
|
||||
width: 400,
|
||||
height: 200,
|
||||
center: true,
|
||||
});
|
||||
win.show();
|
||||
},
|
||||
});
|
||||
}
|
||||
menuArr.push({
|
||||
label: "文件加密",
|
||||
click: () => {
|
||||
const win = new BrowserWindow({
|
||||
title: "文件加密",
|
||||
content: "FilePwd",
|
||||
config: {
|
||||
path: item.path,
|
||||
},
|
||||
width: 400,
|
||||
height: 200,
|
||||
center: true,
|
||||
});
|
||||
win.show();
|
||||
},
|
||||
});
|
||||
// menuArr.push({
|
||||
// label: "评论",
|
||||
// click: () => {
|
||||
|
||||
@@ -77,12 +77,7 @@ import { isShareFile } from "@/util/sharePath";
|
||||
const window: BrowserWindow | undefined = inject("browserWindow");
|
||||
const file = ref<OsFileWithoutContent | null>();
|
||||
const path = window?.config.content
|
||||
if(path.indexOf('/F') === 0) {
|
||||
file.value = (await useSystem()?.fs.getShareInfo(path)).fi
|
||||
// file.value.path = file.value.titleName || file.value.path
|
||||
} else {
|
||||
file.value = await useSystem()?.fs.stat(path);
|
||||
}
|
||||
// file.value = await useSystem()?.fs.stat(window?.config.content);
|
||||
function localName<T>(currentPath:T){
|
||||
if(isShareFile(path) && file.value && file.value.path) {
|
||||
@@ -109,17 +104,7 @@ function editFileName() {
|
||||
resizable: false,
|
||||
});
|
||||
win.on("file.props.edit", async (_: string, data: string) => {
|
||||
//console.log('文件信息:', file.value, data);
|
||||
if(data.indexOf('data/userData') === 0) {
|
||||
const newPathArr = data.split('/')
|
||||
const pathArr = file.value?.path.split('/') || []
|
||||
pathArr.pop()
|
||||
pathArr.push(newPathArr.pop() || '')
|
||||
const shareInfo = await useSystem()?.fs.getShareInfo(pathArr.join('/'))
|
||||
file.value = shareInfo?.fi
|
||||
} else {
|
||||
file.value = await useSystem()?.fs.stat(data);
|
||||
}
|
||||
file.value = await useSystem()?.fs.stat(data);
|
||||
});
|
||||
|
||||
win.show();
|
||||
|
||||
@@ -320,24 +320,7 @@
|
||||
rdev: 0,
|
||||
atime: "",
|
||||
birthtime: "",
|
||||
},
|
||||
{
|
||||
ext: "",
|
||||
isDirectory: true,
|
||||
isFile: false,
|
||||
isSymlink: false,
|
||||
mode: 2147484141,
|
||||
name: "othershare",
|
||||
oldPath: "/F/othershare",
|
||||
parentPath: "/F",
|
||||
path: "/F/othershare",
|
||||
title: "othershare",
|
||||
size: 64,
|
||||
mtime: "",
|
||||
rdev: 0,
|
||||
atime: "",
|
||||
birthtime: "",
|
||||
},
|
||||
}
|
||||
]);
|
||||
const random = ref(0);
|
||||
const shareShow = ref(false);
|
||||
@@ -403,17 +386,10 @@
|
||||
async function onTreeOpen(path: string) {
|
||||
chosenTreePath.value = path;
|
||||
let file: any;
|
||||
// const file = await system.fs.stat(path);
|
||||
if (isRootShare(path)) {
|
||||
file =
|
||||
path === "/F/myshare"
|
||||
? shareFileList.value[0]
|
||||
: shareFileList.value[1];
|
||||
} else if (isShareFile(path)) {
|
||||
file = await system.fs.getShareInfo(path);
|
||||
file = file.fi;
|
||||
file.path = turnLocalPath(file.path, path, 1);
|
||||
} else {
|
||||
if (path.indexOf('/F') === 0) {
|
||||
file = shareFileList.value[0]
|
||||
}
|
||||
else {
|
||||
file = await system.fs.stat(path);
|
||||
}
|
||||
if (file) {
|
||||
|
||||
@@ -56,26 +56,7 @@ const saveFile = async (e: any) => {
|
||||
};
|
||||
eventBus.on("saveFile", saveFile);
|
||||
const writeFile = async (path: string, data: any, title: string, isNewFile: boolean) => {
|
||||
const isShare = ref(false);
|
||||
const isWrite = ref(0);
|
||||
if (isShareFile(path)) {
|
||||
const file = await sys?.fs.getShareInfo(path);
|
||||
isShare.value = true;
|
||||
isWrite.value =
|
||||
file.fs.sender === getSystemConfig().userInfo.id
|
||||
? 1
|
||||
: file.fs.is_write;
|
||||
if (
|
||||
!isWrite.value &&
|
||||
file.fs.sender !== getSystemConfig().userInfo.id
|
||||
) {
|
||||
new Notify({
|
||||
title: "提示",
|
||||
content: "该文件没有编辑权限",
|
||||
});
|
||||
return;
|
||||
}
|
||||
} else if (await sys?.fs.exists(path) && isNewFile) {
|
||||
if (await sys?.fs.exists(path) && isNewFile) {
|
||||
let res = await Dialog.showMessageBox({
|
||||
type: "info",
|
||||
title: "提示",
|
||||
@@ -97,10 +78,7 @@ const writeFile = async (path: string, data: any, title: string, isNewFile: bool
|
||||
//console.log(data.content)
|
||||
}
|
||||
}
|
||||
|
||||
const res = isShare.value
|
||||
? await sys?.fs.writeShareFile(path, data.content, isWrite.value)
|
||||
: await sys?.fs.writeFile(path, data.content);
|
||||
const res = await sys?.fs.writeFile(path, data.content);
|
||||
// console.log("编写文件:", res, isShare);
|
||||
new Notify({
|
||||
title: "提示",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { getSystemConfig } from "@/system/config";
|
||||
import { isRootShare, isShareFile, turnLocalPath, turnServePath } from "@/util/sharePath.ts";
|
||||
import { isShareFile, turnLocalPath, turnServePath } from "@/util/sharePath.ts";
|
||||
import { md5 } from "js-md5";
|
||||
import { fetchGet, fetchPost, getFileUrl } from "../config.ts";
|
||||
import { OsFileMode } from '../core/FileMode';
|
||||
@@ -15,61 +15,14 @@ export async function handleReadDir(path: any): Promise<any> {
|
||||
}
|
||||
// 查看分享文件
|
||||
export async function handleReadShareDir(path: string): Promise<any> {
|
||||
const url = path.indexOf('/F/myshare') !== -1 ? 'sharemylist' : 'sharelist'
|
||||
// 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 handleShareDir(path: string): Promise<any> {
|
||||
path = turnServePath(path)
|
||||
const res = await fetchGet(`${API_BASE_URL}/sharedir?dirPath=${path}`);
|
||||
if (!res.ok) {
|
||||
return false;
|
||||
}
|
||||
return await res.json();
|
||||
}
|
||||
// 读文件
|
||||
export async function handleReadShareFile(path: string): Promise<any> {
|
||||
path = turnServePath(path)
|
||||
const res = await fetchGet(`${API_BASE_URL}/shareread?path=${path}`);
|
||||
if (!res.ok) {
|
||||
return false;
|
||||
}
|
||||
return await res.json();
|
||||
}
|
||||
// 删除分享文件
|
||||
export async function handleShareUnlink(path: string): Promise<any> {
|
||||
const file = await handleShareDetail(path)
|
||||
path = turnServePath(path)
|
||||
const res = await fetchGet(`${API_BASE_URL}/sharedelete?senderid=${file.data.fs.sender}&path=${path}&receverid=${file.data.fs.recever}`);
|
||||
if (!res.ok) {
|
||||
return false;
|
||||
}
|
||||
return await res.json();
|
||||
}
|
||||
// 查看文件信息
|
||||
export async function handleShareDetail(path: string): Promise<any> {
|
||||
const sig = path.indexOf('/F/myshare') === 0 ? 0 : 1
|
||||
path = turnServePath(path)
|
||||
|
||||
const res = await fetchGet(`${API_BASE_URL}/shareinfo?path=${path}&sig=${sig}`);
|
||||
if (!res.ok) {
|
||||
return false;
|
||||
}
|
||||
return await res.json();
|
||||
}
|
||||
// 编写共享文件
|
||||
export async function handleWriteShareFile(path: string, content: any, isWrite: number): Promise<any> {
|
||||
const formData = getFormData(content);
|
||||
const res = await fetchPost(`${API_BASE_URL}/writewithchmod?path=${path}&iswrite=${isWrite}`, formData);
|
||||
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) {
|
||||
@@ -116,9 +69,12 @@ export async function handleExists(path: string): Promise<any> {
|
||||
export async function handleReadFile(path: string, header?: any): Promise<any> {
|
||||
//const userType = getSystemConfig().userType
|
||||
let head = {}
|
||||
head = {
|
||||
pwd: header.pwd !== '' ? md5(header.pwd) : ''
|
||||
if (header) {
|
||||
head = {
|
||||
pwd: header.pwd !== '' ? md5(header.pwd) : ''
|
||||
}
|
||||
}
|
||||
|
||||
const res = await fetchGet(`${API_BASE_URL}/readfile?path=${encodeURIComponent(path)}`, head);
|
||||
if (!res.ok) {
|
||||
return false;
|
||||
@@ -274,8 +230,8 @@ export const useOsFile = () => {
|
||||
return {
|
||||
// 分享
|
||||
async sharedir(path: string) {
|
||||
const fun = isRootShare(path) ? handleReadShareDir : handleShareDir
|
||||
const response = await fun(path);
|
||||
// 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
|
||||
@@ -288,39 +244,7 @@ export const useOsFile = () => {
|
||||
}
|
||||
return [];
|
||||
},
|
||||
async readShareFile(path: string) {
|
||||
const response = await handleReadShareFile(path);
|
||||
if (response && response.data) {
|
||||
return response.data;
|
||||
}
|
||||
return [];
|
||||
},
|
||||
//分享文件夹取消
|
||||
async readShareFileDir(path: string) {
|
||||
const response = await handleShareDir(path)
|
||||
if (response && response.data) {
|
||||
return response.data
|
||||
}
|
||||
return []
|
||||
},
|
||||
async getShareInfo(path: string) {
|
||||
const response = await handleShareDetail(path);
|
||||
if (response && response.data) {
|
||||
response.data.fi.isShare = true
|
||||
response.data.fi.path = turnLocalPath(response.data.fi.path, path, 1)
|
||||
return response.data;
|
||||
}
|
||||
return [];
|
||||
},
|
||||
//编写共享文件
|
||||
async writeShareFile(path: string, content: any, isWrite: number) {
|
||||
path = turnServePath(path)
|
||||
const response = await handleWriteShareFile(path, content, isWrite);
|
||||
if (response) {
|
||||
return response;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
async readdir(path: string) {
|
||||
const response = await handleReadDir(path);
|
||||
if (response && response.data) {
|
||||
@@ -329,6 +253,8 @@ 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;
|
||||
@@ -356,14 +282,14 @@ export const useOsFile = () => {
|
||||
if (response && response.code === 0) {
|
||||
return response.data;
|
||||
}
|
||||
if (response && response.error == 'needPwd') {
|
||||
if (response && response.code == -1 && response.message == '加密文件,需要密码') {
|
||||
return response
|
||||
}
|
||||
return false;
|
||||
},
|
||||
async unlink(path: string) {
|
||||
const fun = path.indexOf('/F') === 0 ? handleShareUnlink : handleUnlink
|
||||
const response = await fun(path);
|
||||
// const fun = path.indexOf('/F') === 0 ? handleShareUnlink : handleUnlink
|
||||
const response = await handleUnlink(path);
|
||||
if (response) {
|
||||
return response;
|
||||
}
|
||||
@@ -377,8 +303,8 @@ export const useOsFile = () => {
|
||||
return false;
|
||||
},
|
||||
async rmdir(path: string) {
|
||||
const fun = path.indexOf('/F') === 0 ? handleShareUnlink : handleRmdir
|
||||
const response = await fun(path);
|
||||
// const fun = path.indexOf('/F') === 0 ? handleShareUnlink : handleRmdir
|
||||
const response = await handleRmdir(path);
|
||||
if (response) {
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -453,18 +453,6 @@ export class System {
|
||||
}
|
||||
/**打开os 文件系统的文件 */
|
||||
async openFile(path: string) {
|
||||
//判断是否是共享文件
|
||||
if (isShareFile(path)) {
|
||||
const arr = path.split('/')
|
||||
const fileContent = await this.fs.readShareFile(path)
|
||||
if (fileContent !== false) {
|
||||
const fileName = extname(arr[arr.length - 1] || '') || 'link'
|
||||
this._flieOpenerMap
|
||||
.get(fileName)
|
||||
?.func.call(this, path, fileContent || '');
|
||||
}
|
||||
} else {
|
||||
//console.log(path)
|
||||
const fileStat = await this.fs.stat(path)
|
||||
if (!fileStat) {
|
||||
throw new Error('文件不存在');
|
||||
@@ -480,9 +468,8 @@ export class System {
|
||||
}
|
||||
// 读取文件内容
|
||||
let fileContent = await this.fs.readFile(path, header);
|
||||
console.log(fileContent)
|
||||
// 改文件需要输入密码
|
||||
if (fileContent && fileContent.error == 'needPwd') {
|
||||
if (fileContent && fileContent.code == -1 && fileContent.message == '加密文件,需要密码') {
|
||||
const temp = await Dialog.showInputBox()
|
||||
if (temp.response !== 1) {
|
||||
return
|
||||
@@ -490,8 +477,8 @@ export class System {
|
||||
// header.salt = filePwd.file.salt || 'vIf_wIUedciAd0nTm6qjJA=='
|
||||
header.pwd = temp?.inputPwd ? temp?.inputPwd : ''
|
||||
const reOpen = await this.fs.readFile(path, header);
|
||||
if (reOpen && reOpen.error == 'needPwd') {
|
||||
notifyError(reOpen.message)
|
||||
if (reOpen == false) {
|
||||
notifyError("文件密码错误")
|
||||
return
|
||||
}
|
||||
fileContent = reOpen
|
||||
@@ -515,7 +502,6 @@ export class System {
|
||||
this._flieOpenerMap
|
||||
.get(fileName)
|
||||
?.func.call(this, path, fileContent || '');
|
||||
}
|
||||
}
|
||||
}
|
||||
// 插件系统
|
||||
|
||||
Reference in New Issue
Block a user