Spaces:
Sleeping
Sleeping
Hkoradiya123 commited on
Commit ·
38ee1b6
1
Parent(s): aea2f4a
Serve frontend and backend from one Space
Browse files- Backend/app.py +28 -5
- Frontend/src/components/auth/SignupForm.jsx +2 -2
- Frontend/src/components/layout/DashboardLayout.jsx +4 -5
- Frontend/src/components/ui/ExamPinModal.jsx +2 -3
- Frontend/src/pages/Dashboard/DashboardOverview.jsx +3 -4
- Frontend/src/pages/Generate/Preview.jsx +5 -8
- Frontend/src/pages/Generate/components/FinalDetailsStep.jsx +2 -3
- Frontend/src/pages/Generate/components/SelectMaterialStep.jsx +3 -4
- Frontend/src/pages/History/History.jsx +5 -9
- Frontend/src/pages/Settings/Settings.jsx +4 -7
- Frontend/src/pages/Upload/Upload.jsx +4 -7
- Frontend/src/utils/api.js +1 -0
Backend/app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import os
|
| 2 |
import logging
|
| 3 |
-
from flask import Flask, jsonify, request
|
| 4 |
from flask_cors import CORS
|
| 5 |
from dotenv import load_dotenv
|
| 6 |
|
|
@@ -12,7 +12,9 @@ from routes.dashboard import dashboard_bp
|
|
| 12 |
# Load environment variables
|
| 13 |
load_dotenv(dotenv_path='.env.local')
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
# Configure CORS - Enable proper preflight headers
|
| 17 |
CORS(app, resources={r"/*": {"origins": "*"}}, supports_credentials=True)
|
| 18 |
|
|
@@ -47,16 +49,37 @@ def handle_exception(e):
|
|
| 47 |
return jsonify(error=str(e)), code
|
| 48 |
|
| 49 |
# -----------------------------------------------------------------------------
|
| 50 |
-
# Home Route
|
| 51 |
# -----------------------------------------------------------------------------
|
| 52 |
-
@app.route('/')
|
| 53 |
-
def
|
| 54 |
return jsonify({
|
| 55 |
"status": "online",
|
| 56 |
"message": "ExamCraft Backend API is running",
|
| 57 |
"version": "1.1.0"
|
| 58 |
})
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
if __name__ == '__main__':
|
| 61 |
# Ensure uploads directory exists
|
| 62 |
os.makedirs('uploads', exist_ok=True)
|
|
|
|
| 1 |
import os
|
| 2 |
import logging
|
| 3 |
+
from flask import Flask, jsonify, request, send_from_directory
|
| 4 |
from flask_cors import CORS
|
| 5 |
from dotenv import load_dotenv
|
| 6 |
|
|
|
|
| 12 |
# Load environment variables
|
| 13 |
load_dotenv(dotenv_path='.env.local')
|
| 14 |
|
| 15 |
+
FRONTEND_DIST_DIR = os.path.join(os.path.dirname(__file__), "frontend_dist")
|
| 16 |
+
|
| 17 |
+
app = Flask(__name__, static_folder=None)
|
| 18 |
# Configure CORS - Enable proper preflight headers
|
| 19 |
CORS(app, resources={r"/*": {"origins": "*"}}, supports_credentials=True)
|
| 20 |
|
|
|
|
| 49 |
return jsonify(error=str(e)), code
|
| 50 |
|
| 51 |
# -----------------------------------------------------------------------------
|
| 52 |
+
# Home Route / SPA serving
|
| 53 |
# -----------------------------------------------------------------------------
|
| 54 |
+
@app.route('/api/health')
|
| 55 |
+
def health():
|
| 56 |
return jsonify({
|
| 57 |
"status": "online",
|
| 58 |
"message": "ExamCraft Backend API is running",
|
| 59 |
"version": "1.1.0"
|
| 60 |
})
|
| 61 |
|
| 62 |
+
|
| 63 |
+
@app.route('/', defaults={'path': ''})
|
| 64 |
+
@app.route('/<path:path>')
|
| 65 |
+
def serve_frontend(path):
|
| 66 |
+
if path.startswith(('api/', 'upload', 'generate', 'download', 'regenerate-question')):
|
| 67 |
+
return jsonify({"error": "Not found"}), 404
|
| 68 |
+
|
| 69 |
+
requested_path = os.path.join(FRONTEND_DIST_DIR, path)
|
| 70 |
+
if path and os.path.isfile(requested_path):
|
| 71 |
+
return send_from_directory(FRONTEND_DIST_DIR, path)
|
| 72 |
+
|
| 73 |
+
index_path = os.path.join(FRONTEND_DIST_DIR, 'index.html')
|
| 74 |
+
if os.path.exists(index_path):
|
| 75 |
+
return send_from_directory(FRONTEND_DIST_DIR, 'index.html')
|
| 76 |
+
|
| 77 |
+
return jsonify({
|
| 78 |
+
"status": "online",
|
| 79 |
+
"message": "Frontend build is not available",
|
| 80 |
+
"version": "1.1.0"
|
| 81 |
+
}), 503
|
| 82 |
+
|
| 83 |
if __name__ == '__main__':
|
| 84 |
# Ensure uploads directory exists
|
| 85 |
os.makedirs('uploads', exist_ok=True)
|
Frontend/src/components/auth/SignupForm.jsx
CHANGED
|
@@ -7,6 +7,7 @@ import { useToast } from '../ui/Toast';
|
|
| 7 |
import { useAuthToggle } from './AuthToggleContext';
|
| 8 |
import { cn } from '../../../src/utils/cn';
|
| 9 |
import { supabase } from '../../../src/utils/supabaseClient';
|
|
|
|
| 10 |
import bcrypt from 'bcryptjs';
|
| 11 |
|
| 12 |
const roles = [
|
|
@@ -91,9 +92,8 @@ export const SignupForm = () => {
|
|
| 91 |
const hashedPassword = bcrypt.hashSync(formData.password, salt);
|
| 92 |
|
| 93 |
// Update the user's profile with the encrypted password immediately via backend API
|
| 94 |
-
const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:5000';
|
| 95 |
try {
|
| 96 |
-
const response = await fetch(`${
|
| 97 |
method: 'PUT',
|
| 98 |
headers: {
|
| 99 |
'Content-Type': 'application/json',
|
|
|
|
| 7 |
import { useAuthToggle } from './AuthToggleContext';
|
| 8 |
import { cn } from '../../../src/utils/cn';
|
| 9 |
import { supabase } from '../../../src/utils/supabaseClient';
|
| 10 |
+
import { API_BASE_URL } from '../../../src/utils/api';
|
| 11 |
import bcrypt from 'bcryptjs';
|
| 12 |
|
| 13 |
const roles = [
|
|
|
|
| 92 |
const hashedPassword = bcrypt.hashSync(formData.password, salt);
|
| 93 |
|
| 94 |
// Update the user's profile with the encrypted password immediately via backend API
|
|
|
|
| 95 |
try {
|
| 96 |
+
const response = await fetch(`${API_BASE_URL}/api/profile`, {
|
| 97 |
method: 'PUT',
|
| 98 |
headers: {
|
| 99 |
'Content-Type': 'application/json',
|
Frontend/src/components/layout/DashboardLayout.jsx
CHANGED
|
@@ -4,6 +4,7 @@ import { useTheme } from "../../context/ThemeContext";
|
|
| 4 |
import { cn } from "../../utils/cn";
|
| 5 |
import { motion, AnimatePresence } from "framer-motion";
|
| 6 |
import { supabase } from "../../utils/supabaseClient";
|
|
|
|
| 7 |
import {
|
| 8 |
LayoutDashboard,
|
| 9 |
UploadCloud,
|
|
@@ -47,9 +48,8 @@ export default function DashboardLayout() {
|
|
| 47 |
const fetchUser = async () => {
|
| 48 |
const { data: { session } } = await supabase.auth.getSession();
|
| 49 |
if (session?.user) {
|
| 50 |
-
const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:5000';
|
| 51 |
try {
|
| 52 |
-
const response = await fetch(`${
|
| 53 |
method: 'GET',
|
| 54 |
headers: {
|
| 55 |
'Content-Type': 'application/json',
|
|
@@ -73,7 +73,7 @@ export default function DashboardLayout() {
|
|
| 73 |
// Prevent sending emails repeatedly per session
|
| 74 |
if (!sessionStorage.getItem('passwordReminderSent')) {
|
| 75 |
sessionStorage.setItem('passwordReminderSent', 'true');
|
| 76 |
-
fetch(`${
|
| 77 |
method: 'POST',
|
| 78 |
headers: { 'Authorization': `Bearer ${session.access_token}` }
|
| 79 |
}).catch(err => console.error("Email API Err:", err));
|
|
@@ -123,8 +123,7 @@ export default function DashboardLayout() {
|
|
| 123 |
setIsSavingPassword(true);
|
| 124 |
try {
|
| 125 |
const { data: { session } } = await supabase.auth.getSession();
|
| 126 |
-
const
|
| 127 |
-
const response = await fetch(`${API_URL}/api/profile`, {
|
| 128 |
method: 'PUT',
|
| 129 |
headers: {
|
| 130 |
'Content-Type': 'application/json',
|
|
|
|
| 4 |
import { cn } from "../../utils/cn";
|
| 5 |
import { motion, AnimatePresence } from "framer-motion";
|
| 6 |
import { supabase } from "../../utils/supabaseClient";
|
| 7 |
+
import { API_BASE_URL } from "../../utils/api";
|
| 8 |
import {
|
| 9 |
LayoutDashboard,
|
| 10 |
UploadCloud,
|
|
|
|
| 48 |
const fetchUser = async () => {
|
| 49 |
const { data: { session } } = await supabase.auth.getSession();
|
| 50 |
if (session?.user) {
|
|
|
|
| 51 |
try {
|
| 52 |
+
const response = await fetch(`${API_BASE_URL}/api/profile`, {
|
| 53 |
method: 'GET',
|
| 54 |
headers: {
|
| 55 |
'Content-Type': 'application/json',
|
|
|
|
| 73 |
// Prevent sending emails repeatedly per session
|
| 74 |
if (!sessionStorage.getItem('passwordReminderSent')) {
|
| 75 |
sessionStorage.setItem('passwordReminderSent', 'true');
|
| 76 |
+
fetch(`${API_BASE_URL}/api/send-password-reminder`, {
|
| 77 |
method: 'POST',
|
| 78 |
headers: { 'Authorization': `Bearer ${session.access_token}` }
|
| 79 |
}).catch(err => console.error("Email API Err:", err));
|
|
|
|
| 123 |
setIsSavingPassword(true);
|
| 124 |
try {
|
| 125 |
const { data: { session } } = await supabase.auth.getSession();
|
| 126 |
+
const response = await fetch(`${API_BASE_URL}/api/profile`, {
|
|
|
|
| 127 |
method: 'PUT',
|
| 128 |
headers: {
|
| 129 |
'Content-Type': 'application/json',
|
Frontend/src/components/ui/ExamPinModal.jsx
CHANGED
|
@@ -3,6 +3,7 @@ import { motion, AnimatePresence } from 'framer-motion';
|
|
| 3 |
import { Lock, ShieldCheck, X, Loader2, AlertCircle } from 'lucide-react';
|
| 4 |
import { Button } from './Button';
|
| 5 |
import { supabase } from '../../utils/supabaseClient';
|
|
|
|
| 6 |
|
| 7 |
export function ExamPinModal({ isOpen, onClose, onVerified, title = "Secure Access" }) {
|
| 8 |
const [pin, setPin] = useState("");
|
|
@@ -21,9 +22,7 @@ export function ExamPinModal({ isOpen, onClose, onVerified, title = "Secure Acce
|
|
| 21 |
setIsVerifying(true);
|
| 22 |
try {
|
| 23 |
const { data: { session } } = await supabase.auth.getSession();
|
| 24 |
-
const
|
| 25 |
-
|
| 26 |
-
const response = await fetch(`${API_URL}/api/verify-exam-password`, {
|
| 27 |
method: 'POST',
|
| 28 |
headers: {
|
| 29 |
'Content-Type': 'application/json',
|
|
|
|
| 3 |
import { Lock, ShieldCheck, X, Loader2, AlertCircle } from 'lucide-react';
|
| 4 |
import { Button } from './Button';
|
| 5 |
import { supabase } from '../../utils/supabaseClient';
|
| 6 |
+
import { API_BASE_URL } from '../../utils/api';
|
| 7 |
|
| 8 |
export function ExamPinModal({ isOpen, onClose, onVerified, title = "Secure Access" }) {
|
| 9 |
const [pin, setPin] = useState("");
|
|
|
|
| 22 |
setIsVerifying(true);
|
| 23 |
try {
|
| 24 |
const { data: { session } } = await supabase.auth.getSession();
|
| 25 |
+
const response = await fetch(`${API_BASE_URL}/api/verify-exam-password`, {
|
|
|
|
|
|
|
| 26 |
method: 'POST',
|
| 27 |
headers: {
|
| 28 |
'Content-Type': 'application/json',
|
Frontend/src/pages/Dashboard/DashboardOverview.jsx
CHANGED
|
@@ -5,6 +5,7 @@ import { useNavigate } from "react-router-dom";
|
|
| 5 |
import { Card, CardContent, CardHeader, CardTitle } from "../../components/ui/Card";
|
| 6 |
import { Skeleton, CardSkeleton } from "../../components/ui/Skeleton";
|
| 7 |
import { supabase } from "../../utils/supabaseClient";
|
|
|
|
| 8 |
import {
|
| 9 |
BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer,
|
| 10 |
PieChart, Pie, Cell,
|
|
@@ -46,15 +47,13 @@ export default function DashboardOverview() {
|
|
| 46 |
const { data: { session } } = await supabase.auth.getSession();
|
| 47 |
if (!session) return;
|
| 48 |
|
| 49 |
-
const
|
| 50 |
-
|
| 51 |
-
const papersRes = await fetch(`${API_URL}/api/exam_papers`, {
|
| 52 |
method: 'GET',
|
| 53 |
headers: { 'Authorization': `Bearer ${session.access_token}` }
|
| 54 |
});
|
| 55 |
const papers = papersRes.ok ? await papersRes.json() : [];
|
| 56 |
|
| 57 |
-
const matsRes = await fetch(`${
|
| 58 |
method: 'GET',
|
| 59 |
headers: { 'Authorization': `Bearer ${session.access_token}` }
|
| 60 |
});
|
|
|
|
| 5 |
import { Card, CardContent, CardHeader, CardTitle } from "../../components/ui/Card";
|
| 6 |
import { Skeleton, CardSkeleton } from "../../components/ui/Skeleton";
|
| 7 |
import { supabase } from "../../utils/supabaseClient";
|
| 8 |
+
import { API_BASE_URL } from "../../utils/api";
|
| 9 |
import {
|
| 10 |
BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer,
|
| 11 |
PieChart, Pie, Cell,
|
|
|
|
| 47 |
const { data: { session } } = await supabase.auth.getSession();
|
| 48 |
if (!session) return;
|
| 49 |
|
| 50 |
+
const papersRes = await fetch(`${API_BASE_URL}/api/exam_papers`, {
|
|
|
|
|
|
|
| 51 |
method: 'GET',
|
| 52 |
headers: { 'Authorization': `Bearer ${session.access_token}` }
|
| 53 |
});
|
| 54 |
const papers = papersRes.ok ? await papersRes.json() : [];
|
| 55 |
|
| 56 |
+
const matsRes = await fetch(`${API_BASE_URL}/api/materials`, {
|
| 57 |
method: 'GET',
|
| 58 |
headers: { 'Authorization': `Bearer ${session.access_token}` }
|
| 59 |
});
|
Frontend/src/pages/Generate/Preview.jsx
CHANGED
|
@@ -6,6 +6,7 @@ import { Button } from "../../components/ui/Button";
|
|
| 6 |
import { cn } from "../../utils/cn";
|
| 7 |
import { ExamPinModal } from "../../components/ui/ExamPinModal";
|
| 8 |
import { supabase } from "../../utils/supabaseClient";
|
|
|
|
| 9 |
|
| 10 |
export default function Preview() {
|
| 11 |
const location = useLocation();
|
|
@@ -27,9 +28,7 @@ export default function Preview() {
|
|
| 27 |
const checkUserPin = async () => {
|
| 28 |
try {
|
| 29 |
const { data: { session } } = await supabase.auth.getSession();
|
| 30 |
-
const
|
| 31 |
-
|
| 32 |
-
const response = await fetch(`${API_URL}/api/profile`, {
|
| 33 |
method: 'GET',
|
| 34 |
headers: { 'Authorization': `Bearer ${session?.access_token}` }
|
| 35 |
});
|
|
@@ -68,8 +67,7 @@ export default function Preview() {
|
|
| 68 |
setIsDownloading(true);
|
| 69 |
try {
|
| 70 |
const { data: { session } } = await supabase.auth.getSession();
|
| 71 |
-
const
|
| 72 |
-
const res = await fetch(`${API_URL}/download`, {
|
| 73 |
method: 'POST',
|
| 74 |
headers: {
|
| 75 |
'Content-Type': 'application/json',
|
|
@@ -108,10 +106,9 @@ export default function Preview() {
|
|
| 108 |
const key = `${sectionIndex}-${questionIndex}`;
|
| 109 |
setLoadingQuestion(key);
|
| 110 |
try {
|
| 111 |
-
const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:5000';
|
| 112 |
const { data: { session } } = await supabase.auth.getSession();
|
| 113 |
|
| 114 |
-
const res = await fetch(`${
|
| 115 |
method: 'POST',
|
| 116 |
headers: {
|
| 117 |
'Content-Type': 'application/json',
|
|
@@ -137,7 +134,7 @@ export default function Preview() {
|
|
| 137 |
|
| 138 |
// Persist the change to the database
|
| 139 |
if (paperResult.paper_id) {
|
| 140 |
-
await fetch(`${
|
| 141 |
method: 'PUT',
|
| 142 |
headers: {
|
| 143 |
'Content-Type': 'application/json',
|
|
|
|
| 6 |
import { cn } from "../../utils/cn";
|
| 7 |
import { ExamPinModal } from "../../components/ui/ExamPinModal";
|
| 8 |
import { supabase } from "../../utils/supabaseClient";
|
| 9 |
+
import { API_BASE_URL } from "../../utils/api";
|
| 10 |
|
| 11 |
export default function Preview() {
|
| 12 |
const location = useLocation();
|
|
|
|
| 28 |
const checkUserPin = async () => {
|
| 29 |
try {
|
| 30 |
const { data: { session } } = await supabase.auth.getSession();
|
| 31 |
+
const response = await fetch(`${API_BASE_URL}/api/profile`, {
|
|
|
|
|
|
|
| 32 |
method: 'GET',
|
| 33 |
headers: { 'Authorization': `Bearer ${session?.access_token}` }
|
| 34 |
});
|
|
|
|
| 67 |
setIsDownloading(true);
|
| 68 |
try {
|
| 69 |
const { data: { session } } = await supabase.auth.getSession();
|
| 70 |
+
const res = await fetch(`${API_BASE_URL}/download`, {
|
|
|
|
| 71 |
method: 'POST',
|
| 72 |
headers: {
|
| 73 |
'Content-Type': 'application/json',
|
|
|
|
| 106 |
const key = `${sectionIndex}-${questionIndex}`;
|
| 107 |
setLoadingQuestion(key);
|
| 108 |
try {
|
|
|
|
| 109 |
const { data: { session } } = await supabase.auth.getSession();
|
| 110 |
|
| 111 |
+
const res = await fetch(`${API_BASE_URL}/regenerate-question`, {
|
| 112 |
method: 'POST',
|
| 113 |
headers: {
|
| 114 |
'Content-Type': 'application/json',
|
|
|
|
| 134 |
|
| 135 |
// Persist the change to the database
|
| 136 |
if (paperResult.paper_id) {
|
| 137 |
+
await fetch(`${API_BASE_URL}/api/exam_papers/${paperResult.paper_id}`, {
|
| 138 |
method: 'PUT',
|
| 139 |
headers: {
|
| 140 |
'Content-Type': 'application/json',
|
Frontend/src/pages/Generate/components/FinalDetailsStep.jsx
CHANGED
|
@@ -7,6 +7,7 @@ import { Input } from '../../../components/ui/Input';
|
|
| 7 |
import { useNavigate } from 'react-router-dom';
|
| 8 |
import { cn } from '../../../../src/utils/cn';
|
| 9 |
import { supabase } from '../../../../src/utils/supabaseClient';
|
|
|
|
| 10 |
|
| 11 |
export const FinalDetailsStep = () => {
|
| 12 |
const { finalDetails, setFinalDetails, configure, materials, setStep } = useGenerate();
|
|
@@ -75,14 +76,12 @@ export const FinalDetailsStep = () => {
|
|
| 75 |
const { data: { session } } = await supabase.auth.getSession();
|
| 76 |
const token = session?.access_token;
|
| 77 |
|
| 78 |
-
const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:5000';
|
| 79 |
-
|
| 80 |
const headers = { 'Content-Type': 'application/json' };
|
| 81 |
if (token) {
|
| 82 |
headers['Authorization'] = `Bearer ${token}`;
|
| 83 |
}
|
| 84 |
|
| 85 |
-
const res = await fetch(`${
|
| 86 |
method: 'POST',
|
| 87 |
headers: headers,
|
| 88 |
body: JSON.stringify({
|
|
|
|
| 7 |
import { useNavigate } from 'react-router-dom';
|
| 8 |
import { cn } from '../../../../src/utils/cn';
|
| 9 |
import { supabase } from '../../../../src/utils/supabaseClient';
|
| 10 |
+
import { API_BASE_URL } from '../../../../src/utils/api';
|
| 11 |
|
| 12 |
export const FinalDetailsStep = () => {
|
| 13 |
const { finalDetails, setFinalDetails, configure, materials, setStep } = useGenerate();
|
|
|
|
| 76 |
const { data: { session } } = await supabase.auth.getSession();
|
| 77 |
const token = session?.access_token;
|
| 78 |
|
|
|
|
|
|
|
| 79 |
const headers = { 'Content-Type': 'application/json' };
|
| 80 |
if (token) {
|
| 81 |
headers['Authorization'] = `Bearer ${token}`;
|
| 82 |
}
|
| 83 |
|
| 84 |
+
const res = await fetch(`${API_BASE_URL}/generate`, {
|
| 85 |
method: 'POST',
|
| 86 |
headers: headers,
|
| 87 |
body: JSON.stringify({
|
Frontend/src/pages/Generate/components/SelectMaterialStep.jsx
CHANGED
|
@@ -6,6 +6,7 @@ import { FileText, Tag, Presentation, Code, FileSpreadsheet, Search, Filter, Che
|
|
| 6 |
import { cn } from '../../../../src/utils/cn';
|
| 7 |
import { Button } from '../../../components/ui/Button';
|
| 8 |
import { supabase } from '../../../utils/supabaseClient';
|
|
|
|
| 9 |
|
| 10 |
export const SelectMaterialStep = () => {
|
| 11 |
const { materials, setMaterials, setStep } = useGenerate();
|
|
@@ -20,8 +21,7 @@ export const SelectMaterialStep = () => {
|
|
| 20 |
try {
|
| 21 |
const { data: { session } } = await supabase.auth.getSession();
|
| 22 |
if (!session) return;
|
| 23 |
-
const
|
| 24 |
-
const res = await fetch(`${API_URL}/api/materials`, {
|
| 25 |
method: "GET",
|
| 26 |
headers: { 'Authorization': `Bearer ${session.access_token}` }
|
| 27 |
});
|
|
@@ -77,8 +77,7 @@ export const SelectMaterialStep = () => {
|
|
| 77 |
|
| 78 |
try {
|
| 79 |
const { data: { session } } = await supabase.auth.getSession();
|
| 80 |
-
const
|
| 81 |
-
const res = await fetch(`${API_URL}/upload`, {
|
| 82 |
method: 'POST',
|
| 83 |
headers: { 'Authorization': `Bearer ${session?.access_token || ''}` },
|
| 84 |
body: formData
|
|
|
|
| 6 |
import { cn } from '../../../../src/utils/cn';
|
| 7 |
import { Button } from '../../../components/ui/Button';
|
| 8 |
import { supabase } from '../../../utils/supabaseClient';
|
| 9 |
+
import { API_BASE_URL } from '../../../utils/api';
|
| 10 |
|
| 11 |
export const SelectMaterialStep = () => {
|
| 12 |
const { materials, setMaterials, setStep } = useGenerate();
|
|
|
|
| 21 |
try {
|
| 22 |
const { data: { session } } = await supabase.auth.getSession();
|
| 23 |
if (!session) return;
|
| 24 |
+
const res = await fetch(`${API_BASE_URL}/api/materials`, {
|
|
|
|
| 25 |
method: "GET",
|
| 26 |
headers: { 'Authorization': `Bearer ${session.access_token}` }
|
| 27 |
});
|
|
|
|
| 77 |
|
| 78 |
try {
|
| 79 |
const { data: { session } } = await supabase.auth.getSession();
|
| 80 |
+
const res = await fetch(`${API_BASE_URL}/upload`, {
|
|
|
|
| 81 |
method: 'POST',
|
| 82 |
headers: { 'Authorization': `Bearer ${session?.access_token || ''}` },
|
| 83 |
body: formData
|
Frontend/src/pages/History/History.jsx
CHANGED
|
@@ -6,6 +6,7 @@ import { Button } from "../../components/ui/Button";
|
|
| 6 |
import { TableRowSkeleton } from "../../components/ui/Skeleton";
|
| 7 |
import { supabase } from "../../utils/supabaseClient";
|
| 8 |
import { ExamPinModal } from "../../components/ui/ExamPinModal";
|
|
|
|
| 9 |
import { Lock } from "lucide-react";
|
| 10 |
|
| 11 |
export default function History() {
|
|
@@ -32,14 +33,12 @@ export default function History() {
|
|
| 32 |
const { data: { session } } = await supabase.auth.getSession();
|
| 33 |
if (!session) return;
|
| 34 |
|
| 35 |
-
const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:5000';
|
| 36 |
-
|
| 37 |
// Fetch history and profile in parallel or sequence
|
| 38 |
const [historyRes, profileRes] = await Promise.all([
|
| 39 |
-
fetch(`${
|
| 40 |
headers: { 'Authorization': `Bearer ${session.access_token}` }
|
| 41 |
}),
|
| 42 |
-
fetch(`${
|
| 43 |
headers: { 'Authorization': `Bearer ${session.access_token}` }
|
| 44 |
})
|
| 45 |
]);
|
|
@@ -84,8 +83,7 @@ export default function History() {
|
|
| 84 |
|
| 85 |
try {
|
| 86 |
const { data: { session } } = await supabase.auth.getSession();
|
| 87 |
-
const
|
| 88 |
-
const res = await fetch(`${API_URL}/download`, {
|
| 89 |
method: 'POST',
|
| 90 |
headers: {
|
| 91 |
'Content-Type': 'application/json',
|
|
@@ -133,9 +131,7 @@ export default function History() {
|
|
| 133 |
|
| 134 |
try {
|
| 135 |
const { data: { session } } = await supabase.auth.getSession();
|
| 136 |
-
const
|
| 137 |
-
|
| 138 |
-
const res = await fetch(`${API_URL}/api/exam_papers/${id}`, {
|
| 139 |
method: 'DELETE',
|
| 140 |
headers: {
|
| 141 |
'Authorization': `Bearer ${session?.access_token}`
|
|
|
|
| 6 |
import { TableRowSkeleton } from "../../components/ui/Skeleton";
|
| 7 |
import { supabase } from "../../utils/supabaseClient";
|
| 8 |
import { ExamPinModal } from "../../components/ui/ExamPinModal";
|
| 9 |
+
import { API_BASE_URL } from "../../utils/api";
|
| 10 |
import { Lock } from "lucide-react";
|
| 11 |
|
| 12 |
export default function History() {
|
|
|
|
| 33 |
const { data: { session } } = await supabase.auth.getSession();
|
| 34 |
if (!session) return;
|
| 35 |
|
|
|
|
|
|
|
| 36 |
// Fetch history and profile in parallel or sequence
|
| 37 |
const [historyRes, profileRes] = await Promise.all([
|
| 38 |
+
fetch(`${API_BASE_URL}/api/exam_papers`, {
|
| 39 |
headers: { 'Authorization': `Bearer ${session.access_token}` }
|
| 40 |
}),
|
| 41 |
+
fetch(`${API_BASE_URL}/api/profile`, {
|
| 42 |
headers: { 'Authorization': `Bearer ${session.access_token}` }
|
| 43 |
})
|
| 44 |
]);
|
|
|
|
| 83 |
|
| 84 |
try {
|
| 85 |
const { data: { session } } = await supabase.auth.getSession();
|
| 86 |
+
const res = await fetch(`${API_BASE_URL}/download`, {
|
|
|
|
| 87 |
method: 'POST',
|
| 88 |
headers: {
|
| 89 |
'Content-Type': 'application/json',
|
|
|
|
| 131 |
|
| 132 |
try {
|
| 133 |
const { data: { session } } = await supabase.auth.getSession();
|
| 134 |
+
const res = await fetch(`${API_BASE_URL}/api/exam_papers/${id}`, {
|
|
|
|
|
|
|
| 135 |
method: 'DELETE',
|
| 136 |
headers: {
|
| 137 |
'Authorization': `Bearer ${session?.access_token}`
|
Frontend/src/pages/Settings/Settings.jsx
CHANGED
|
@@ -6,6 +6,7 @@ import { Button } from "../../components/ui/Button";
|
|
| 6 |
import { Input } from "../../components/ui/Input";
|
| 7 |
import { Card, CardHeader, CardTitle, CardContent, CardDescription, CardFooter } from "../../components/ui/Card";
|
| 8 |
import { supabase } from "../../utils/supabaseClient";
|
|
|
|
| 9 |
import { useToast } from "../../components/ui/Toast";
|
| 10 |
|
| 11 |
export default function Settings() {
|
|
@@ -33,9 +34,7 @@ export default function Settings() {
|
|
| 33 |
return;
|
| 34 |
}
|
| 35 |
|
| 36 |
-
const
|
| 37 |
-
|
| 38 |
-
const response = await fetch(`${API_URL}/api/profile`, {
|
| 39 |
method: 'GET',
|
| 40 |
headers: {
|
| 41 |
'Content-Type': 'application/json',
|
|
@@ -102,8 +101,7 @@ export default function Settings() {
|
|
| 102 |
avatar_url: profile.avatar_url
|
| 103 |
};
|
| 104 |
|
| 105 |
-
const
|
| 106 |
-
const response = await fetch(`${API_URL}/api/profile`, {
|
| 107 |
method: 'PUT',
|
| 108 |
headers: {
|
| 109 |
'Content-Type': 'application/json',
|
|
@@ -150,8 +148,7 @@ export default function Settings() {
|
|
| 150 |
setIsSavingExamPassword(true);
|
| 151 |
try {
|
| 152 |
const { data: { session } } = await supabase.auth.getSession();
|
| 153 |
-
const
|
| 154 |
-
const response = await fetch(`${API_URL}/api/profile`, {
|
| 155 |
method: 'PUT',
|
| 156 |
headers: {
|
| 157 |
'Content-Type': 'application/json',
|
|
|
|
| 6 |
import { Input } from "../../components/ui/Input";
|
| 7 |
import { Card, CardHeader, CardTitle, CardContent, CardDescription, CardFooter } from "../../components/ui/Card";
|
| 8 |
import { supabase } from "../../utils/supabaseClient";
|
| 9 |
+
import { API_BASE_URL } from "../../utils/api";
|
| 10 |
import { useToast } from "../../components/ui/Toast";
|
| 11 |
|
| 12 |
export default function Settings() {
|
|
|
|
| 34 |
return;
|
| 35 |
}
|
| 36 |
|
| 37 |
+
const response = await fetch(`${API_BASE_URL}/api/profile`, {
|
|
|
|
|
|
|
| 38 |
method: 'GET',
|
| 39 |
headers: {
|
| 40 |
'Content-Type': 'application/json',
|
|
|
|
| 101 |
avatar_url: profile.avatar_url
|
| 102 |
};
|
| 103 |
|
| 104 |
+
const response = await fetch(`${API_BASE_URL}/api/profile`, {
|
|
|
|
| 105 |
method: 'PUT',
|
| 106 |
headers: {
|
| 107 |
'Content-Type': 'application/json',
|
|
|
|
| 148 |
setIsSavingExamPassword(true);
|
| 149 |
try {
|
| 150 |
const { data: { session } } = await supabase.auth.getSession();
|
| 151 |
+
const response = await fetch(`${API_BASE_URL}/api/profile`, {
|
|
|
|
| 152 |
method: 'PUT',
|
| 153 |
headers: {
|
| 154 |
'Content-Type': 'application/json',
|
Frontend/src/pages/Upload/Upload.jsx
CHANGED
|
@@ -4,6 +4,7 @@ import { motion, AnimatePresence } from "framer-motion";
|
|
| 4 |
import { UploadCloud, File, X, CheckCircle2, FileText, Database, AlertCircle } from "lucide-react";
|
| 5 |
import { Button } from "../../components/ui/Button";
|
| 6 |
import { supabase } from "../../utils/supabaseClient";
|
|
|
|
| 7 |
|
| 8 |
export default function Upload() {
|
| 9 |
const [file, setFile] = useState(null);
|
|
@@ -20,8 +21,7 @@ export default function Upload() {
|
|
| 20 |
try {
|
| 21 |
const { data: { session } } = await supabase.auth.getSession();
|
| 22 |
if (!session) return;
|
| 23 |
-
const
|
| 24 |
-
const res = await fetch(`${API_URL}/api/materials`, {
|
| 25 |
method: "GET",
|
| 26 |
headers: { 'Authorization': `Bearer ${session.access_token}` }
|
| 27 |
});
|
|
@@ -83,9 +83,8 @@ export default function Upload() {
|
|
| 83 |
const formData = new FormData();
|
| 84 |
formData.append("file", file);
|
| 85 |
|
| 86 |
-
const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:5000';
|
| 87 |
const { data: { session } } = await supabase.auth.getSession();
|
| 88 |
-
const response = await fetch(`${
|
| 89 |
method: "POST",
|
| 90 |
headers: { 'Authorization': `Bearer ${session?.access_token || ''}` },
|
| 91 |
body: formData
|
|
@@ -118,9 +117,7 @@ export default function Upload() {
|
|
| 118 |
|
| 119 |
try {
|
| 120 |
const { data: { session } } = await supabase.auth.getSession();
|
| 121 |
-
const
|
| 122 |
-
|
| 123 |
-
const res = await fetch(`${API_URL}/api/materials/${id}`, {
|
| 124 |
method: 'DELETE',
|
| 125 |
headers: {
|
| 126 |
'Authorization': `Bearer ${session?.access_token}`
|
|
|
|
| 4 |
import { UploadCloud, File, X, CheckCircle2, FileText, Database, AlertCircle } from "lucide-react";
|
| 5 |
import { Button } from "../../components/ui/Button";
|
| 6 |
import { supabase } from "../../utils/supabaseClient";
|
| 7 |
+
import { API_BASE_URL } from "../../utils/api";
|
| 8 |
|
| 9 |
export default function Upload() {
|
| 10 |
const [file, setFile] = useState(null);
|
|
|
|
| 21 |
try {
|
| 22 |
const { data: { session } } = await supabase.auth.getSession();
|
| 23 |
if (!session) return;
|
| 24 |
+
const res = await fetch(`${API_BASE_URL}/api/materials`, {
|
|
|
|
| 25 |
method: "GET",
|
| 26 |
headers: { 'Authorization': `Bearer ${session.access_token}` }
|
| 27 |
});
|
|
|
|
| 83 |
const formData = new FormData();
|
| 84 |
formData.append("file", file);
|
| 85 |
|
|
|
|
| 86 |
const { data: { session } } = await supabase.auth.getSession();
|
| 87 |
+
const response = await fetch(`${API_BASE_URL}/upload`, {
|
| 88 |
method: "POST",
|
| 89 |
headers: { 'Authorization': `Bearer ${session?.access_token || ''}` },
|
| 90 |
body: formData
|
|
|
|
| 117 |
|
| 118 |
try {
|
| 119 |
const { data: { session } } = await supabase.auth.getSession();
|
| 120 |
+
const res = await fetch(`${API_BASE_URL}/api/materials/${id}`, {
|
|
|
|
|
|
|
| 121 |
method: 'DELETE',
|
| 122 |
headers: {
|
| 123 |
'Authorization': `Bearer ${session?.access_token}`
|
Frontend/src/utils/api.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
export const API_BASE_URL = import.meta.env.VITE_API_URL || window.location.origin;
|