|
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
|
@@ -36,27 +37,29 @@ async def _read_response(self, response):
|
36 | 37 | return response.status, data
|
37 | 38 |
|
38 | 39 | async def get(self, url):
|
39 |
| - response = await self.session.get(f"{self.api_url}{url}", headers=self._headers, allow_redirects=False) |
| 40 | + full_url = urllib.parse.urljoin(self.api_url, url) |
| 41 | + response = await self.session.get(full_url, headers=self._headers, allow_redirects=False) |
40 | 42 | return await self._read_response(response)
|
41 | 43 |
|
42 | 44 | async def post(self, url, json):
|
43 |
| - response = await self.session.post( |
44 |
| - f"{self.api_url}{url}", json=json, headers=self._headers, allow_redirects=False |
45 |
| - ) |
| 45 | + full_url = urllib.parse.urljoin(self.api_url, url) |
| 46 | + response = await self.session.post(full_url, json=json, headers=self._headers, allow_redirects=False) |
46 | 47 | return await self._read_response(response)
|
47 | 48 |
|
48 | 49 | async def put(self, url, json):
|
49 |
| - response = await self.session.put( |
50 |
| - f"{self.api_url}{url}", json=json, headers=self._headers, allow_redirects=False |
51 |
| - ) |
| 50 | + full_url = urllib.parse.urljoin(self.api_url, url) |
| 51 | + response = await self.session.put(full_url, json=json, headers=self._headers, allow_redirects=False) |
52 | 52 | return await self._read_response(response)
|
53 | 53 |
|
54 | 54 | def tus_upload(self, upload_token, fullpath, filename):
|
55 |
| - tus = TusClient(f"{self.tus_url}/new-package/tus/") |
| 55 | + full_url = urllib.parse.urljoin(self.tus_url, "/new-package/tus/") |
| 56 | + tus = TusClient(full_url) |
56 | 57 |
|
57 | 58 | try:
|
58 | 59 | uploader = tus.uploader(
|
59 |
| - fullpath, chunk_size=UPLOAD_CHUNK_SIZE, metadata={"filename": filename, "upload-token": upload_token} |
| 60 | + fullpath, |
| 61 | + chunk_size=UPLOAD_CHUNK_SIZE, |
| 62 | + metadata={"filename": filename, "upload-token": upload_token}, |
60 | 63 | )
|
61 | 64 | uploader.upload()
|
62 | 65 | except TusCommunicationError:
|
|
0 commit comments