27 lines
924 B
TypeScript
27 lines
924 B
TypeScript
import { zValidator } from "@hono/zod-validator"
|
|
import { Hono } from "hono"
|
|
import { gogAuthInput, gogGamesInput } from "./schema.ts"
|
|
import { exchangeGogCode, fetchGogGames } from "./service.ts"
|
|
|
|
export const gogRouter = new Hono()
|
|
.post("/auth", zValidator("json", gogAuthInput), async (c) => {
|
|
try {
|
|
const { code } = c.req.valid("json")
|
|
const result = await exchangeGogCode(code)
|
|
return c.json(result)
|
|
} catch (err) {
|
|
const message = err instanceof Error ? err.message : "Unknown error"
|
|
return c.json({ error: message }, 500)
|
|
}
|
|
})
|
|
.post("/games", zValidator("json", gogGamesInput), async (c) => {
|
|
try {
|
|
const { accessToken, refreshToken } = c.req.valid("json")
|
|
const result = await fetchGogGames(accessToken, refreshToken)
|
|
return c.json(result)
|
|
} catch (err) {
|
|
const message = err instanceof Error ? err.message : "Unknown error"
|
|
return c.json({ error: message }, 500)
|
|
}
|
|
})
|