mirror of
https://github.com/StuffAnThings/qbit_manage.git
synced 2024-11-10 17:47:13 +08:00
Notifiarr update
This commit is contained in:
parent
cdca77d88e
commit
75552ab5c2
3 changed files with 9 additions and 26 deletions
|
@ -155,8 +155,6 @@ class Config:
|
|||
try:
|
||||
self.NotifiarrFactory = Notifiarr(self, {
|
||||
"apikey": self.util.check_for_attribute(self.data, "apikey", parent="notifiarr", throw=True),
|
||||
"develop": self.util.check_for_attribute(self.data, "develop", parent="notifiarr", var_type="bool", default=False, do_print=False, save=False),
|
||||
"test": self.util.check_for_attribute(self.data, "test", parent="notifiarr", var_type="bool", default=False, do_print=False, save=False),
|
||||
"instance": self.util.check_for_attribute(self.data, "instance", parent="notifiarr", default=False, do_print=False, save=False)
|
||||
})
|
||||
except Failed as e:
|
||||
|
|
|
@ -6,42 +6,28 @@ from json import JSONDecodeError
|
|||
logger = util.logger
|
||||
|
||||
base_url = "https://notifiarr.com/api/v1/"
|
||||
dev_url = "https://dev.notifiarr.com/api/v1/"
|
||||
|
||||
|
||||
class Notifiarr:
|
||||
def __init__(self, config, params):
|
||||
self.config = config
|
||||
self.apikey = params["apikey"]
|
||||
self.develop = params["develop"]
|
||||
self.test = params["test"]
|
||||
self.header = {"X-API-Key": self.apikey}
|
||||
self.instance = params["instance"]
|
||||
logger.secret(self.apikey)
|
||||
url, _ = self.get_url("user/validate/")
|
||||
response = self.config.get(url)
|
||||
response = self.config.get(f"{base_url}user/qbitManage/", headers=self.header, params={"fetch": "settings"})
|
||||
response_json = None
|
||||
try:
|
||||
response_json = response.json()
|
||||
except JSONDecodeError as e:
|
||||
if response.status_code >= 400:
|
||||
if response.status_code == 525:
|
||||
raise Failed("Notifiarr Error (Response: 525): SSL handshake between Cloudflare and the origin web server failed.")
|
||||
else:
|
||||
raise Failed(e)
|
||||
if response_json is None:
|
||||
raise Failed("Notifiarr Error: Unable to connect to Notifiarr. It may be down?")
|
||||
logger.debug(e)
|
||||
raise Failed("Notifiarr Error: Invalid response")
|
||||
if response.status_code >= 400 or ("result" in response_json and response_json["result"] == "error"):
|
||||
logger.debug(f"Response: {response_json}")
|
||||
raise Failed(f"({response.status_code} [{response.reason}]) {response_json}")
|
||||
if not params["test"] and not response_json["details"]["response"]:
|
||||
if not response_json["details"]["response"]:
|
||||
raise Failed("Notifiarr Error: Invalid apikey")
|
||||
|
||||
def get_url(self, path):
|
||||
url = f"{dev_url if self.develop else base_url}{'notification/test' if self.test else f'{path}{self.apikey}'}"
|
||||
if self.config.trace_mode:
|
||||
logger.debug(url)
|
||||
if self.test:
|
||||
params = {"event": f"qbitManage-{self.apikey[:5]}", "qbit_client": self.config.data["qbt"]["host"], "instance": self.instance}
|
||||
else:
|
||||
params = {"qbit_client": self.config.data["qbt"]["host"], "instance": self.instance}
|
||||
return url, params
|
||||
def notification(self, json):
|
||||
params = {"qbit_client": self.config.data["qbt"]["host"], "instance": self.instance}
|
||||
return self.config.get(f"{base_url}notification/qbitManage/", json=json, headers=self.header, params=params)
|
||||
|
|
|
@ -35,9 +35,8 @@ class Webhooks:
|
|||
if self.notifiarr is None:
|
||||
break
|
||||
else:
|
||||
url, params = self.notifiarr.get_url("notification/qbitManage/")
|
||||
for x in range(6):
|
||||
response = self.config.get(url, json=json, params=params)
|
||||
response = self.notifiarr.notification(json=json)
|
||||
if response.status_code < 500:
|
||||
break
|
||||
elif webhook == "apprise":
|
||||
|
|
Loading…
Reference in a new issue