Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions optifit app/lib/config/api_constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ class ApiConstants {
// Gemini API configuration (new primary API)
static const String geminiApiEndpoint =
'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent';

static final String geminiApiKey = dotenv.env['GEMINI_API_KEY']!;

// New: Centralized endpoint for chat functionalities
static const String chatApiEndpoint =
'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent';

Comment on lines 10 to 12
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Unify endpoint and harden API key access.

  • Avoid duplicate URL constants: point chatApiEndpoint to geminiApiEndpoint.
  • Don’t crash on missing GEMINI_API_KEY; fail fast with a clear error.
- static const String chatApiEndpoint =
-     'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent';
+ static const String chatApiEndpoint = geminiApiEndpoint;
@@
- static final String geminiApiKey = dotenv.env['GEMINI_API_KEY']!;
+ static String get geminiApiKey {
+   final key = dotenv.env['GEMINI_API_KEY'];
+   if (key == null || key.isEmpty) {
+     throw StateError('GEMINI_API_KEY is not set');
+   }
+   return key;
+ }
@@
- static Map<String, String> get geminiHeaders => {'Content-Type': 'application/json', 'x-goog-api-key': geminiApiKey};
+ static Map<String, String> get geminiHeaders => {
+   'Content-Type': 'application/json',
+   'x-goog-api-key': geminiApiKey,
+ };

Also applies to: 22-24

🤖 Prompt for AI Agents
In optifit app/lib/config/api_constants.dart around lines 10-12 and 22-24, the
chatApiEndpoint is duplicated and API key access can crash silently; refactor so
chatApiEndpoint references the single geminiApiEndpoint constant (remove the
duplicate literal), and harden GEMINI_API_KEY retrieval by checking for
null/empty and throwing a clear, early exception (or returning a typed failure)
with a descriptive message instead of allowing a runtime null error—ensure
callers expect/handle that error.

// API endpoints for squat analysis server
static final String squatServerUpload =
'${dotenv.env['NGROK_FORWARDING_URL']!}/upload';
static final String squatServerResult =
'${dotenv.env['NGROK_FORWARDING_URL']!}/result';
// WORKING: Your exercise detection server (local ip v4 address used)
static const String exerciseServerUpload = 'http://127.0.0.0:5000/upload';
static const String exerciseServerResult = 'http://127.0.0.0:5000/result';

static const String pushupServerUpload = exerciseServerUpload;
static const String pushupServerResult = exerciseServerResult;
static const String squatServerUpload = exerciseServerUpload;
static const String squatServerResult = exerciseServerResult;
Comment on lines +14 to +20
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Blocking: invalid loopback IP (127.0.0.0) will fail requests.

Use 127.0.0.1 (or env-provided base URL). Current constants will never reach the local Flask server.

Apply:

- static const String exerciseServerUpload = 'http://127.0.0.0:5000/upload';
- static const String exerciseServerResult = 'http://127.0.0.0:5000/result';
+ static const String exerciseServerUpload = 'http://127.0.0.1:5000/upload';
+ static const String exerciseServerResult = 'http://127.0.0.1:5000/result';

Recommended: read a base URL from .env (EXERCISE_SERVER_BASE_URL) and derive all four endpoints.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
static const String exerciseServerUpload = 'http://127.0.0.0:5000/upload';
static const String exerciseServerResult = 'http://127.0.0.0:5000/result';
static const String pushupServerUpload = exerciseServerUpload;
static const String pushupServerResult = exerciseServerResult;
static const String squatServerUpload = exerciseServerUpload;
static const String squatServerResult = exerciseServerResult;
static const String exerciseServerUpload = 'http://127.0.0.1:5000/upload';
static const String exerciseServerResult = 'http://127.0.0.1:5000/result';
static const String pushupServerUpload = exerciseServerUpload;
static const String pushupServerResult = exerciseServerResult;
static const String squatServerUpload = exerciseServerUpload;
static const String squatServerResult = exerciseServerResult;
🤖 Prompt for AI Agents
In optifit app/lib/config/api_constants.dart around lines 14 to 20, the
endpoints use the invalid loopback IP 127.0.0.0 which will never reach a local
Flask server; change the base host to 127.0.0.1 or, better, read a base URL from
an environment variable (EXERCISE_SERVER_BASE_URL) and derive the four endpoints
from that base (e.g. `${base}/upload` and `${base}/result`), falling back to
'http://127.0.0.1:5000' if the env var is missing; update the four constants to
use the computed base and ensure any consumers import the updated constants.


// API headers for Gemini
static Map<String, String> get geminiHeaders => {
'Content-Type': 'application/json',
'x-goog-api-key': geminiApiKey,
};
static Map<String, String> get geminiHeaders => {'Content-Type': 'application/json', 'x-goog-api-key': geminiApiKey};
}
Loading
Loading