Spaces:
Running
Running
BitCheck Codex commited on
Commit ·
fb51cc2
1
Parent(s): acb83b5
fix: remove deprecated email aliases from image verification API
Browse files- README.md +0 -2
- app/routes/verify_image.py +2 -14
README.md
CHANGED
|
@@ -79,8 +79,6 @@ curl -X POST "http://127.0.0.1:7860/verify/image" \
|
|
| 79 |
Optional fields:
|
| 80 |
|
| 81 |
- `user_email`
|
| 82 |
-
- `user_emil` as a deprecated typo alias for `user_email`
|
| 83 |
-
- `user_gmail` as a deprecated alias for `user_email`
|
| 84 |
- `threshold`
|
| 85 |
- `run_explainability`
|
| 86 |
- `run_ocr`
|
|
|
|
| 79 |
Optional fields:
|
| 80 |
|
| 81 |
- `user_email`
|
|
|
|
|
|
|
| 82 |
- `threshold`
|
| 83 |
- `run_explainability`
|
| 84 |
- `run_ocr`
|
app/routes/verify_image.py
CHANGED
|
@@ -30,8 +30,6 @@ router = APIRouter()
|
|
| 30 |
@router.post("/verify/image", response_model=VerificationReport)
|
| 31 |
async def verify_image(
|
| 32 |
user_email: str | None = Form(None, description="Email address of the user who owns this image and report."),
|
| 33 |
-
user_emil: str | None = Form(None, description="Deprecated typo alias for user_email."),
|
| 34 |
-
user_gmail: str | None = Form(None, description="Deprecated alias for user_email."),
|
| 35 |
file: UploadFile = File(...),
|
| 36 |
run_explainability: bool = Form(True),
|
| 37 |
run_ocr: bool = Form(True),
|
|
@@ -40,7 +38,7 @@ async def verify_image(
|
|
| 40 |
threshold: float | None = Form(None),
|
| 41 |
) -> dict[str, Any]:
|
| 42 |
start = time.perf_counter()
|
| 43 |
-
normalized_user_email =
|
| 44 |
verification_id = new_verification_id()
|
| 45 |
suffix = validate_upload_metadata(file)
|
| 46 |
upload_path = save_upload(file, verification_id, suffix)
|
|
@@ -120,7 +118,7 @@ def list_reports(user_email: str | None = None) -> dict[str, Any]:
|
|
| 120 |
report = json.loads(path.read_text(encoding="utf-8"))
|
| 121 |
except Exception:
|
| 122 |
continue
|
| 123 |
-
report_user_email = report.get("user_email")
|
| 124 |
if normalized_user_email and report_user_email != normalized_user_email:
|
| 125 |
continue
|
| 126 |
reports.append(
|
|
@@ -146,16 +144,6 @@ def _safe(name: str, fn: Any, fallback: dict[str, Any]) -> dict[str, Any]:
|
|
| 146 |
return data
|
| 147 |
|
| 148 |
|
| 149 |
-
def _resolve_user_email(user_email: str | None, user_emil: str | None, user_gmail: str | None) -> str | None:
|
| 150 |
-
values = [value for value in (user_email, user_emil, user_gmail) if value and value.strip()]
|
| 151 |
-
if not values:
|
| 152 |
-
return None
|
| 153 |
-
normalized = {_validate_email(value) for value in values}
|
| 154 |
-
if len(normalized) > 1:
|
| 155 |
-
raise HTTPException(status_code=400, detail="user_email, user_emil, and user_gmail must match when more than one is provided.")
|
| 156 |
-
return normalized.pop()
|
| 157 |
-
|
| 158 |
-
|
| 159 |
def _validate_email(value: str) -> str:
|
| 160 |
email = value.strip().lower()
|
| 161 |
if not re.fullmatch(r"[^@\s]+@[^@\s]+\.[^@\s]+", email):
|
|
|
|
| 30 |
@router.post("/verify/image", response_model=VerificationReport)
|
| 31 |
async def verify_image(
|
| 32 |
user_email: str | None = Form(None, description="Email address of the user who owns this image and report."),
|
|
|
|
|
|
|
| 33 |
file: UploadFile = File(...),
|
| 34 |
run_explainability: bool = Form(True),
|
| 35 |
run_ocr: bool = Form(True),
|
|
|
|
| 38 |
threshold: float | None = Form(None),
|
| 39 |
) -> dict[str, Any]:
|
| 40 |
start = time.perf_counter()
|
| 41 |
+
normalized_user_email = _validate_email(user_email) if user_email else None
|
| 42 |
verification_id = new_verification_id()
|
| 43 |
suffix = validate_upload_metadata(file)
|
| 44 |
upload_path = save_upload(file, verification_id, suffix)
|
|
|
|
| 118 |
report = json.loads(path.read_text(encoding="utf-8"))
|
| 119 |
except Exception:
|
| 120 |
continue
|
| 121 |
+
report_user_email = report.get("user_email")
|
| 122 |
if normalized_user_email and report_user_email != normalized_user_email:
|
| 123 |
continue
|
| 124 |
reports.append(
|
|
|
|
| 144 |
return data
|
| 145 |
|
| 146 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
def _validate_email(value: str) -> str:
|
| 148 |
email = value.strip().lower()
|
| 149 |
if not re.fullmatch(r"[^@\s]+@[^@\s]+\.[^@\s]+", email):
|