feat: associate device id with username when logging in

This commit is contained in:
2024-09-21 13:16:56 -04:00
parent 209a0b477d
commit c1bf12de4f
8 changed files with 1302 additions and 189 deletions

View File

@@ -5,6 +5,7 @@ import { streamSSE } from "hono/streaming";
import { fetchEpisodes } from "~/controllers/episodes/getByAniListId";
import { maybeScheduleNextAiringEpisode } from "~/libs/maybeScheduleNextAiringEpisode";
import { readEnvVariable } from "~/libs/readEnvVariable";
import { associateDeviceIdWithUsername } from "~/models/token";
import { setWatchStatus } from "~/models/watchStatus";
import type { Env } from "~/types/env";
import { EpisodesResponseSchema } from "~/types/episode";
@@ -60,9 +61,8 @@ const route = createRoute({
const app = new OpenAPIHono<Env>();
app.openapi(route, async (c) => {
// const deviceId = await c.req.header("X-Aniplay-Device-Id");
// const aniListToken = await c.req.header("X-AniList-Token");
const { deviceId, token: aniListToken } = await c.req.query();
const deviceId = await c.req.header("X-Aniplay-Device-Id");
const aniListToken = await c.req.header("X-AniList-Token");
if (!aniListToken) {
return c.json(ErrorResponse, { status: 401 });
@@ -74,6 +74,8 @@ app.openapi(route, async (c) => {
return c.json(ErrorResponse, { status: 401 });
}
await associateDeviceIdWithUsername(env(c, "workerd"), deviceId, username);
return streamSSE(
c,
async (stream) => {