|
1 | 1 | import aiohttp
|
2 | 2 | import logging
|
| 3 | +import urllib.parse |
3 | 4 |
|
4 | 5 | from tusclient.client import TusClient
|
5 | 6 | from tusclient.exceptions import TusCommunicationError
|
@@ -38,27 +39,29 @@ async def _read_response(self, response):
|
38 | 39 | return response.status, data
|
39 | 40 |
|
40 | 41 | async def get(self, url):
|
41 |
| - response = await self.session.get(f"{self.api_url}{url}", headers=self._headers, allow_redirects=False) |
| 42 | + full_url = urllib.parse.urljoin(self.api_url, url) |
| 43 | + response = await self.session.get(full_url, headers=self._headers, allow_redirects=False) |
42 | 44 | return await self._read_response(response)
|
43 | 45 |
|
44 | 46 | async def post(self, url, json):
|
45 |
| - response = await self.session.post( |
46 |
| - f"{self.api_url}{url}", json=json, headers=self._headers, allow_redirects=False |
47 |
| - ) |
| 47 | + full_url = urllib.parse.urljoin(self.api_url, url) |
| 48 | + response = await self.session.post(full_url, json=json, headers=self._headers, allow_redirects=False) |
48 | 49 | return await self._read_response(response)
|
49 | 50 |
|
50 | 51 | async def put(self, url, json):
|
51 |
| - response = await self.session.put( |
52 |
| - f"{self.api_url}{url}", json=json, headers=self._headers, allow_redirects=False |
53 |
| - ) |
| 52 | + full_url = urllib.parse.urljoin(self.api_url, url) |
| 53 | + response = await self.session.put(full_url, json=json, headers=self._headers, allow_redirects=False) |
54 | 54 | return await self._read_response(response)
|
55 | 55 |
|
56 | 56 | def tus_upload(self, upload_token, fullpath, filename):
|
57 |
| - tus = TusClient(f"{self.tus_url}/new-package/tus/") |
| 57 | + full_url = urllib.parse.urljoin(self.tus_url, "/new-package/tus/") |
| 58 | + tus = TusClient(full_url) |
58 | 59 |
|
59 | 60 | try:
|
60 | 61 | uploader = tus.uploader(
|
61 |
| - fullpath, chunk_size=UPLOAD_CHUNK_SIZE, metadata={"filename": filename, "upload-token": upload_token} |
| 62 | + fullpath, |
| 63 | + chunk_size=UPLOAD_CHUNK_SIZE, |
| 64 | + metadata={"filename": filename, "upload-token": upload_token}, |
62 | 65 | )
|
63 | 66 | uploader.upload()
|
64 | 67 | except TusCommunicationError:
|
|
0 commit comments