Browse Source

add:分享文件夹展示

master
prr 8 months ago
parent
commit
30ffd8cd1a
  1. 2
      frontend/components.d.ts
  2. 7
      frontend/src/components/computer/Computer.vue
  3. 5
      frontend/src/components/setting/SetFilePwd.vue
  4. 9
      frontend/src/hook/useComputer.ts
  5. 19
      frontend/src/system/core/FileOs.ts
  6. 13
      frontend/src/system/index.ts
  7. 19
      frontend/src/system/window/Dialog.ts
  8. 7
      frontend/src/util/sharePath.ts

2
frontend/components.d.ts

@ -57,8 +57,6 @@ declare module 'vue' {
ElCarouselItem: typeof import('element-plus/es')['ElCarouselItem']
ElCheckbox: typeof import('element-plus/es')['ElCheckbox']
ElCol: typeof import('element-plus/es')['ElCol']
ElCollapse: typeof import('element-plus/es')['ElCollapse']
ElCollapseItem: typeof import('element-plus/es')['ElCollapseItem']
ElColorPicker: typeof import('element-plus/es')['ElColorPicker']
ElContainer: typeof import('element-plus/es')['ElContainer']
ElDialog: typeof import('element-plus/es')['ElDialog']

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

@ -165,8 +165,7 @@ const { refersh, createFolder, backFolder, openFolder, onComputerMount } = useCo
return system.fs.readdir(path);
},
sharedir(path) {
const val:number = getSystemConfig().userInfo.id
return system.fs.sharedir(val,path)
return system.fs.sharedir(getSystemConfig().userInfo.id,path)
},
exists(path) {
return system.fs.exists(path);
@ -174,6 +173,10 @@ const { refersh, createFolder, backFolder, openFolder, onComputerMount } = useCo
isDirectory(file) {
return file.isDirectory;
},
//
readShareDir(path){
return system.fs.readShareFileDir(getSystemConfig().userInfo.id, path)
},
notify(title, content) {
new Notify({
title,

5
frontend/src/components/setting/SetFilePwd.vue

@ -33,8 +33,7 @@ const params = {
}
//
async function toSetFilePwd() {
//console.log('aaa:',filePwd.value);
params.pwd = filePwd.value === '' ? '' : md5(filePwd.value)
params.pwd = filePwd.value || md5(filePwd.value)
params.isPwd = filePwd.value === '' ? 0 : 1
const url = getApiUrl() + '/file/setfilepwd'
const header = {
@ -50,8 +49,6 @@ async function toSetFilePwd() {
params.pwd = ''
notifyError("设置文件密码失败")
}
//console.log('',params);
setSystemKey('file',params)
}
function clearPwd() {

9
frontend/src/hook/useComputer.ts

@ -1,5 +1,6 @@
import * as fspath from '../system/core/Path';
import { OsFileWithoutContent } from '../system/core/FileSystem';
import { turnFilePath } from "@/util/sharePath.ts";
export type RouterPath = string;
export const useComputer = (adpater: {
@ -15,6 +16,7 @@ export const useComputer = (adpater: {
isDirectory: (file: OsFileWithoutContent) => boolean;
notify: (title: string, content: string) => void;
search: (keyword: string) => Promise<OsFileWithoutContent[]>;
readShareDir: (path: RouterPath) => Promise<OsFileWithoutContent[]>;
}) => {
const isVia = async (path: RouterPath) => {
if (path === '') path = '/';
@ -42,8 +44,10 @@ export const useComputer = (adpater: {
if (!(await isVia(currentPath))) return;
// console.log('use computer refresh:', currentPath);
let result
if (currentPath.substring(0,2) == '/F') {
if (currentPath === '/F/myshare' || currentPath === '/F/othershare') {
result = await adpater.sharedir(currentPath)
} else if (currentPath.indexOf('/F') === 0) {
result = await adpater.readShareDir(currentPath)
} else {
result = await adpater.readdir(currentPath);
}
@ -68,7 +72,8 @@ export const useComputer = (adpater: {
};
const openFolder = (file: OsFileWithoutContent) => {
if (adpater.isDirectory(file)) {
adpater.setRouter(file.path);
const path = file?.isShare ? turnFilePath(file) : file.path
adpater.setRouter(path);
refersh();
} else {
adpater.openFile(file.path);

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

@ -21,6 +21,15 @@ export async function handleReadShareDir(id: number,path: string): Promise<any>
}
return await res.json();
}
// 查看分享文件夹
export async function handleShareDir(id: number,path: string): Promise<any> {
path = turnServePath(path)
const res = await fetchGet(`${API_BASE_URL}/sharedir?id=${id}&dirPath=${path}`);
if (!res.ok) {
return false;
}
return await res.json();
}
// 读文件
export async function handleReadShareFile(path: string): Promise<any> {
path = turnServePath(path)
@ -95,7 +104,6 @@ export async function handleExists(path: string): Promise<any> {
}
export async function handleReadFile(path: string , header?: {[key: string]: string}): Promise<any> {
// console.log('请求头:', header);
const res = await fetchGet(`${API_BASE_URL}/readfile?path=${encodeURIComponent(path)}`, header);
if (!res.ok) {
return false;
@ -248,7 +256,7 @@ export const useOsFile = () => {
},
async readShareFile(path: string) {
const file = await handleShareDetail(path,getSystemConfig()?.userInfo.id)
console.log('文件信息:',file, file.data.fs.is_write);
// console.log('文件信息:',file, file.data.fs.is_write);
if(!file.data.fs.is_write) {
alert('该文件不能编辑')
console.log('该文件不能编辑');
@ -260,6 +268,13 @@ export const useOsFile = () => {
}
return [];
},
async readShareFileDir(id: number, path: string) {
const response = await handleShareDir(id,path);
if (response && response.data) {
return response.data;
}
return [];
},
async getShareInfo(path: string) {
const response = await handleShareDetail(path, getSystemConfig().userInfo.id);
if (response && response.data) {

13
frontend/src/system/index.ts

@ -432,7 +432,6 @@ export class System {
if (isShareFile(path)) {
const arr = path.split('/')
const fileContent = await this.fs.readShareFile(path)
// console.log('阅读:', fileContent);
if (fileContent !== false) {
const fileName = extname(arr[arr.length - 1] || '') || 'link'
this._flieOpenerMap
@ -455,19 +454,23 @@ export class System {
salt: '',
filePwd: ''
}
header.salt = filePwd.file.salt ? filePwd.file.salt : 'vIf_wIUedciAd0nTm6qjJA=='
header.filePwd = filePwd.file.pwd
//判断文件是否需要输入密码
if(fileStat.isPwd && path.indexOf('.exe') === -1) {
const temp = await Dialog.showInputBox(filePwd.file.pwd)
const temp = await Dialog.showInputBox()
if (temp.response !== 1) {
return
}
header.salt = filePwd.file.salt || 'vIf_wIUedciAd0nTm6qjJA=='
header.filePwd = temp?.inputPwd || ''
}
// 读取文件内容
const fileContent = await this.fs.readFile(path, header);
if (!fileContent && fileStat.isPwd){
notifyError('密码错误')
return
}
// 从_fileOpenerMap中获取文件扩展名对应的函数并调用
const fileName = extname(fileStat?.name || '') || 'link'
//console.log(fileName)
this._flieOpenerMap
.get(fileName)
?.func.call(this, path, fileContent || '');

19
frontend/src/system/window/Dialog.ts

@ -1,7 +1,6 @@
import { ElMessageBox } from 'element-plus'
import {BrowserWindow} from "./BrowserWindow"
import { md5 } from "js-md5"
import { notifyError } from "@/util/msg"
class Dialog {
constructor() {
// static class
@ -103,31 +102,27 @@ class Dialog {
return porm;
}
public static showInputBox(correctPwd: string): Promise<{response: number}>{
let promres: (value: { response: number }) => void = () => {
public static showInputBox(): Promise<{response: number, inputPwd?: string}>{
let promres: (value: { response: number, inputPwd?: string }) => void = () => {
// do nothing
};
const porm = new Promise<{
response: number;
response: number,
inputPwd?: string
}>((resolve) => {
promres = resolve;
});
ElMessageBox.prompt('请输入文件加密密码' , '提示', {
inputType: 'password',
confirmButtonText: '确定',
cancelButtonText: '取消',
}).then(({value}) => {
// console.log('正确否:', correctPwd === md5(value));
// console.log('正确密码:', correctPwd);
const isCorrect = md5(value) === correctPwd ? 1 : 0
if(!isCorrect) {
notifyError('密码错误')
}
promres({
response: isCorrect,
response: 1,
inputPwd: md5(value)
});
}).catch(()=>{
console.log('取消');
promres({
response: -1,
});

7
frontend/src/util/sharePath.ts

@ -1,3 +1,4 @@
import { OsFileWithoutContent } from '../system/core/FileSystem';
export function turnServePath(path: string): string {
const replaceUrl = path.indexOf('/F/myshare') === 0 ? '/F/myshare' : '/F/othershare'
return path.replace(replaceUrl, 'data/userData')
@ -8,4 +9,10 @@ export function turnLocalPath(path: string, newTemp: string): string {
export function isShareFile(path: string) : boolean {
// console.log('是否是共享文件:',path,path.indexOf('/F/myshare') === 0 || path.indexOf('/F/othershare') === 0);
return path.indexOf('/F/myshare') === 0 || path.indexOf('/F/othershare') === 0
}
//返回路径
export function turnFilePath(file: OsFileWithoutContent) : string {
// console.log('是否是共享文件:',path,path.indexOf('/F/myshare') === 0 || path.indexOf('/F/othershare') === 0);
const arr = file.path.split('/')
return `/${arr[1]}/${arr[2]}/${arr[arr.length - 1]}`
}
Loading…
Cancel
Save