mirror of
https://github.com/blw1138/Zordon.git
synced 2025-12-17 08:48:13 +00:00
Use alphanumeric API tokens instead of ints
This commit is contained in:
@@ -25,7 +25,7 @@ from src.engines.engine_manager import EngineManager
|
|||||||
from src.render_queue import RenderQueue, JobNotFoundError
|
from src.render_queue import RenderQueue, JobNotFoundError
|
||||||
from src.utilities.config import Config
|
from src.utilities.config import Config
|
||||||
from src.utilities.misc_helper import system_safe_path, current_system_os, current_system_cpu, \
|
from src.utilities.misc_helper import system_safe_path, current_system_os, current_system_cpu, \
|
||||||
current_system_os_version
|
current_system_os_version, num_to_alphanumeric
|
||||||
from src.utilities.server_helper import generate_thumbnail_for_job
|
from src.utilities.server_helper import generate_thumbnail_for_job
|
||||||
from src.utilities.zeroconf_server import ZeroconfServer
|
from src.utilities.zeroconf_server import ZeroconfServer
|
||||||
|
|
||||||
@@ -56,8 +56,8 @@ def jobs_json():
|
|||||||
try:
|
try:
|
||||||
hash_token = request.args.get('token', None)
|
hash_token = request.args.get('token', None)
|
||||||
all_jobs = [x.json() for x in RenderQueue.all_jobs()]
|
all_jobs = [x.json() for x in RenderQueue.all_jobs()]
|
||||||
job_cache_token = str(json.dumps(all_jobs).__hash__())
|
job_cache_int = int(json.dumps(all_jobs).__hash__())
|
||||||
|
job_cache_token = num_to_alphanumeric(job_cache_int)
|
||||||
if hash_token and hash_token == job_cache_token:
|
if hash_token and hash_token == job_cache_token:
|
||||||
return [], 204 # no need to update
|
return [], 204 # no need to update
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import os
|
|||||||
import platform
|
import platform
|
||||||
import shutil
|
import shutil
|
||||||
import socket
|
import socket
|
||||||
|
import string
|
||||||
import subprocess
|
import subprocess
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
@@ -156,3 +157,19 @@ def is_localhost(comparison_hostname):
|
|||||||
return comparison_hostname == local_hostname
|
return comparison_hostname == local_hostname
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def num_to_alphanumeric(num):
|
||||||
|
# List of possible alphanumeric characters
|
||||||
|
characters = string.ascii_letters + string.digits
|
||||||
|
|
||||||
|
# Make sure number is positive
|
||||||
|
num = abs(num)
|
||||||
|
|
||||||
|
# Convert number to alphanumeric
|
||||||
|
result = ""
|
||||||
|
while num > 0:
|
||||||
|
num, remainder = divmod(num, len(characters))
|
||||||
|
result += characters[remainder]
|
||||||
|
|
||||||
|
return result[::-1] # Reverse the result to get the correct alphanumeric string
|
||||||
|
|||||||
Reference in New Issue
Block a user