-
-
Notifications
You must be signed in to change notification settings - Fork 1
Add Admin API to the backend + more docs and badges #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 7 commits
088a74a
74a4cab
fe00499
719e7e4
15647d9
4c93423
c4f36f9
a84c161
2ba7999
787ee86
ef8bbe2
2740b2a
4d6da15
90646ea
0c90caf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
node_modules | ||
.env.keys | ||
secrets/ | ||
.env.decrypted | ||
*.decrypted |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
deno 2.0.4 | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"recommendations": [ | ||
"denoland.vscode-deno", | ||
"vivaxy.vscode-conventional-commits" | ||
] | ||
} | ||
"recommendations": [ | ||
"denoland.vscode-deno", | ||
"vivaxy.vscode-conventional-commits" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,41 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
import { Bool, OpenAPIRoute, Str } from "chanfana"; | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
import { Context } from "hono"; | ||||||||||||||||||||||||||||||||||||||||||||||
import { z } from "zod"; | ||||||||||||||||||||||||||||||||||||||||||||||
import { handleGitHubAuth, hashToken } from "../lib/githubAuth.ts"; | ||||||||||||||||||||||||||||||||||||||||||||||
import { kv } from "../lib/db.ts"; | ||||||||||||||||||||||||||||||||||||||||||||||
import { config } from "../lib/config.ts"; | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
export class testGitHubAuth extends OpenAPIRoute { | ||||||||||||||||||||||||||||||||||||||||||||||
override schema = { | ||||||||||||||||||||||||||||||||||||||||||||||
tags: ["admin"], | ||||||||||||||||||||||||||||||||||||||||||||||
summary: "Check if you are authenticated or not", | ||||||||||||||||||||||||||||||||||||||||||||||
description: "To avoid wasting GitHub API requests, we'll cache the API results on KV for 5 minutes. You can also use this endpoint to clear the cache by add `?force=1` URL parameter.", | ||||||||||||||||||||||||||||||||||||||||||||||
ajhalili2006 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||
security: [ | ||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||
BearerAuth: [], | ||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||
], | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
override async handle(c: Context) { | ||||||||||||||||||||||||||||||||||||||||||||||
const authHeader = c.req.header("Authorization") | ||||||||||||||||||||||||||||||||||||||||||||||
const parsedAuthHeader = authHeader?.split(" ") || ["bearer", "null"]; | ||||||||||||||||||||||||||||||||||||||||||||||
const tokHash = await hashToken(parsedAuthHeader[1]); | ||||||||||||||||||||||||||||||||||||||||||||||
const key = ["cachedGitHubTokenHash", tokHash]; | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
if (parsedAuthHeader[1] == "null") { | ||||||||||||||||||||||||||||||||||||||||||||||
return c.json({ | ||||||||||||||||||||||||||||||||||||||||||||||
ok: false, | ||||||||||||||||||||||||||||||||||||||||||||||
error: "missing auth key" | ||||||||||||||||||||||||||||||||||||||||||||||
}, 418) | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
ajhalili2006 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
const result = await handleGitHubAuth(parsedAuthHeader[1], true) | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
const dbMeta = await (await kv(config.kvUrl)).get(key) | ||||||||||||||||||||||||||||||||||||||||||||||
return c.json({ | ||||||||||||||||||||||||||||||||||||||||||||||
ok: result, | ||||||||||||||||||||||||||||||||||||||||||||||
result: dbMeta | ||||||||||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||||||||||
|
const dbMeta = await (await kv(config.kvUrl)).get(key) | |
return c.json({ | |
ok: result, | |
result: dbMeta | |
}) | |
try { | |
const dbMeta = await (await kv(config.kvUrl)).get(key) | |
return c.json({ | |
ok: result, | |
result: dbMeta ?? null | |
}) | |
} catch (error) { | |
console.error('KV store error:', error); | |
return c.json({ | |
ok: result, | |
result: null, | |
error: { | |
code: "KV_ERROR", | |
message: "Failed to retrieve cached data" | |
} | |
}, 500) | |
} |
Uh oh!
There was an error while loading. Please reload this page.