Skip to content

Commit

Permalink
feat: allow also URLs for dataset downloads (#65)
Browse files Browse the repository at this point in the history
* feat: check if url is valid

* fix: try better url pattern

---------

Co-authored-by: Ignacio Heredia <[email protected]>
  • Loading branch information
MartaOB and IgnacioHeredia authored Oct 28, 2024
1 parent bbbb11a commit 17563f5
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions ai4papi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,14 @@ def validate_conf(conf):
if datasets:
for d in datasets:

# Validate DOI
# Validate DOI and URL
# ref: https://stackoverflow.com/a/48524047/18471590
pattern = r"^10.\d{4,9}/[-._;()/:A-Z0-9]+$"
if not re.match(pattern, d['doi'], re.IGNORECASE):
doiPattern = r"^10.\d{4,9}/[-._;()/:A-Z0-9]+$"
urlPattern = r"https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)"
if not (re.match(doiPattern, d['doi'], re.IGNORECASE) or re.match(urlPattern, d['doi'], re.IGNORECASE)):
raise HTTPException(
status_code=400,
detail="Invalid DOI."
detail="Invalid DOI or URL."
)

# Check force pull parameter
Expand Down

0 comments on commit 17563f5

Please sign in to comment.