mirror of
https://github.com/StuffAnThings/qbit_manage.git
synced 2025-10-11 14:27:09 +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:
|
try:
|
||||||
self.NotifiarrFactory = Notifiarr(self, {
|
self.NotifiarrFactory = Notifiarr(self, {
|
||||||
"apikey": self.util.check_for_attribute(self.data, "apikey", parent="notifiarr", throw=True),
|
"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)
|
"instance": self.util.check_for_attribute(self.data, "instance", parent="notifiarr", default=False, do_print=False, save=False)
|
||||||
})
|
})
|
||||||
except Failed as e:
|
except Failed as e:
|
||||||
|
|
|
@ -6,42 +6,28 @@ from json import JSONDecodeError
|
||||||
logger = util.logger
|
logger = util.logger
|
||||||
|
|
||||||
base_url = "https://notifiarr.com/api/v1/"
|
base_url = "https://notifiarr.com/api/v1/"
|
||||||
dev_url = "https://dev.notifiarr.com/api/v1/"
|
|
||||||
|
|
||||||
|
|
||||||
class Notifiarr:
|
class Notifiarr:
|
||||||
def __init__(self, config, params):
|
def __init__(self, config, params):
|
||||||
self.config = config
|
self.config = config
|
||||||
self.apikey = params["apikey"]
|
self.apikey = params["apikey"]
|
||||||
self.develop = params["develop"]
|
self.header = {"X-API-Key": self.apikey}
|
||||||
self.test = params["test"]
|
|
||||||
self.instance = params["instance"]
|
self.instance = params["instance"]
|
||||||
logger.secret(self.apikey)
|
logger.secret(self.apikey)
|
||||||
url, _ = self.get_url("user/validate/")
|
response = self.config.get(f"{base_url}user/qbitManage/", headers=self.header, params={"fetch": "settings"})
|
||||||
response = self.config.get(url)
|
|
||||||
response_json = None
|
response_json = None
|
||||||
try:
|
try:
|
||||||
response_json = response.json()
|
response_json = response.json()
|
||||||
except JSONDecodeError as e:
|
except JSONDecodeError as e:
|
||||||
if response.status_code >= 400:
|
logger.debug(e)
|
||||||
if response.status_code == 525:
|
raise Failed("Notifiarr Error: Invalid response")
|
||||||
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?")
|
|
||||||
if response.status_code >= 400 or ("result" in response_json and response_json["result"] == "error"):
|
if response.status_code >= 400 or ("result" in response_json and response_json["result"] == "error"):
|
||||||
logger.debug(f"Response: {response_json}")
|
logger.debug(f"Response: {response_json}")
|
||||||
raise Failed(f"({response.status_code} [{response.reason}]) {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")
|
raise Failed("Notifiarr Error: Invalid apikey")
|
||||||
|
|
||||||
def get_url(self, path):
|
def notification(self, json):
|
||||||
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}
|
params = {"qbit_client": self.config.data["qbt"]["host"], "instance": self.instance}
|
||||||
return url, params
|
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:
|
if self.notifiarr is None:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
url, params = self.notifiarr.get_url("notification/qbitManage/")
|
|
||||||
for x in range(6):
|
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:
|
if response.status_code < 500:
|
||||||
break
|
break
|
||||||
elif webhook == "apprise":
|
elif webhook == "apprise":
|
||||||
|
|
Loading…
Add table
Reference in a new issue