mirror of
https://github.com/Myzel394/amiopen.now.git
synced 2025-06-18 15:35:27 +02:00
24 lines
552 B
TypeScript
24 lines
552 B
TypeScript
import { createMiddleware } from "hono/factory";
|
|
|
|
export type PresentationType = "terminal" | "browser";
|
|
|
|
const TERMINAL_USER_AGENT = /^(curl|wget|python-urllib|pycurl|java)/i;
|
|
|
|
const presentation = createMiddleware<{
|
|
Variables: {
|
|
presentation: PresentationType;
|
|
};
|
|
}>(async (context, next) => {
|
|
const userAgent = context.req.header("User-Agent") || "";
|
|
|
|
if (TERMINAL_USER_AGENT.test(userAgent)) {
|
|
context.set("presentation", "terminal");
|
|
} else {
|
|
context.set("presentation", "browser");
|
|
}
|
|
|
|
await next();
|
|
});
|
|
|
|
export default presentation;
|