25 lines
580 B
Python
25 lines
580 B
Python
import os
|
|
from typing import Self
|
|
|
|
import httpx
|
|
|
|
|
|
class RequestClient:
|
|
_client: httpx.Client = None
|
|
|
|
def __new__(cls) -> Self:
|
|
if cls._client is None:
|
|
url = os.environ.get("DRIVE_HOST_URL").strip()
|
|
if not url:
|
|
url = "localhost:3000"
|
|
cls._client = httpx.Client(base_url=url)
|
|
return super().__new__(cls)
|
|
|
|
@classmethod
|
|
def set_token(cls, token: str):
|
|
cls._client.headers = {"Authorization": f"Bearer {token}"}
|
|
|
|
@property
|
|
def client(self) -> httpx.Client:
|
|
return self._client
|