-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7157ba5
commit 164e491
Showing
6 changed files
with
102 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { getMeta, setMeta } from "./db"; | ||
|
||
const encoder = new TextEncoder(); | ||
|
||
export function validateSecret(env: Env, secret: string): boolean { | ||
const secretBytes = encoder.encode(env.ADMINISTRATOR_SECRET); | ||
const inputBytes = encoder.encode(secret); | ||
|
||
if (secretBytes.byteLength !== inputBytes.byteLength) { | ||
return false; | ||
} | ||
|
||
return crypto.subtle.timingSafeEqual(secretBytes, inputBytes); | ||
} | ||
|
||
export async function setCommitHash(env: Env, hash: string) { | ||
await setMeta(env, 'commit_hash', hash); | ||
} | ||
|
||
export async function compareCommitHash(env: Env, hash: string): Promise<boolean> { | ||
const storedHash = await getMeta(env, 'commit_hash'); | ||
return storedHash === hash; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// Generated by Wrangler on Mon Jul 15 2024 16:30:44 GMT+0800 (China Standard Time) | ||
// Generated by Wrangler on Wed Jul 17 2024 12:23:04 GMT+0800 (China Standard Time) | ||
// by running `wrangler types` | ||
|
||
interface Env { | ||
ADMINISTRATOR_SECRET: string; | ||
DB: D1Database; | ||
} |