mirror of
https://github.com/jaypyles/Scraperr.git
synced 2025-12-12 18:56:17 +00:00
fix: small fixes to accompany the docs implementation (#35)
This commit is contained in:
@@ -4,6 +4,7 @@ from gc import disable
|
||||
from queue import Empty
|
||||
from typing import Any, Optional
|
||||
from datetime import datetime, timedelta
|
||||
import logging
|
||||
|
||||
# PDM
|
||||
from jose import JWTError, jwt
|
||||
@@ -16,6 +17,8 @@ from fastapi.security import OAuth2PasswordBearer
|
||||
from api.backend.schemas import User, UserInDB, TokenData
|
||||
from api.backend.database import get_user_collection
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
_ = load_dotenv()
|
||||
|
||||
SECRET_KEY = os.getenv("SECRET_KEY") or ""
|
||||
@@ -74,10 +77,16 @@ def create_access_token(
|
||||
|
||||
|
||||
async def get_current_user(token: str = Depends(oauth2_scheme)):
|
||||
LOG.info(f"Getting current user with token: {token}")
|
||||
|
||||
if not token:
|
||||
return EMPTY_USER
|
||||
|
||||
try:
|
||||
payload: Optional[dict[str, Any]] = jwt.decode(
|
||||
token, SECRET_KEY, algorithms=[ALGORITHM]
|
||||
)
|
||||
|
||||
if not payload:
|
||||
return EMPTY_USER
|
||||
|
||||
@@ -91,6 +100,10 @@ async def get_current_user(token: str = Depends(oauth2_scheme)):
|
||||
except JWTError:
|
||||
return EMPTY_USER
|
||||
|
||||
except Exception as e:
|
||||
LOG.error(f"Exception occurred: {e}")
|
||||
return EMPTY_USER
|
||||
|
||||
user = await get_user(email=token_data.email)
|
||||
|
||||
if user is None:
|
||||
|
||||
@@ -5,6 +5,7 @@ from io import StringIO
|
||||
import csv
|
||||
import logging
|
||||
import random
|
||||
from typing import Optional
|
||||
|
||||
# PDM
|
||||
from fastapi import Depends, APIRouter
|
||||
@@ -26,7 +27,7 @@ from api.backend.models import (
|
||||
Job,
|
||||
)
|
||||
from api.backend.schemas import User
|
||||
from api.backend.auth.auth_utils import get_current_user
|
||||
from api.backend.auth.auth_utils import get_current_user, EMPTY_USER
|
||||
from api.backend.utils import clean_text
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@@ -49,7 +50,7 @@ async def submit_scrape_job(job: Job):
|
||||
job_dict = job.model_dump()
|
||||
await insert(job_dict)
|
||||
|
||||
return JSONResponse(content=f"Job queued for scraping: {job.id}")
|
||||
return JSONResponse(content={"id": job.id})
|
||||
except Exception as e:
|
||||
return JSONResponse(content={"error": str(e)}, status_code=500)
|
||||
|
||||
@@ -70,6 +71,7 @@ async def retrieve_scrape_jobs(
|
||||
@job_router.get("/job/{id}")
|
||||
async def job(id: str, user: User = Depends(get_current_user)):
|
||||
LOG.info(f"Retrieving jobs for account: {user.email}")
|
||||
|
||||
try:
|
||||
filter = {"user": user.email, "id": id}
|
||||
results = await query(filter)
|
||||
|
||||
@@ -7,12 +7,10 @@ from lxml import etree
|
||||
from seleniumwire import webdriver
|
||||
from lxml.etree import _Element # type: ignore [reportPrivateImport]
|
||||
from fake_useragent import UserAgent
|
||||
from webdriver_manager.chrome import ChromeDriverManager
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
from selenium.webdriver.chrome.options import Options as ChromeOptions
|
||||
from selenium.webdriver.chrome.service import Service
|
||||
from urllib.parse import urlparse, urljoin
|
||||
|
||||
from api.backend.models import Element, CapturedElement
|
||||
|
||||
@@ -111,7 +111,10 @@ export const JobSubmitter = ({ stateProps }: Props) => {
|
||||
return response.json();
|
||||
})
|
||||
.then((data) => {
|
||||
setSnackbarMessage(data || "Job submitted successfully.");
|
||||
setSnackbarMessage(
|
||||
`Job: ${data.id} submitted successfully.` ||
|
||||
"Job submitted successfully."
|
||||
);
|
||||
setSnackbarSeverity("info");
|
||||
setSnackbarOpen(true);
|
||||
})
|
||||
|
||||
@@ -219,7 +219,8 @@ const AI: React.FC = () => {
|
||||
</Box>
|
||||
) : (
|
||||
<>
|
||||
{messages.map((message, index) => (
|
||||
{messages &&
|
||||
messages.map((message, index) => (
|
||||
<Box
|
||||
key={index}
|
||||
sx={{
|
||||
|
||||
Reference in New Issue
Block a user