Skip to content

Commit 62e1d02

Browse files
authored
Merge pull request #15 from connorakey/rust-rewrite
Added Extra Features and Bug fixes
2 parents 78feab8 + cd8a4e7 commit 62e1d02

File tree

9 files changed

+532
-183
lines changed

9 files changed

+532
-183
lines changed

backend/src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use axum::{routing::post, Json, Router, http::StatusCode};
1+
use axum::{routing::post, Json, Router, http::StatusCode, extract::DefaultBodyLimit};
22
use serde::{Deserialize, Serialize};
33
use std::net::SocketAddr;
44
use backend::openai::{get_step_by_step_guidance, get_final_answer};
@@ -49,7 +49,8 @@ async fn main() {
4949

5050
let app = Router::new()
5151
.route("/api/openai", post(openai))
52-
.route("/admin/add_api_key", post(add_api_key));
52+
.route("/admin/add_api_key", post(add_api_key))
53+
.layer(DefaultBodyLimit::max(100 * 1024 * 1024)); // 100MB limit
5354

5455
// Get port from environment variable, default to 3000 if not set
5556
let port = std::env::var("PORT").unwrap_or_else(|_| "3000".to_string());

frontend/maths-online-app/src-tauri/src/request.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ pub struct OpenAiRequest {
1616
pub request_type: OpenAiRequestType,
1717
}
1818

19+
#[derive(Debug, Clone, Serialize, Deserialize)]
20+
pub struct OpenAiRequestWithUrl {
21+
pub image_b64: String,
22+
pub api_key: String,
23+
pub request_type: OpenAiRequestType,
24+
pub base_url: String,
25+
}
26+
1927
#[derive(Debug, Clone, Serialize, Deserialize)]
2028
pub struct OpenAiResponse {
2129
pub success: bool,

frontend/maths-online-app/src/App.tsx

Lines changed: 88 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,41 @@ function App() {
3838
if (screenshotResult.success) {
3939
// Process the screenshot with AI
4040
console.log('Screenshot captured successfully, processing with AI...');
41-
// TODO: Send to AI for processing
42-
setSolutionData({
43-
solution: `Step-by-Step Solution (Screenshot Mode):\n\nScreenshot captured from coordinates (${coordinates.x1}, ${coordinates.y1}) to (${coordinates.x2}, ${coordinates.y2})\n\n1. First, identify the problem type...\n2. Apply the appropriate formula...\n3. Solve step by step...\n4. Check your answer.`
44-
});
41+
42+
// Get settings for API configuration
43+
const settings = await invoke<{
44+
base_url: string;
45+
api_key: string;
46+
}>('get_settings');
47+
48+
console.log('Settings loaded:', settings);
49+
50+
// Send to backend for processing
51+
const requestParams = {
52+
request: {
53+
image_b64: screenshotResult.base64_data,
54+
api_key: settings.api_key,
55+
request_type: 'StepByStep'
56+
},
57+
baseUrl: settings.base_url
58+
};
59+
60+
console.log('Sending request with params:', requestParams);
61+
62+
const apiResponse = await invoke<{
63+
success: boolean;
64+
response: string;
65+
}>('send_openai_request', requestParams);
66+
67+
if (apiResponse.success) {
68+
setSolutionData({
69+
solution: apiResponse.response
70+
});
71+
} else {
72+
setSolutionData({
73+
error: `API request failed: ${apiResponse.response}`
74+
});
75+
}
4576
} else {
4677
setSolutionData({
4778
error: `Screenshot failed: ${screenshotResult.error || 'Unknown error'}`
@@ -55,7 +86,7 @@ function App() {
5586
}
5687
};
5788

58-
const handleFormSubmit = (data: {
89+
const handleFormSubmit = async (data: {
5990
requestType: RequestType;
6091
imageData?: string;
6192
useScreenshot: boolean;
@@ -69,22 +100,58 @@ function App() {
69100
// Set loading state
70101
setSolutionData({ isLoading: true });
71102

72-
if (data.useScreenshot) {
73-
// Handle screenshot mode
74-
console.log('Taking screenshot...');
75-
handleScreenshotMode();
76-
} else if (data.imageData) {
77-
// Handle uploaded image
78-
console.log('Processing uploaded image...');
79-
// TODO: Implement image processing
80-
// invoke('process_uploaded_image', { base64Input: data.imageData })
81-
82-
// For now, simulate loading
83-
setTimeout(() => {
84-
setSolutionData({
85-
solution: `Step-by-Step Solution (Upload Mode):\n\n1. Analyzing uploaded image...\n2. Identifying mathematical expressions...\n3. Applying solution method...\n4. Final answer: [Solution will appear here]`
86-
});
87-
}, 3000);
103+
try {
104+
if (data.useScreenshot) {
105+
// Handle screenshot mode
106+
console.log('Taking screenshot...');
107+
await handleScreenshotMode();
108+
} else if (data.imageData) {
109+
// Handle uploaded image
110+
console.log('Processing uploaded image...');
111+
112+
// Get settings for API configuration
113+
const settings = await invoke<{
114+
base_url: string;
115+
api_key: string;
116+
}>('get_settings');
117+
118+
console.log('Settings loaded for upload:', settings);
119+
120+
// Determine request type based on form selection
121+
const requestType = data.requestType === RequestType.StepByStep ? 'StepByStep' : 'FinalAnswer';
122+
123+
// Send to backend for processing
124+
const requestParams = {
125+
request: {
126+
image_b64: data.imageData,
127+
api_key: settings.api_key,
128+
request_type: requestType
129+
},
130+
baseUrl: settings.base_url
131+
};
132+
133+
console.log('Sending upload request with params:', requestParams);
134+
135+
const apiResponse = await invoke<{
136+
success: boolean;
137+
response: string;
138+
}>('send_openai_request', requestParams);
139+
140+
if (apiResponse.success) {
141+
setSolutionData({
142+
solution: apiResponse.response
143+
});
144+
} else {
145+
setSolutionData({
146+
error: `API request failed: ${apiResponse.response}`
147+
});
148+
}
149+
}
150+
} catch (error) {
151+
console.error('API request error:', error);
152+
setSolutionData({
153+
error: `Failed to process request: ${error}`
154+
});
88155
}
89156
};
90157

frontend/maths-online-app/src/components/MathQuestionForm.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ const MathQuestionForm: React.FC<MathQuestionFormProps> = ({ onSubmit }) => {
8989
<UploadBox
9090
onImageUpload={handleImageUpload}
9191
onError={handleUploadError}
92+
isUploaded={!!uploadedImage}
9293
/>
9394
</div>
9495
)}

frontend/maths-online-app/src/components/Settings.css

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,79 @@
238238
text-align: center;
239239
}
240240

241+
/* Password Change Section */
242+
.secondary-button {
243+
padding: 10px 16px;
244+
background-color: #f3f4f6;
245+
color: #374151;
246+
border: 2px solid #e5e7eb;
247+
border-radius: 8px;
248+
font-size: 0.875rem;
249+
font-weight: 500;
250+
cursor: pointer;
251+
transition: all 0.2s;
252+
}
253+
254+
.secondary-button:hover {
255+
background-color: #e5e7eb;
256+
border-color: #d1d5db;
257+
}
258+
259+
.password-change-section {
260+
margin-top: 20px;
261+
padding: 20px;
262+
background-color: #f8fafc;
263+
border: 1px solid #e5e7eb;
264+
border-radius: 8px;
265+
animation: slideDown 0.3s ease-out;
266+
}
267+
268+
@keyframes slideDown {
269+
from {
270+
opacity: 0;
271+
transform: translateY(-10px);
272+
}
273+
to {
274+
opacity: 1;
275+
transform: translateY(0);
276+
}
277+
}
278+
279+
.password-change-section .setting-field {
280+
margin-bottom: 16px;
281+
}
282+
283+
.password-change-actions {
284+
margin-top: 20px;
285+
text-align: right;
286+
}
287+
288+
.primary-button {
289+
padding: 12px 24px;
290+
background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
291+
color: white;
292+
border: none;
293+
border-radius: 8px;
294+
font-size: 0.875rem;
295+
font-weight: 600;
296+
cursor: pointer;
297+
transition: all 0.2s;
298+
}
299+
300+
.primary-button:hover:not(:disabled) {
301+
background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
302+
transform: translateY(-1px);
303+
box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
304+
}
305+
306+
.primary-button:disabled {
307+
background: #d1d5db;
308+
color: #9ca3af;
309+
cursor: not-allowed;
310+
transform: none;
311+
box-shadow: none;
312+
}
313+
241314
.settings-footer {
242315
padding: 16px 24px;
243316
border-top: 1px solid #e5e7eb;

0 commit comments

Comments
 (0)