Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.

Commit 347ea57

Browse files
committed
Feat: add file name search
1 parent 8e72d05 commit 347ea57

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/routers/file_router.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ routerApp.use((event, ctx, data, next) => {
3232
routerApp.on("file/list", (ctx, data) => {
3333
try {
3434
const fileManager = getFileManager(data.instanceUuid);
35-
const { page, pageSize, target } = data;
35+
const { page, pageSize, target, fileName } = data;
3636
fileManager.cd(target);
37-
const overview = fileManager.list(page, pageSize);
37+
const overview = fileManager.list(page, pageSize, fileName);
3838
protocol.response(ctx, overview);
3939
} catch (error) {
4040
protocol.responseError(ctx, error);

src/service/system_file.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ export default class FileManager {
6969
this.cwd = path.normalize(path.join(this.cwd, dirName));
7070
}
7171

72-
list(page: 0, pageSize = 40) {
72+
list(page: 0, pageSize = 40, searchFileName?: string) {
7373
if (pageSize > 100 || pageSize <= 0 || page < 0) throw new Error("Beyond the value limit");
74-
const fileNames = fs.readdirSync(this.toAbsolutePath());
74+
let fileNames = fs.readdirSync(this.toAbsolutePath());
75+
if (searchFileName) fileNames = fileNames.filter((name) => name.includes(searchFileName));
76+
7577
const total = fileNames.length;
7678
const sliceStart = page * pageSize;
7779
const sliceEnd = sliceStart + pageSize;

0 commit comments

Comments
 (0)