1
0
mirror of https://github.com/acgnhiki/blrec.git synced 2025-04-25 05:00:23 +08:00

Fix the bark server url with path will cause erroneously url join .

If bark server url is "https://xxxurl/path1" , urllib.parse.urljoin("https://xxxurl/path1","/push") will return "https://xxxurl/push".   And  urllib.parse.urljoin("https://xxxurl/path1/","push") will return the expected result with "https://xxxurl/path1/push".  Server url end with "/", and pathurl begin without "/" is neccessary.
This commit is contained in:
ashesofdream 2023-08-29 14:44:10 +08:00 committed by acgnhiki
parent 5aad77c337
commit 8f77e843ad

View File

@ -266,12 +266,13 @@ class BarkResponse(TypedDict):
class Bark(MessagingProvider):
_server: Final = 'https://api.day.app'
_endpoint: Final = '/push'
_server: Final = 'https://api.day.app/'
_endpoint: Final = 'push'
def __init__(self, server: str = '', pushkey: str = '') -> None:
super().__init__()
self.server = server
self.server = server if len(server) > 0 else self._server
self.server = self.server if self.server[-1] == "/" else (self.server+'/')
self.pushkey = pushkey
async def send_message(
@ -287,7 +288,7 @@ class Bark(MessagingProvider):
async def _post_message(
self, title: str, content: str, msg_type: BarkMessageType
) -> None:
url = urljoin(self.server or self._server, self._endpoint)
url = urljoin(self.server, self._endpoint)
# content size is limited to a maximum size of 4 KB (4096 bytes)
if len(content.encode()) >= 4096:
content = content.encode()[:4090].decode(errors='ignore') + ' ...'