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,
|
'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
|
# See https://ntfy.sh/docs/publish/#publish-as-json
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
|
@ -494,11 +490,23 @@ class NotifyNtfy(NotifyBase):
|
||||||
data['topic'] = topic
|
data['topic'] = topic
|
||||||
virt_payload = data
|
virt_payload = data
|
||||||
|
|
||||||
|
if self.attach:
|
||||||
|
virt_payload['attach'] = self.attach
|
||||||
|
|
||||||
|
if self.filename:
|
||||||
|
virt_payload['filename'] = self.filename
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Point our payload to our parameters
|
# Point our payload to our parameters
|
||||||
virt_payload = params
|
virt_payload = params
|
||||||
notify_url += '/{topic}'.format(topic=topic)
|
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:
|
if image_url:
|
||||||
headers['X-Icon'] = image_url
|
headers['X-Icon'] = image_url
|
||||||
|
|
||||||
|
@ -523,18 +531,6 @@ class NotifyNtfy(NotifyBase):
|
||||||
if self.__tags:
|
if self.__tags:
|
||||||
headers['X-Tags'] = ",".join(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)' % (
|
self.logger.debug('ntfy POST URL: %s (cert_verify=%r)' % (
|
||||||
notify_url, self.verify_certificate,
|
notify_url, self.verify_certificate,
|
||||||
))
|
))
|
||||||
|
@ -547,13 +543,18 @@ class NotifyNtfy(NotifyBase):
|
||||||
# Default response type
|
# Default response type
|
||||||
response = None
|
response = None
|
||||||
|
|
||||||
|
if data:
|
||||||
|
data = data if attach else dumps(data)
|
||||||
|
|
||||||
|
else: # not data:
|
||||||
|
data = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r = requests.post(
|
r = requests.post(
|
||||||
notify_url,
|
notify_url,
|
||||||
params=params if params else None,
|
params=params if params else None,
|
||||||
data=dumps(data) if data else None,
|
data=data,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
files=files,
|
|
||||||
auth=auth,
|
auth=auth,
|
||||||
verify=self.verify_certificate,
|
verify=self.verify_certificate,
|
||||||
timeout=self.request_timeout,
|
timeout=self.request_timeout,
|
||||||
|
@ -608,7 +609,6 @@ class NotifyNtfy(NotifyBase):
|
||||||
notify_url) + 'notification.'
|
notify_url) + 'notification.'
|
||||||
)
|
)
|
||||||
self.logger.debug('Socket Exception: %s' % str(e))
|
self.logger.debug('Socket Exception: %s' % str(e))
|
||||||
return False, response
|
|
||||||
|
|
||||||
except (OSError, IOError) as e:
|
except (OSError, IOError) as e:
|
||||||
self.logger.warning(
|
self.logger.warning(
|
||||||
|
@ -616,13 +616,8 @@ class NotifyNtfy(NotifyBase):
|
||||||
attach.name if isinstance(attach, AttachBase)
|
attach.name if isinstance(attach, AttachBase)
|
||||||
else virt_payload))
|
else virt_payload))
|
||||||
self.logger.debug('I/O Exception: %s' % str(e))
|
self.logger.debug('I/O Exception: %s' % str(e))
|
||||||
return False, response
|
|
||||||
|
|
||||||
finally:
|
return False, response
|
||||||
# Close our file (if it's open) stored in the second element
|
|
||||||
# of our files tuple (index 1)
|
|
||||||
if files:
|
|
||||||
files['file'][1].close()
|
|
||||||
|
|
||||||
def url(self, privacy=False, *args, **kwargs):
|
def url(self, privacy=False, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue