This repository has been archived on 2024-08-23. You can view files and clone it, but cannot push or open issues or pull requests.
desktop_client/desktop_client/request_client.py

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