(
Extension(current_user): Extension<Option<User>>,
req: Request<B>,
next: Next<B>,
)
| 78 | } |
| 79 | |
| 80 | pub async fn valid_openai_api_key<B>( |
| 81 | Extension(current_user): Extension<Option<User>>, |
| 82 | req: Request<B>, |
| 83 | next: Next<B>, |
| 84 | ) -> Response |
| 85 | where |
| 86 | B: Send + 'static, |
| 87 | { |
| 88 | let key = current_user |
| 89 | .unwrap() |
| 90 | .openai_api_key |
| 91 | .unwrap_or(String::new()); |
| 92 | |
| 93 | let client = reqwest::Client::new(); |
| 94 | match client |
| 95 | .get("https://api.openai.com/v1/engines") |
| 96 | .bearer_auth(&key) |
| 97 | .send() |
| 98 | .await |
| 99 | { |
| 100 | Ok(res) => { |
| 101 | if res.status().is_success() { |
| 102 | next.run(req).await |
| 103 | } else { |
| 104 | println!("failure!"); |
| 105 | error_response(403, "You API key is not set or invalid. Go to Settings.") |
| 106 | } |
| 107 | } |
| 108 | Err(_) => error_response(403, "You API key is not set or invalid. Go to Settings"), |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | pub async fn handle_error<B>( |
| 113 | Extension(current_user): Extension<Option<User>>, |
nothing calls this directly
no test coverage detected