diff --git a/src/controllers/maybeUpdateLastConnectedAt.ts b/src/controllers/maybeUpdateLastConnectedAt.ts new file mode 100644 index 0000000..42d1f66 --- /dev/null +++ b/src/controllers/maybeUpdateLastConnectedAt.ts @@ -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(); +}); diff --git a/src/index.ts b/src/index.ts index 31277f0..b89c6b5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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(