feat: 新增app管理和文件管理

This commit is contained in:
2024-10-06 20:10:20 +08:00
parent 1f81d3400c
commit 477ad00d86
18 changed files with 713 additions and 0 deletions

30
src/routes/file/list.ts Normal file
View File

@@ -0,0 +1,30 @@
import { app } from '@/app.ts';
import { getMinioList } from './module/get-minio-list.ts';
import path from 'path';
import { CustomError } from '@abearxiong/router';
app
.route({
path: 'file',
key: 'list',
middleware: ['auth'],
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
const data = ctx.query.data || {};
const prefixBase = '/' + tokenUser.username;
const handlePrefix = (prefix: string) => {
// 清理所有的 '..'
if (prefix.includes('..')) {
throw new CustomError('invalid prefix');
}
return prefix;
};
const _prefix = handlePrefix(data.prefix);
const prefix = path.join(prefixBase, './', _prefix);
const recursive = data.recursive;
const list = await getMinioList({ prefix: prefix.slice(1), recursive: recursive });
ctx.body = list;
return ctx;
})
.addTo(app);