mirror of
https://github.com/Myzel394/amiopen.now.git
synced 2025-06-18 15:35:27 +02:00
29 lines
743 B
TypeScript
29 lines
743 B
TypeScript
import { createMiddleware } from "hono/factory";
|
|
|
|
export type PresentationType = "terminal" | "browser" | "cli-browser";
|
|
|
|
const TERMINAL_USER_AGENT =
|
|
/^(curl|wget|python-urllib|pycurl|java|go-http-client|php)/i;
|
|
|
|
const CLI_BROWSER_USER_AGENT = /^(lynx|elinks|w3m)/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 if (CLI_BROWSER_USER_AGENT.test(userAgent)) {
|
|
context.set("presentation", "cli-browser");
|
|
} else {
|
|
context.set("presentation", "browser");
|
|
}
|
|
|
|
await next();
|
|
});
|
|
|
|
export default presentation;
|