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:
14
src/controllers/maybeUpdateLastConnectedAt.ts
Normal file
14
src/controllers/maybeUpdateLastConnectedAt.ts
Normal 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();
|
||||
});
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user