mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Add updates to notifs
This commit is contained in:
parent
5266e6e098
commit
ff1ba23830
@ -579,8 +579,7 @@ class Helpers:
|
||||
|
||||
return version_data
|
||||
|
||||
@staticmethod
|
||||
def get_announcements():
|
||||
def get_announcements(self):
|
||||
data = []
|
||||
try:
|
||||
response = requests.get("https://craftycontrol.com/notify.json", timeout=2)
|
||||
@ -588,6 +587,8 @@ class Helpers:
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to fetch notifications with error: {e}")
|
||||
|
||||
if self.update_available:
|
||||
data.append(self.update_available)
|
||||
return data
|
||||
|
||||
def get_version_string(self):
|
||||
|
@ -726,12 +726,23 @@ class TasksManager:
|
||||
def check_for_updates(self):
|
||||
logger.info("Checking for Crafty updates...")
|
||||
self.helper.update_available = self.helper.check_remote_version()
|
||||
remote = self.helper.update_available
|
||||
if self.helper.update_available:
|
||||
logger.info(f"Found new version {self.helper.update_available}")
|
||||
else:
|
||||
logger.info(
|
||||
"No updates found! You are on the most up to date Crafty version."
|
||||
)
|
||||
if self.helper.update_available:
|
||||
self.helper.update_available = {
|
||||
"id": str(remote),
|
||||
"title": f"{remote} Update Available",
|
||||
"date": "",
|
||||
"desc": "Instructions for updating can be found"
|
||||
" by clicking this notification.",
|
||||
"link": "https://docs.craftycontrol.com/pages/"
|
||||
"getting-started/installation/linux/?h=updating#updating-crafty",
|
||||
}
|
||||
logger.info("Refreshing Gravatar PFPs...")
|
||||
for user in HelperUsers.get_all_users():
|
||||
if user.email:
|
||||
|
@ -40,6 +40,8 @@ class ApiAnnounceIndexHandler(BaseApiHandler):
|
||||
for item in cleared[:]:
|
||||
if item not in res:
|
||||
cleared.remove(item)
|
||||
updata = {"cleared_notifs": ",".join(cleared)}
|
||||
self.controller.users.update_user(auth_data[4]["user_id"], updata)
|
||||
if len(cleared) > 0:
|
||||
for item in data[:]:
|
||||
if item["id"] in cleared:
|
||||
@ -93,7 +95,7 @@ class ApiAnnounceIndexHandler(BaseApiHandler):
|
||||
for item in cleared_notifs[:]:
|
||||
if item not in res:
|
||||
cleared_notifs.remove(item)
|
||||
if is_valid_uuid(data["id"]):
|
||||
if str(data["id"]) in str(res):
|
||||
cleared_notifs.append(data["id"])
|
||||
else:
|
||||
self.finish_json(200, {"status": "error", "error": "INVALID_DATA"})
|
||||
@ -107,12 +109,3 @@ class ApiAnnounceIndexHandler(BaseApiHandler):
|
||||
"data": {},
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def is_valid_uuid(value):
|
||||
try:
|
||||
uuid.UUID(str(value))
|
||||
|
||||
return True
|
||||
except ValueError:
|
||||
return False
|
||||
|
Loading…
Reference in New Issue
Block a user