mirror of https://github.com/caronc/apprise
Ntfy inline images are now correctly displayed (#892)
parent
b6e07dd35e
commit
276da2ef79
|
@ -453,10 +453,6 @@ class NotifyNtfy(NotifyBase):
|
|||
'User-Agent': self.app_id,
|
||||
}
|
||||
|
||||
# Some default values for our request object to which we'll update
|
||||
# depending on what our payload is
|
||||
files = None
|
||||
|
||||
# See https://ntfy.sh/docs/publish/#publish-as-json
|
||||
data = {}
|
||||
|
||||
|
@ -494,11 +490,23 @@ class NotifyNtfy(NotifyBase):
|
|||
data['topic'] = topic
|
||||
virt_payload = data
|
||||
|
||||
if self.attach:
|
||||
virt_payload['attach'] = self.attach
|
||||
|
||||
if self.filename:
|
||||
virt_payload['filename'] = self.filename
|
||||
|
||||
else:
|
||||
# Point our payload to our parameters
|
||||
virt_payload = params
|
||||
notify_url += '/{topic}'.format(topic=topic)
|
||||
|
||||
# Prepare our Header
|
||||
virt_payload['filename'] = attach.name
|
||||
|
||||
with open(attach.path, 'rb') as fp:
|
||||
data = fp.read()
|
||||
|
||||
if image_url:
|
||||
headers['X-Icon'] = image_url
|
||||
|
||||
|
@ -523,18 +531,6 @@ class NotifyNtfy(NotifyBase):
|
|||
if self.__tags:
|
||||
headers['X-Tags'] = ",".join(self.__tags)
|
||||
|
||||
if isinstance(attach, AttachBase):
|
||||
# Prepare our Header
|
||||
params['filename'] = attach.name
|
||||
|
||||
# prepare our files object
|
||||
files = {'file': (attach.name, open(attach.path, 'rb'))}
|
||||
|
||||
elif self.attach is not None:
|
||||
data['attach'] = self.attach
|
||||
if self.filename is not None:
|
||||
data['filename'] = self.filename
|
||||
|
||||
self.logger.debug('ntfy POST URL: %s (cert_verify=%r)' % (
|
||||
notify_url, self.verify_certificate,
|
||||
))
|
||||
|
@ -547,13 +543,18 @@ class NotifyNtfy(NotifyBase):
|
|||
# Default response type
|
||||
response = None
|
||||
|
||||
if data:
|
||||
data = data if attach else dumps(data)
|
||||
|
||||
else: # not data:
|
||||
data = None
|
||||
|
||||
try:
|
||||
r = requests.post(
|
||||
notify_url,
|
||||
params=params if params else None,
|
||||
data=dumps(data) if data else None,
|
||||
data=data,
|
||||
headers=headers,
|
||||
files=files,
|
||||
auth=auth,
|
||||
verify=self.verify_certificate,
|
||||
timeout=self.request_timeout,
|
||||
|
@ -608,7 +609,6 @@ class NotifyNtfy(NotifyBase):
|
|||
notify_url) + 'notification.'
|
||||
)
|
||||
self.logger.debug('Socket Exception: %s' % str(e))
|
||||
return False, response
|
||||
|
||||
except (OSError, IOError) as e:
|
||||
self.logger.warning(
|
||||
|
@ -616,13 +616,8 @@ class NotifyNtfy(NotifyBase):
|
|||
attach.name if isinstance(attach, AttachBase)
|
||||
else virt_payload))
|
||||
self.logger.debug('I/O Exception: %s' % str(e))
|
||||
return False, response
|
||||
|
||||
finally:
|
||||
# Close our file (if it's open) stored in the second element
|
||||
# of our files tuple (index 1)
|
||||
if files:
|
||||
files['file'][1].close()
|
||||
return False, response
|
||||
|
||||
def url(self, privacy=False, *args, **kwargs):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue