satori-python-client 0.14.0__tar.gz → 0.14.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: satori-python-client
3
- Version: 0.14.0
3
+ Version: 0.14.2
4
4
  Summary: Satori Protocol SDK for python, specify client part
5
5
  Home-page: https://github.com/RF-Tar-Railt/satori-python
6
6
  Author-Email: RF-Tar-Railt <rf_tar_railt@qq.com>
@@ -24,7 +24,7 @@ classifiers = [
24
24
  "Programming Language :: Python :: 3.12",
25
25
  "Operating System :: OS Independent",
26
26
  ]
27
- version = "0.14.0"
27
+ version = "0.14.2"
28
28
 
29
29
  [project.license]
30
30
  text = "MIT"
@@ -61,6 +61,20 @@ class Account(Generic[TP]):
61
61
  def identity(self):
62
62
  return f"{self.platform}/{self.self_id}"
63
63
 
64
+ def ensure_url(self, url: str) -> URL:
65
+ """确定链接形式。
66
+
67
+ 若链接符合以下条件之一,则返回链接的代理形式 ({host}/{path}/{version}/proxy/{url}):
68
+ - 链接以 "upload://" 开头
69
+ - 链接开头出现在 self_info.proxy_urls 中的某一项
70
+ """
71
+ if url.startswith("upload"):
72
+ return self.config.api_base / "proxy" / url.lstrip("/")
73
+ for proxy_url in self.self_info.proxy_urls:
74
+ if url.startswith(proxy_url):
75
+ return self.config.api_base / "proxy" / url.lstrip("/")
76
+ return URL(url)
77
+
64
78
  def __repr__(self):
65
79
  return f"<Account {self.self_id} ({self.platform})>"
66
80
 
@@ -63,6 +63,14 @@ class Account(Generic[TP]):
63
63
  def custom(
64
64
  self, *, protocol_cls: type[TP1] = ApiProtocol, host: str, port: int, token: str | None = None
65
65
  ) -> Account[TP1]: ...
66
+ def ensure_url(self, url: str) -> URL:
67
+ """确定链接形式。
68
+
69
+ 若链接符合以下条件之一,则返回链接的代理形式 ({host}/{path}/{version}/proxy/{url}):
70
+ - 链接以 "upload://" 开头
71
+ - 链接开头出现在 self_info.proxy_urls 中的某一项
72
+ """
73
+
66
74
  async def send(self, event: Event, message: str | Iterable[str | Element]) -> list[MessageObject]:
67
75
  """发送消息。返回一个 `MessageObject` 对象构成的数组。
68
76
 
@@ -37,7 +37,7 @@ class ApiProtocol:
37
37
 
38
38
  async def download(self, url: str):
39
39
  """访问内部链接。"""
40
- endpoint = self.account.config.api_base / "proxy" / url.lstrip("/")
40
+ endpoint = self.account.ensure_url(url)
41
41
  aio = Launart.current().get_component(AiohttpClientService)
42
42
  async with aio.session.get(endpoint) as resp:
43
43
  await validate_response(resp, noreturn=True)