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();
|
||||
});
|
||||
Reference in New Issue
Block a user