Browse Source

fix:文件分享接口删除

master
prr 6 months ago
parent
commit
1da8d4e117
  1. 7
      frontend/src/components/builtin/FileList.vue
  2. 15
      frontend/src/components/builtin/FileProps.vue
  3. 34
      frontend/src/components/computer/Computer.vue
  4. 26
      frontend/src/components/window/IframeFile.vue
  5. 106
      frontend/src/system/core/FileOs.ts
  6. 20
      frontend/src/system/index.ts

7
frontend/src/components/builtin/FileList.vue

@ -440,11 +440,6 @@
}); });
} }
const userType = sys.getConfig("userType"); 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) { if (userType == "member" && !item.isShare && !item.isDirectory) {
menuArr.push({ menuArr.push({
label: "分享给...", label: "分享给...",
@ -462,7 +457,6 @@
win.show(); win.show();
}, },
}); });
if (isPwd) {
menuArr.push({ menuArr.push({
label: "文件加密", label: "文件加密",
click: () => { click: () => {
@ -479,7 +473,6 @@
win.show(); win.show();
}, },
}); });
}
// menuArr.push({ // menuArr.push({
// label: "", // label: "",
// click: () => { // click: () => {

15
frontend/src/components/builtin/FileProps.vue

@ -77,12 +77,7 @@ import { isShareFile } from "@/util/sharePath";
const window: BrowserWindow | undefined = inject("browserWindow"); const window: BrowserWindow | undefined = inject("browserWindow");
const file = ref<OsFileWithoutContent | null>(); const file = ref<OsFileWithoutContent | null>();
const path = window?.config.content 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(path);
}
// file.value = await useSystem()?.fs.stat(window?.config.content); // file.value = await useSystem()?.fs.stat(window?.config.content);
function localName<T>(currentPath:T){ function localName<T>(currentPath:T){
if(isShareFile(path) && file.value && file.value.path) { if(isShareFile(path) && file.value && file.value.path) {
@ -109,17 +104,7 @@ function editFileName() {
resizable: false, resizable: false,
}); });
win.on("file.props.edit", async (_: string, data: string) => { 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(); win.show();

34
frontend/src/components/computer/Computer.vue

@ -320,24 +320,7 @@
rdev: 0, rdev: 0,
atime: "", atime: "",
birthtime: "", 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 random = ref(0);
const shareShow = ref(false); const shareShow = ref(false);
@ -403,17 +386,10 @@
async function onTreeOpen(path: string) { async function onTreeOpen(path: string) {
chosenTreePath.value = path; chosenTreePath.value = path;
let file: any; let file: any;
// const file = await system.fs.stat(path); if (path.indexOf('/F') === 0) {
if (isRootShare(path)) { file = shareFileList.value[0]
file = }
path === "/F/myshare" else {
? 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 {
file = await system.fs.stat(path); file = await system.fs.stat(path);
} }
if (file) { if (file) {

26
frontend/src/components/window/IframeFile.vue

@ -56,26 +56,7 @@ const saveFile = async (e: any) => {
}; };
eventBus.on("saveFile", saveFile); eventBus.on("saveFile", saveFile);
const writeFile = async (path: string, data: any, title: string, isNewFile: boolean) => { const writeFile = async (path: string, data: any, title: string, isNewFile: boolean) => {
const isShare = ref(false); if (await sys?.fs.exists(path) && isNewFile) {
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) {
let res = await Dialog.showMessageBox({ let res = await Dialog.showMessageBox({
type: "info", type: "info",
title: "提示", title: "提示",
@ -97,10 +78,7 @@ const writeFile = async (path: string, data: any, title: string, isNewFile: bool
//console.log(data.content) //console.log(data.content)
} }
} }
const res = await sys?.fs.writeFile(path, data.content);
const res = isShare.value
? await sys?.fs.writeShareFile(path, data.content, isWrite.value)
: await sys?.fs.writeFile(path, data.content);
// console.log("", res, isShare); // console.log("", res, isShare);
new Notify({ new Notify({
title: "提示", title: "提示",

106
frontend/src/system/core/FileOs.ts

@ -1,5 +1,5 @@
import { getSystemConfig } from "@/system/config"; 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 { md5 } from "js-md5";
import { fetchGet, fetchPost, getFileUrl } from "../config.ts"; import { fetchGet, fetchPost, getFileUrl } from "../config.ts";
import { OsFileMode } from '../core/FileMode'; 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> { 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}`); const res = await fetchGet(`${API_BASE_URL}/${url}`);
if (!res.ok) { if (!res.ok) {
return false; return false;
} }
return await res.json(); 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> { export async function handleStat(path: string): Promise<any> {
const res = await fetchGet(`${API_BASE_URL}/stat?path=${encodeURIComponent(path)}`); const res = await fetchGet(`${API_BASE_URL}/stat?path=${encodeURIComponent(path)}`);
if (!res.ok) { 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> { export async function handleReadFile(path: string, header?: any): Promise<any> {
//const userType = getSystemConfig().userType //const userType = getSystemConfig().userType
let head = {} let head = {}
if (header) {
head = { head = {
pwd: header.pwd !== '' ? md5(header.pwd) : '' pwd: header.pwd !== '' ? md5(header.pwd) : ''
} }
}
const res = await fetchGet(`${API_BASE_URL}/readfile?path=${encodeURIComponent(path)}`, head); const res = await fetchGet(`${API_BASE_URL}/readfile?path=${encodeURIComponent(path)}`, head);
if (!res.ok) { if (!res.ok) {
return false; return false;
@ -274,8 +230,8 @@ export const useOsFile = () => {
return { return {
// 分享 // 分享
async sharedir(path: string) { async sharedir(path: string) {
const fun = isRootShare(path) ? handleReadShareDir : handleShareDir // const fun = isRootShare(path) ? handleReadShareDir : handleShareDir
const response = await fun(path); const response = await handleReadShareDir(path);
if (response && response.data) { if (response && response.data) {
const result = response.data.map((item: { [key: string]: OsFile }) => { const result = response.data.map((item: { [key: string]: OsFile }) => {
item.fi.isShare = true item.fi.isShare = true
@ -288,39 +244,7 @@ export const useOsFile = () => {
} }
return []; 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) { async readdir(path: string) {
const response = await handleReadDir(path); const response = await handleReadDir(path);
if (response && response.data) { if (response && response.data) {
@ -329,6 +253,8 @@ export const useOsFile = () => {
return []; return [];
}, },
async stat(path: string) { async stat(path: string) {
path.indexOf('/F/myshare') == 0 ? (path = turnServePath(path)) : ''
const response = await handleStat(path); const response = await handleStat(path);
if (response && response.data) { if (response && response.data) {
return response.data; return response.data;
@ -356,14 +282,14 @@ export const useOsFile = () => {
if (response && response.code === 0) { if (response && response.code === 0) {
return response.data; return response.data;
} }
if (response && response.error == 'needPwd') { if (response && response.code == -1 && response.message == '加密文件,需要密码') {
return response return response
} }
return false; return false;
}, },
async unlink(path: string) { async unlink(path: string) {
const fun = path.indexOf('/F') === 0 ? handleShareUnlink : handleUnlink // const fun = path.indexOf('/F') === 0 ? handleShareUnlink : handleUnlink
const response = await fun(path); const response = await handleUnlink(path);
if (response) { if (response) {
return response; return response;
} }
@ -377,8 +303,8 @@ export const useOsFile = () => {
return false; return false;
}, },
async rmdir(path: string) { async rmdir(path: string) {
const fun = path.indexOf('/F') === 0 ? handleShareUnlink : handleRmdir // const fun = path.indexOf('/F') === 0 ? handleShareUnlink : handleRmdir
const response = await fun(path); const response = await handleRmdir(path);
if (response) { if (response) {
return response; return response;
} }

20
frontend/src/system/index.ts

@ -453,18 +453,6 @@ export class System {
} }
/**打开os 文件系统的文件 */ /**打开os 文件系统的文件 */
async openFile(path: string) { 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) const fileStat = await this.fs.stat(path)
if (!fileStat) { if (!fileStat) {
throw new Error('文件不存在'); throw new Error('文件不存在');
@ -480,9 +468,8 @@ export class System {
} }
// 读取文件内容 // 读取文件内容
let fileContent = await this.fs.readFile(path, header); 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() const temp = await Dialog.showInputBox()
if (temp.response !== 1) { if (temp.response !== 1) {
return return
@ -490,8 +477,8 @@ export class System {
// header.salt = filePwd.file.salt || 'vIf_wIUedciAd0nTm6qjJA==' // header.salt = filePwd.file.salt || 'vIf_wIUedciAd0nTm6qjJA=='
header.pwd = temp?.inputPwd ? temp?.inputPwd : '' header.pwd = temp?.inputPwd ? temp?.inputPwd : ''
const reOpen = await this.fs.readFile(path, header); const reOpen = await this.fs.readFile(path, header);
if (reOpen && reOpen.error == 'needPwd') { if (reOpen == false) {
notifyError(reOpen.message) notifyError("文件密码错误")
return return
} }
fileContent = reOpen fileContent = reOpen
@ -517,7 +504,6 @@ export class System {
?.func.call(this, path, fileContent || ''); ?.func.call(this, path, fileContent || '');
} }
} }
}
// 插件系统 // 插件系统
use(func: OsPlugin): void { use(func: OsPlugin): void {
return func(this); return func(this);

Loading…
Cancel
Save