mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-09 23:49:27 +08:00
* fix: 204 no content response * Update data-wrapping.ts * Update plugin.ts Co-authored-by: chenos <chenlinxh@gmail.com>
41 lines
679 B
TypeScript
41 lines
679 B
TypeScript
import { Context, Next } from '@nocobase/actions';
|
|
|
|
export function dataWrapping() {
|
|
return async function dataWrapping(ctx: Context, next: Next) {
|
|
await next();
|
|
|
|
if (ctx.withoutDataWrapping) {
|
|
return;
|
|
}
|
|
|
|
if (!ctx?.action?.params) {
|
|
return;
|
|
}
|
|
|
|
if (ctx.body instanceof Buffer) {
|
|
return;
|
|
}
|
|
|
|
if (!ctx.body) {
|
|
if (ctx.action.actionName == 'get') {
|
|
ctx.status = 404;
|
|
}
|
|
}
|
|
|
|
const { rows, ...meta } = ctx.body || {};
|
|
|
|
if (rows) {
|
|
ctx.body = {
|
|
data: rows,
|
|
meta,
|
|
};
|
|
} else {
|
|
ctx.body = {
|
|
data: ctx.body,
|
|
};
|
|
}
|
|
};
|
|
}
|
|
|
|
export default dataWrapping;
|