feat: use hono context json and text
This commit is contained in:
@@ -14,15 +14,12 @@ const middleware: MiddlewareHandler = async (ctx, next) => {
|
||||
// only enable when debugInfo=true
|
||||
if (config.debugInfo) {
|
||||
if (outputType === 'debug.json') {
|
||||
ctx.header('Content-Type', 'application/json; charset=UTF-8');
|
||||
return ctx.body(ctx.get('json') ? JSON.stringify(ctx.get('json'), null, 4) : JSON.stringify({ message: 'plugin does not set debug json' }));
|
||||
return ctx.json(ctx.get('json') || { message: 'plugin does not set debug json' });
|
||||
}
|
||||
|
||||
if (/(\d+)\.debug\.html$/.test(outputType)) {
|
||||
ctx.header('Content-Type', 'text/html; charset=UTF-8');
|
||||
|
||||
const index = Number.parseInt(outputType.match(/(\d+)\.debug\.html$/)?.[1] || '0');
|
||||
return ctx.body(data?.item?.[index]?.description || `data.item[${index}].description not found`);
|
||||
return ctx.text(data?.item?.[index]?.description || `data.item[${index}].description not found`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,8 +84,7 @@ const middleware: MiddlewareHandler = async (ctx, next) => {
|
||||
}
|
||||
|
||||
if (outputType === 'ums') {
|
||||
ctx.header('Content-Type', 'application/json; charset=UTF-8');
|
||||
return ctx.body(rss3Ums(result));
|
||||
return ctx.json(rss3Ums(result));
|
||||
} else if (outputType === 'json') {
|
||||
ctx.header('Content-Type', 'application/feed+json; charset=UTF-8');
|
||||
return ctx.body(json(result));
|
||||
|
||||
Reference in New Issue
Block a user