Skip to content

Commit

Permalink
文件管理快捷键,进程优化
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaobaidadada committed Nov 26, 2024
1 parent f5c6b3f commit eda968e
Show file tree
Hide file tree
Showing 16 changed files with 551 additions and 326 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "filecat",
"version": "1.0.10",
"version": "1.0.11",
"description": "filecat 文件管理器",
"author": "xiaobaidadada",
"scripts": {
Expand Down Expand Up @@ -73,7 +73,7 @@
"dependencies": {
"@xiaobaidadada/node-pty-prebuilt": "^1.0.4",
"@xiaobaidadada/node-tuntap2-wintun": "^1.0.6",
"node-process-watcher": "^1.0.2",
"node-process-watcher": "^1.0.3",
"node-unrar-js": "^2.0.2",
"ssh2": "^1.15.0"
},
Expand Down
22 changes: 22 additions & 0 deletions src/common/ListUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,28 @@ export function getByList(list, value) {
return list[index];
}

// 获取数组元素的最大值和最小值
export function getMaxByList(list?:number[]) {
if(!list) {
return {};
}
let max;
let min;
for (let v of list) {
if(max === undefined) {
max = v;
} else if (max < v) {
max = v;
}
if (min === undefined) {
min = v;
} else if (min > v) {
min = v;
}
}
return {max,min};
}

// 删除数组中的一个元素,并返回新的数组
export function getNewDeleteByList(list, value) {
const index = list.indexOf(value);
Expand Down
6 changes: 4 additions & 2 deletions src/main/domain/data/DataUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ export class DataUtil {
}

// 上传到临时目录下,并返回文件路径
public static writeFileSyncTemp(filename: string,dir, data: any) {
public static writeFileSyncTemp(filename: string,dir, data?: any) {
const p = path.join(Env.work_dir, dir, filename);
this.checkFile(filename,dir);
fs.writeFileSync(p, data);
if (data) {
fs.writeFileSync(p, data);
}
return p;
}
}
Expand Down
78 changes: 44 additions & 34 deletions src/main/domain/file/file.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,54 +21,64 @@ import {
} from "../../../common/file.pojo";
import {FileServiceImpl} from "./file.service";
import {Result, Sucess} from "../../other/Result";
import multer from 'multer';
import {cutCopyReq, fileInfoReq, fileReq, saveTxtReq} from "../../../common/req/file.req";
import {Cache} from "../../other/cache";
import {msg} from "../../../common/frame/router";
import {CmdType, WsData} from "../../../common/frame/WsData";
import {settingService} from "../setting/setting.service";
import { Request } from 'express';
import {Request, Response} from 'express';


@JsonController("/file")
export class FileController {


@Get()
async getRootFile(@Req() ctx): Promise<Result<GetFilePojo | string>> {
return await FileServiceImpl.getFile('',ctx.headers.authorization);
return await FileServiceImpl.getFile('', ctx.headers.authorization);
}

@Get('/:path([^"]{0,})')
async getFile(@Req() ctx,@Param("path") path?: string,@QueryParam("is_sys_path",{required:false}) is_sys_path?: number): Promise<Result<GetFilePojo | string>> {
return await FileServiceImpl.getFile(path,ctx.headers.authorization,is_sys_path);
async getFile(@Req() ctx, @Param("path") path?: string, @QueryParam("is_sys_path", {required: false}) is_sys_path?: number): Promise<Result<GetFilePojo | string>> {
return await FileServiceImpl.getFile(path, ctx.headers.authorization, is_sys_path);
}

@Post('/file/info')
async getFileInfo(@Req() ctx, @Body() data: {type:FileTypeEnum,path:string}) {
return Sucess(await FileServiceImpl.getFileInfo(data.type,data.path,ctx.headers.authorization));
async getFileInfo(@Req() ctx, @Body() data: { type: FileTypeEnum, path: string }) {
return Sucess(await FileServiceImpl.getFileInfo(data.type, data.path, ctx.headers.authorization));
}

// @Put('/:path([^"]{0,})')
// async uploadFile(@Req() ctx, @Param("path") path?: string, @UploadedFile('file', {options: FileServiceImpl.fileUploadOptions}) file?: any) {
// // await FileServiceImpl.uploadFile(path, file,ctx.headers.authorization);
// return Sucess("1");
// }

@Put('/:path([^"]{0,})')
async uploadFile(@Req() ctx,@Param("path") path?: string, @UploadedFile('file') file?: multer.File) {
await FileServiceImpl.uploadFile(path, file,ctx.headers.authorization);
async uploadFile(@Req() req: Request, @Res() res: Response, @Param("path") path?: string) {
await FileServiceImpl.uploadFile(path, req, res, req.headers.authorization);
return Sucess("1");
}


@Delete('/:path([^"]{0,})')
async deletes(@Req() ctx,@Param("path") path?: string) {
return await FileServiceImpl.deletes(ctx.headers.authorization,path);
async deletes(@Req() ctx, @Param("path") path?: string) {
return await FileServiceImpl.deletes(ctx.headers.authorization, path);
}

@Post('/save/:path([^"]{0,})')
async save(@Req() ctx,@Param("path") path?: string, @Body() data?: saveTxtReq,@QueryParam("is_sys_path",{required:false}) is_sys_path?: number) {
await FileServiceImpl.save(ctx.headers.authorization,data?.context, path,is_sys_path);
async save(@Req() ctx, @Param("path") path?: string, @Body() data?: saveTxtReq, @QueryParam("is_sys_path", {required: false}) is_sys_path?: number) {
await FileServiceImpl.save(ctx.headers.authorization, data?.context, path, is_sys_path);
return Sucess("1");
}

// base保存支持分片 这个框架post默认最大只支持1mb
@Post('/base64/save/:path([^"]{0,})')
async common_base64_save(@Req() ctx,@Param("path") path?: string,@Body() data?: {base64_context:string,type:base64UploadType}) {
await FileServiceImpl.common_base64_save(ctx.headers.authorization,path,data.base64_context,data.type);
async common_base64_save(@Req() ctx, @Param("path") path?: string, @Body() data?: {
base64_context: string,
type: base64UploadType
}) {
await FileServiceImpl.common_base64_save(ctx.headers.authorization, path, data.base64_context, data.type);
return Sucess("1");
}

Expand All @@ -81,38 +91,38 @@ export class FileController {


@Post('/cut')
async cut(@Req() ctx,@Body() data?: cutCopyReq) {
await FileServiceImpl.cut(ctx.headers.authorization,data);
async cut(@Req() ctx, @Body() data?: cutCopyReq) {
await FileServiceImpl.cut(ctx.headers.authorization, data);
return Sucess("1");
}

@Post('/copy')
async copy(@Req() ctx,@Body() data?: cutCopyReq) {
await FileServiceImpl.copy(ctx.headers.authorization,data);
async copy(@Req() ctx, @Body() data?: cutCopyReq) {
await FileServiceImpl.copy(ctx.headers.authorization, data);
return Sucess("1");
}

@Post('/new/file')
async newFile(@Req() ctx,@Body() data?: fileInfoReq) {
await FileServiceImpl.newFile(ctx.headers.authorization,data);
async newFile(@Req() ctx, @Body() data?: fileInfoReq) {
await FileServiceImpl.newFile(ctx.headers.authorization, data);
return Sucess("1");
}

@Post('/new/dir')
async newDir(@Req() ctx ,@Body() data?: fileInfoReq) {
await FileServiceImpl.newDir(ctx.headers.authorization,data);
async newDir(@Req() ctx, @Body() data?: fileInfoReq) {
await FileServiceImpl.newDir(ctx.headers.authorization, data);
return Sucess("1");
}

@Post('/rename')
async rename(@Req() ctx ,@Body() data?: fileInfoReq) {
await FileServiceImpl.rename(ctx.headers.authorization,data);
async rename(@Req() ctx, @Body() data?: fileInfoReq) {
await FileServiceImpl.rename(ctx.headers.authorization, data);
return Sucess("1");
}

// 切换路径
@Post('/base_switch')
async switchBasePath(@Body() data:{root_index:number},@Req() ctx ) {
async switchBasePath(@Body() data: { root_index: number }, @Req() ctx) {
const obj = Cache.getTokenMap().get(ctx.headers.authorization);
if (obj) {
obj["root_index"] = data.root_index;
Expand All @@ -122,14 +132,14 @@ export class FileController {

// 获取主根位置
@Post('/base_switch/get')
async switchGetBasePath(@Req() req: Request ) {
async switchGetBasePath(@Req() req: Request) {
const obj = Cache.getTokenMap().get(req.headers.authorization);
let index;
if (obj["root_index"]!==undefined) {
if (obj["root_index"] !== undefined) {
index = obj["root_index"];
} else {
const list = settingService.getFilesSetting();
for (let i=0;i<list.length;i++) {
for (let i = 0; i < list.length; i++) {
const item = list[i];
if (item.default) {
index = i;
Expand All @@ -140,27 +150,27 @@ export class FileController {
}

@msg(CmdType.file_video_trans)
async file_video_trans(data:WsData<FileVideoFormatTransPojo>) {
async file_video_trans(data: WsData<FileVideoFormatTransPojo>) {
FileServiceImpl.file_video_trans(data);
return ""
}

@msg(CmdType.file_uncompress)
async uncompress(data:WsData<FileCompressPojo>) {
async uncompress(data: WsData<FileCompressPojo>) {
FileServiceImpl.uncompress(data);
return ""
}

@msg(CmdType.file_compress)
async compress(data:WsData<FileCompressPojo>) {
async compress(data: WsData<FileCompressPojo>) {
FileServiceImpl.FileCompress(data);
return ""
}

// 获取studio路径
@Post("/studio/get/item")
async studio_get_item(@Body() data:{path:string},@Req() ctx ) {
return Sucess(await FileServiceImpl.studio_get_item(data.path,ctx.headers.authorization));
async studio_get_item(@Body() data: { path: string }, @Req() ctx) {
return Sucess(await FileServiceImpl.studio_get_item(data.path, ctx.headers.authorization));
}

}
Loading

0 comments on commit eda968e

Please sign in to comment.