Files
outline/server/routes/api/middlewares/apiResponse.ts
T
Tom Moor 8d44a0fd92 chore: Migrate from JSZip to Yazl (#12408)
* chore: Migrate from JSZip to Yazl

* Add koa stream helper, PR feedback
2026-05-21 23:27:23 -04:00

24 lines
569 B
TypeScript

import stream from "node:stream";
import type { Context, Next } from "koa";
import { Readable } from "readable-stream";
export default function apiResponse() {
return async function apiResponseMiddleware(ctx: Context, next: Next) {
await next();
const ok = ctx.status < 400;
if (
typeof ctx.body === "object" &&
!(ctx.body instanceof Readable) &&
!(ctx.body instanceof stream.Readable) &&
!(ctx.body instanceof Buffer)
) {
ctx.body = {
...ctx.body,
status: ctx.status,
ok,
};
}
};
}