Skip to content

Commit 0ac0190

Browse files
committed
Refactor ticket request to use query params
Updated directupload and dvuploader modules to construct ticket request URLs using query parameters instead of the build_url helper. Also added API token to request headers for direct upload support check.
1 parent 8ea6e03 commit 0ac0190

2 files changed

Lines changed: 21 additions & 17 deletions

File tree

dvuploader/directupload.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from rich.progress import Progress, TaskID
1111

1212
from dvuploader.file import File
13-
from dvuploader.utils import build_url, init_logging, wait_for_dataset_unlock
13+
from dvuploader.utils import init_logging, wait_for_dataset_unlock
1414

1515
TESTING = bool(os.environ.get("DVUPLOADER_TESTING", False))
1616
MAX_FILE_DISPLAY = int(os.environ.get("DVUPLOADER_MAX_FILE_DISPLAY", 50))
@@ -205,14 +205,16 @@ async def _request_ticket(
205205
Returns:
206206
Dict: Upload ticket containing URL and storage identifier.
207207
"""
208-
url = build_url(
209-
endpoint=urljoin(dataverse_url, TICKET_ENDPOINT),
210-
key=api_token,
211-
persistentId=persistent_id,
212-
size=file_size,
208+
url = urljoin(dataverse_url, TICKET_ENDPOINT)
209+
210+
response = await session.get(
211+
url,
212+
timeout=None,
213+
params={
214+
"size": file_size,
215+
"persistentId": persistent_id,
216+
},
213217
)
214-
215-
response = await session.get(url, timeout=None)
216218
response.raise_for_status()
217219

218220
return response.json()["data"]

dvuploader/dvuploader.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
)
1818
from dvuploader.file import File
1919
from dvuploader.nativeupload import native_upload
20-
from dvuploader.utils import build_url, retrieve_dataset_files, setup_pbar
20+
from dvuploader.utils import retrieve_dataset_files, setup_pbar
2121

2222

2323
class DVUploader(BaseModel):
@@ -410,15 +410,17 @@ def _has_direct_upload(
410410
bool: True if direct upload is supported, False otherwise.
411411
"""
412412

413-
query = build_url(
414-
endpoint=urljoin(dataverse_url, TICKET_ENDPOINT),
415-
key=api_token,
416-
persistentId=persistent_id,
417-
size=1024,
418-
)
419-
420413
# Send HTTP request
421-
response = httpx.get(query)
414+
response = httpx.get(
415+
urljoin(dataverse_url, TICKET_ENDPOINT),
416+
params={
417+
"size": 1024,
418+
"persistentId": persistent_id,
419+
},
420+
headers={
421+
"X-Dataverse-key": api_token,
422+
},
423+
)
422424

423425
if response.status_code == 404:
424426
return False

0 commit comments

Comments
 (0)