脚本管理忽略符号文件

This commit is contained in:
whyour 2023-12-23 00:28:31 +08:00
parent 62168979e3
commit 2713942a68
2 changed files with 41 additions and 29 deletions

View File

@ -34,7 +34,14 @@ export default (app: Router) => {
const logger: Logger = Container.get('logger'); const logger: Logger = Container.get('logger');
try { try {
let result = []; let result = [];
const blacklist = ['node_modules', '.git', '.pnpm']; const blacklist = [
'node_modules',
'.git',
'.pnpm',
'pnpm-lock.yaml',
'yarn.lock',
'package-lock.json',
];
if (req.query.path) { if (req.query.path) {
const targetPath = path.join( const targetPath = path.join(
config.scriptPath, config.scriptPath,

View File

@ -251,34 +251,39 @@ export async function readDirs(
): Promise<IFile[]> { ): Promise<IFile[]> {
const relativePath = path.relative(baseDir, dir); const relativePath = path.relative(baseDir, dir);
const files = await fs.readdir(dir); const files = await fs.readdir(dir);
const result: IFile[] = await Promise.all( const result: IFile[] = [];
files
.filter((x) => !blacklist.includes(x)) for (const file of files) {
.map(async (file: string) => {
const subPath = path.join(dir, file); const subPath = path.join(dir, file);
const stats = await fs.stat(subPath); const stats = await fs.stat(subPath);
const key = path.join(relativePath, file); const key = path.join(relativePath, file);
if (blacklist.includes(file) || stats.isSymbolicLink()) {
continue;
}
if (stats.isDirectory()) { if (stats.isDirectory()) {
return { const children = await readDirs(subPath, baseDir, blacklist, sort);
result.push({
title: file, title: file,
key, key,
type: 'directory', type: 'directory',
parent: relativePath, parent: relativePath,
mtime: stats.mtime.getTime(), mtime: stats.mtime.getTime(),
children: (await readDirs(subPath, baseDir)).sort(sort), children: children.sort(sort),
}; });
} } else {
return { result.push({
title: file, title: file,
type: 'file', type: 'file',
isLeaf: true,
key, key,
parent: relativePath, parent: relativePath,
size: stats.size, size: stats.size,
mtime: stats.mtime.getTime(), mtime: stats.mtime.getTime(),
}; });
}), }
); }
return result.sort(sort); return result.sort(sort);
} }