Spaces:
Running
Running
fix hardcoded routers
Browse files
frontend/src/pages/MapDetailsPage/MapDetailPage.tsx
CHANGED
|
@@ -91,6 +91,13 @@ export default function MapDetailPage() {
|
|
| 91 |
];
|
| 92 |
|
| 93 |
const fetchMapData = useCallback(async (id: string) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
setIsNavigating(true);
|
| 95 |
setLoading(true);
|
| 96 |
|
|
@@ -112,7 +119,7 @@ export default function MapDetailPage() {
|
|
| 112 |
}, []);
|
| 113 |
|
| 114 |
useEffect(() => {
|
| 115 |
-
if (!mapId) {
|
| 116 |
setError('Map ID is required');
|
| 117 |
setLoading(false);
|
| 118 |
return;
|
|
@@ -177,6 +184,11 @@ export default function MapDetailPage() {
|
|
| 177 |
}, [map, search, srcFilter, catFilter, regionFilter, countryFilter, imageTypeFilter, showReferenceExamples, mapId, navigate, loading, isDeleting]);
|
| 178 |
|
| 179 |
const checkNavigationAvailability = async (currentId: string) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
try {
|
| 181 |
const response = await fetch('/api/images');
|
| 182 |
if (response.ok) {
|
|
|
|
| 91 |
];
|
| 92 |
|
| 93 |
const fetchMapData = useCallback(async (id: string) => {
|
| 94 |
+
// Validate the ID before making the request
|
| 95 |
+
if (!id || id === 'undefined' || id === 'null' || id.trim() === '') {
|
| 96 |
+
setError('Invalid Map ID');
|
| 97 |
+
setLoading(false);
|
| 98 |
+
return;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
setIsNavigating(true);
|
| 102 |
setLoading(true);
|
| 103 |
|
|
|
|
| 119 |
}, []);
|
| 120 |
|
| 121 |
useEffect(() => {
|
| 122 |
+
if (!mapId || mapId === 'undefined' || mapId === 'null') {
|
| 123 |
setError('Map ID is required');
|
| 124 |
setLoading(false);
|
| 125 |
return;
|
|
|
|
| 184 |
}, [map, search, srcFilter, catFilter, regionFilter, countryFilter, imageTypeFilter, showReferenceExamples, mapId, navigate, loading, isDeleting]);
|
| 185 |
|
| 186 |
const checkNavigationAvailability = async (currentId: string) => {
|
| 187 |
+
// Validate the ID before making the request
|
| 188 |
+
if (!currentId || currentId === 'undefined' || currentId === 'null' || currentId.trim() === '') {
|
| 189 |
+
return;
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
try {
|
| 193 |
const response = await fetch('/api/images');
|
| 194 |
if (response.ok) {
|
py_backend/app/crud.py
CHANGED
|
@@ -141,7 +141,7 @@ def get_all_captions_with_images(db: Session):
|
|
| 141 |
return (
|
| 142 |
db.query(models.Captions)
|
| 143 |
.options(
|
| 144 |
-
joinedload(models.Captions.images),
|
| 145 |
)
|
| 146 |
.all()
|
| 147 |
)
|
|
|
|
| 141 |
return (
|
| 142 |
db.query(models.Captions)
|
| 143 |
.options(
|
| 144 |
+
joinedload(models.Captions.images).joinedload(models.Images.countries),
|
| 145 |
)
|
| 146 |
.all()
|
| 147 |
)
|
py_backend/app/routers/caption.py
CHANGED
|
@@ -242,14 +242,8 @@ def get_all_captions_legacy_format(
|
|
| 242 |
# Get the associated image for this caption
|
| 243 |
if caption.images:
|
| 244 |
for image in caption.images:
|
| 245 |
-
# Create a response in the old format where caption data is embedded in image
|
| 246 |
from .upload import convert_image_to_dict
|
| 247 |
-
|
| 248 |
-
url = storage.get_object_url(image.file_key)
|
| 249 |
-
if url.startswith('/') and settings.STORAGE_PROVIDER == "local":
|
| 250 |
-
url = f"http://localhost:8000{url}"
|
| 251 |
-
except Exception:
|
| 252 |
-
url = f"/api/images/{image.image_id}/file"
|
| 253 |
|
| 254 |
img_dict = convert_image_to_dict(image, url)
|
| 255 |
|
|
|
|
| 242 |
# Get the associated image for this caption
|
| 243 |
if caption.images:
|
| 244 |
for image in caption.images:
|
|
|
|
| 245 |
from .upload import convert_image_to_dict
|
| 246 |
+
url = f"/api/images/{image.image_id}/file"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
|
| 248 |
img_dict = convert_image_to_dict(image, url)
|
| 249 |
|
py_backend/app/routers/upload.py
CHANGED
|
@@ -166,6 +166,16 @@ def list_images(db: Session = Depends(get_db)):
|
|
| 166 |
@router.get("/{image_id}", response_model=schemas.ImageOut)
|
| 167 |
def get_image(image_id: str, db: Session = Depends(get_db)):
|
| 168 |
"""Get a single image by ID"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
img = crud.get_image(db, image_id)
|
| 170 |
if not img:
|
| 171 |
raise HTTPException(404, "Image not found")
|
|
|
|
| 166 |
@router.get("/{image_id}", response_model=schemas.ImageOut)
|
| 167 |
def get_image(image_id: str, db: Session = Depends(get_db)):
|
| 168 |
"""Get a single image by ID"""
|
| 169 |
+
# Validate image_id before querying database
|
| 170 |
+
if not image_id or image_id in ['undefined', 'null', '']:
|
| 171 |
+
raise HTTPException(400, "Invalid image ID")
|
| 172 |
+
|
| 173 |
+
# Validate UUID format
|
| 174 |
+
import re
|
| 175 |
+
uuid_pattern = re.compile(r'^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$', re.IGNORECASE)
|
| 176 |
+
if not uuid_pattern.match(image_id):
|
| 177 |
+
raise HTTPException(400, "Invalid image ID format")
|
| 178 |
+
|
| 179 |
img = crud.get_image(db, image_id)
|
| 180 |
if not img:
|
| 181 |
raise HTTPException(404, "Image not found")
|