mirror of
				https://github.com/monkeytypegame/monkeytype.git
				synced 2025-10-31 11:16:08 +08:00 
			
		
		
		
	* Migrate some utils to TS * Add argument type * Fix logic * Refactor math functions * Rename function
		
			
				
	
	
		
			24 lines
		
	
	
	
		
			642 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			24 lines
		
	
	
	
		
			642 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import fetch from "node-fetch";
 | |
| 
 | |
| interface CaptchaData {
 | |
|   success: boolean;
 | |
|   challenge_ts?: number;
 | |
|   hostname: string;
 | |
|   "error-codes"?: string[];
 | |
| }
 | |
| 
 | |
| export async function verify(captcha: string): Promise<boolean> {
 | |
|   if (process.env.MODE === "dev") {
 | |
|     return true;
 | |
|   }
 | |
|   const response = await fetch(
 | |
|     `https://www.google.com/recaptcha/api/siteverify`,
 | |
|     {
 | |
|       method: "POST",
 | |
|       headers: { "Content-Type": "application/x-www-form-urlencoded" },
 | |
|       body: `secret=${process.env.RECAPTCHA_SECRET}&response=${captcha}`,
 | |
|     }
 | |
|   );
 | |
|   const captchaData = (await response.json()) as CaptchaData;
 | |
|   return captchaData.success;
 | |
| }
 |