feat: add middleware to update "last connected at" when a request comes in

relies on a header named "X-Aniplay-Device-Id"
This commit is contained in:
2024-09-08 16:32:31 -05:00
parent 01aef0ad95
commit cc9bb8ab4d
2 changed files with 18 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
import { createMiddleware } from "hono/factory";
import { updateDeviceLastConnectedAt } from "~/models/token";
export const maybeUpdateLastConnectedAt = createMiddleware(async (c, next) => {
const deviceId = await c.req.header("X-Aniplay-Device-Id");
console.log("deviceId", deviceId);
if (!deviceId) {
return next();
}
await updateDeviceLastConnectedAt(c.env, deviceId);
return next();
});

View File

@@ -1,8 +1,12 @@
import { swaggerUI } from "@hono/swagger-ui";
import { OpenAPIHono } from "@hono/zod-openapi";
import { maybeUpdateLastConnectedAt } from "~/controllers/maybeUpdateLastConnectedAt";
const app = new OpenAPIHono();
app.use(maybeUpdateLastConnectedAt);
app.route(
"/",
await import("~/controllers/health-check").then(