mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
Handle offlien GitHub #763
Some checks are pending
docker / docker_dev (push) Waiting to run
Some checks are pending
docker / docker_dev (push) Waiting to run
This commit is contained in:
@@ -909,41 +909,44 @@ def collect_lang_strings(json, pref, stringSqlParams):
|
|||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
def checkNewVersion():
|
def checkNewVersion():
|
||||||
|
|
||||||
mylog('debug', [f"[Version check] Checking if new version available"])
|
mylog('debug', [f"[Version check] Checking if new version available"])
|
||||||
|
|
||||||
newVersion = False
|
newVersion = False
|
||||||
|
|
||||||
f = open(applicationPath + '/front/buildtimestamp.txt', 'r')
|
with open(applicationPath + '/front/buildtimestamp.txt', 'r') as f:
|
||||||
buildTimestamp = int(f.read().strip())
|
buildTimestamp = int(f.read().strip())
|
||||||
f.close()
|
|
||||||
|
|
||||||
data = ""
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
url = requests.get("https://api.github.com/repos/jokob-sk/NetAlertX/releases")
|
response = requests.get("https://api.github.com/repos/jokob-sk/NetAlertX/releases")
|
||||||
text = url.text
|
response.raise_for_status() # Raise an exception for HTTP errors
|
||||||
data = json.loads(text)
|
text = response.text
|
||||||
except requests.exceptions.ConnectionError as e:
|
except requests.exceptions.RequestException as e:
|
||||||
mylog('minimal', ["[Version check] ⚠ ERROR: Couldn't check for new release."])
|
mylog('minimal', ["[Version check] ⚠ ERROR: Couldn't check for new release."])
|
||||||
data = ""
|
return False
|
||||||
|
|
||||||
|
try:
|
||||||
|
data = json.loads(text)
|
||||||
|
except json.JSONDecodeError as e:
|
||||||
|
mylog('minimal', ["[Version check] ⚠ ERROR: Invalid JSON response from GitHub."])
|
||||||
|
return False
|
||||||
|
|
||||||
# make sure we received a valid response and not an API rate limit exceeded message
|
# make sure we received a valid response and not an API rate limit exceeded message
|
||||||
if data != "" and len(data) > 0 and isinstance(data, list) and "published_at" in data[0]:
|
if data and isinstance(data, list) and "published_at" in data[0]:
|
||||||
|
|
||||||
dateTimeStr = data[0]["published_at"]
|
dateTimeStr = data[0]["published_at"]
|
||||||
|
|
||||||
releaseTimestamp = int(datetime.datetime.strptime(dateTimeStr, '%Y-%m-%dT%H:%M:%S%z').timestamp())
|
releaseTimestamp = int(datetime.datetime.strptime(dateTimeStr, '%Y-%m-%dT%H:%M:%S%z').timestamp())
|
||||||
|
|
||||||
if releaseTimestamp > buildTimestamp + 600:
|
if releaseTimestamp > buildTimestamp + 600:
|
||||||
mylog('none', ["[Version check] New version of the container available!"])
|
mylog('none', ["[Version check] New version of the container available!"])
|
||||||
newVersion = True
|
newVersion = True
|
||||||
else:
|
else:
|
||||||
mylog('none', ["[Version check] Running the latest version."])
|
mylog('none', ["[Version check] Running the latest version."])
|
||||||
|
else:
|
||||||
|
mylog('minimal', ["[Version check] ⚠ ERROR: Received unexpected response from GitHub."])
|
||||||
|
|
||||||
return newVersion
|
return newVersion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
def initOrSetParam(db, parID, parValue):
|
def initOrSetParam(db, parID, parValue):
|
||||||
sql = db.sql
|
sql = db.sql
|
||||||
|
|||||||
Reference in New Issue
Block a user