添加删除文件
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { app } from '@/app.ts';
|
||||
import { getFileStat, getMinioList, deleteFile, updateFileStat } from './module/get-minio-list.ts';
|
||||
import { getFileStat, getMinioList, deleteFile, updateFileStat, deleteFiles } from './module/get-minio-list.ts';
|
||||
import path from 'path';
|
||||
import { CustomError } from '@kevisual/router';
|
||||
import { get } from 'http';
|
||||
@@ -147,3 +147,37 @@ app
|
||||
return ctx;
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
app
|
||||
.route({
|
||||
path: 'file',
|
||||
key: 'delete-all',
|
||||
middleware: ['auth'],
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const tokenUser = ctx.state.tokenUser;
|
||||
let directory = ctx.query.data?.directory as string;
|
||||
if (!directory) {
|
||||
ctx.throw(400, 'directory is required');
|
||||
}
|
||||
if (directory.startsWith('/')) {
|
||||
ctx.throw(400, 'directory is invalid, cannot start with /');
|
||||
}
|
||||
if (directory.endsWith('/')) {
|
||||
ctx.throw(400, 'directory is invalid, cannot end with /');
|
||||
}
|
||||
const prefix = tokenUser.username + '/' + directory + '/';
|
||||
const list = await getMinioList<true>({ prefix, recursive: true });
|
||||
if (list.length === 0) {
|
||||
ctx.throw(400, 'directory is empty');
|
||||
}
|
||||
const res = await deleteFiles(list.map((item) => item.name));
|
||||
if (!res) {
|
||||
ctx.throw(500, 'delete all failed');
|
||||
}
|
||||
ctx.body = {
|
||||
deleted: list.length,
|
||||
message: 'delete all success',
|
||||
};
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
Reference in New Issue
Block a user