You can set where the backend server is now.

This commit is contained in:
Ada Werefox 2024-03-08 19:11:50 -06:00
parent eed3fe39c6
commit a76661cfad
10 changed files with 104 additions and 72 deletions

View File

@ -1,46 +1,15 @@
annotated-types==0.6.0
anyio==4.3.0
arrow==1.3.0
asgiref==3.7.2 asgiref==3.7.2
autopep8==2.0.4 autopep8==2.0.4
binaryornot==0.4.4
certifi==2024.2.2 certifi==2024.2.2
chardet==5.2.0
charset-normalizer==3.3.2 charset-normalizer==3.3.2
click==8.1.7 Django==5.0.3
cookiecutter==2.6.0
Django==5.0.2
django-browser-reload==1.12.1 django-browser-reload==1.12.1
django-tailwind==3.8.0 django-tailwind==3.8.0
fastapi==0.110.0
h11==0.14.0
httptools==0.6.1
idna==3.6 idna==3.6
Jinja2==3.1.3
markdown-it-py==3.0.0
MarkupSafe==2.1.5
mdurl==0.1.2
numpy==1.26.4 numpy==1.26.4
pyarrow==15.0.0 pyarrow==15.0.1
pycodestyle==2.11.1 pycodestyle==2.11.1
pydantic==2.6.3 pylance==0.10.2
pydantic_core==2.16.3
Pygments==2.17.2
python-dateutil==2.8.2
python-dotenv==1.0.1
python-slugify==8.0.4
PyYAML==6.0.1
requests==2.31.0 requests==2.31.0
rich==13.7.1
six==1.16.0
sniffio==1.3.1
sqlparse==0.4.4 sqlparse==0.4.4
starlette==0.36.3
text-unidecode==1.3
types-python-dateutil==2.8.19.20240106
typing_extensions==4.10.0
urllib3==2.2.1 urllib3==2.2.1
uvicorn==0.27.1
uvloop==0.19.0
watchfiles==0.21.0
websockets==12.0

View File

@ -1,27 +0,0 @@
annotated-types==0.6.0
anyio==4.3.0
asgiref==3.7.2
autopep8==2.0.4
click==8.1.7
Django==5.0.2
django-browser-reload==1.12.1
django-tailwind==3.8.0
fastapi==0.110.0
h11==0.14.0
httptools==0.6.1
idna==3.6
numpy==1.26.4
pyarrow==15.0.0
pycodestyle==2.11.1
pydantic==2.6.3
pydantic_core==2.16.3
python-dotenv==1.0.1
PyYAML==6.0.1
sniffio==1.3.1
sqlparse==0.4.4
starlette==0.36.3
typing_extensions==4.10.0
uvicorn==0.27.1
uvloop==0.19.0
watchfiles==0.21.0
websockets==12.0

View File

@ -0,0 +1,14 @@
from django import forms
from json import loads
class ServerAddressForm(forms.Form):
with open('tracker/static/tracker/data/listen_address.json', 'r') as address:
read_address = loads(address.read())
if (read_address['address']['user'] != ""):
server_address = read_address['address']['user']
else:
server_address = read_address['address']['default']
server_address_form = forms.URLField(
max_length=1312, initial=server_address, empty_value="http://localhost:8000/", label="")
server_address_form.widget.attrs["class"] = "w-full text-sm rounded-md border-2 border-bluelight-dark bg-[#242424]/10"

View File

@ -1,7 +1,9 @@
var current_hash = ""; var current_hash = "";
var server_address = "";
window.onload = () => { window.onload = () => {
fetch("http://localhost:8080/static/tracker/data/holy_cross_codes.json") get_updated_server_address();
fetch(`${document.URL}static/tracker/data/holy_cross_codes.json`)
.then((response) => response.json()) .then((response) => response.json())
.then( .then(
(data) => { (data) => {
@ -19,8 +21,26 @@ window.onload = () => {
); );
}; };
async function get_updated_server_address() {
fetch(`${document.URL}static/tracker/data/listen_address.json`)
.then((response) => response.json())
.then(
(data) => {
server_address_object = JSON.parse(JSON.stringify(data));
if (server_address_object.user != "") {
server_address = server_address_object.address.user;
} else {
server_address = server_address_object.address.default;
}
document.getElementById("id_server_address_form").value =
server_address;
},
(error) => console.log(error)
);
}
async function refresh_elements(cross_codes) { async function refresh_elements(cross_codes) {
fetch("http://localhost:8000/spoiler") fetch(server_address)
.then((response) => response.json()) .then((response) => response.json())
.then( .then(
(data) => { (data) => {
@ -31,6 +51,7 @@ async function refresh_elements(cross_codes) {
return; return;
} else { } else {
current_hash = response_object.Debug.Hash; current_hash = response_object.Debug.Hash;
get_updated_server_address();
} }
// Parse out data from the back-end into variables. // Parse out data from the back-end into variables.
@ -319,7 +340,7 @@ async function refresh_elements(cross_codes) {
scene_entrances_undiscovered <= 0 scene_entrances_undiscovered <= 0
) { ) {
summary_block.classList.add("hidden"); summary_block.classList.add("hidden");
breakdown_block.classList.add("hidden"); // breakdown_block.classList.add("hidden");
} }
new_summary_list.firstElementChild.appendChild( new_summary_list.firstElementChild.appendChild(
summary_block.cloneNode(true) summary_block.cloneNode(true)
@ -346,6 +367,7 @@ async function refresh_elements(cross_codes) {
}, },
(error) => { (error) => {
document.getElementById("status-block").classList.remove("hidden"); document.getElementById("status-block").classList.remove("hidden");
// get_updated_server_address();
return error; return error;
} }
); );

View File

@ -0,0 +1 @@
{"address": {"default": "http://localhost:8000/spoiler", "user": "http://localhost:8000/spoiler"}}

View File

@ -0,0 +1,13 @@
<form action="{% url "set_address" %}"
method="post"
class="px-2 py-1 flex flex-row space-x-2 rounded-md ring-4 ring-bluelight-dark bg-bluelight-translucent"
id="server-address-form">
<div class="w-full text-sm rounded-md border-2 border-bluelight-dark bg-[#242424]/10" hidden></div>
{% csrf_token %}
<label for="address-form-input"
class="m-auto text-md justify-center align-top min-w-fit text-md text-nowrap">Server:</label>
{% for field in form %}{{ field }}{% endfor %}
<input type="submit"
value="Submit"
class="p-2 m-auto text-sm rounded-md ring-2 ring-bluelight-dark bg-bluelight-translucent" />
</form>

View File

@ -15,6 +15,7 @@
&nbsp;Tunic Transition Tracker &nbsp;Tunic Transition Tracker
</div> </div>
<hr class="border-2 border-bluelight-translucent-dark rounded-md" /> <hr class="border-2 border-bluelight-translucent-dark rounded-md" />
{% include "tracker/address/index.html" %}
{% include "tracker/status/index.html" %} {% include "tracker/status/index.html" %}
<div class="p-4 flex flex-col max-w-full space-y-4 md:space-y-4 text-md rounded-md ring-4 bg-bluelight-translucent ring-bluelight-dark" <div class="p-4 flex flex-col max-w-full space-y-4 md:space-y-4 text-md rounded-md ring-4 bg-bluelight-translucent ring-bluelight-dark"
id="overview"> id="overview">

View File

@ -4,4 +4,5 @@ from . import views
urlpatterns = [ urlpatterns = [
path("", views.index, name="index"), path("", views.index, name="index"),
path("set/address/", views.set_address, name="set_address"),
] ]

View File

@ -1,19 +1,28 @@
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse, HttpResponseRedirect
from django.template import loader from django.template import loader
from json import loads from json import loads, dumps
from math import floor from math import floor
import requests import requests
from .forms import ServerAddressForm
# Create your views here. # Create your views here.
def index(request): def index(request):
request_data = None request_data = None
server_address = 'http://localhost:8000/spoiler'
with open('tracker/static/tracker/data/listen_address.json', 'r') as address:
read_address = loads(address.read())
if (read_address['address']['user'] != ""):
server_address = read_address['address']['user']
else:
server_address = read_address['address']['default']
# server_address = 'http://localhost:8000/spoiler'
is_hidden = True is_hidden = True
try: try:
request_data = requests.get(server_address).text request_data = requests.get(
server_address, timeout=5, verify=True).text
except: except:
with open('empty_spoiler.json', 'r') as t: with open('empty_spoiler.json', 'r') as t:
try: try:
@ -52,6 +61,8 @@ def index(request):
current_cross_codes = {} current_cross_codes = {}
print(e) print(e)
template = loader.get_template("tracker/index.html") template = loader.get_template("tracker/index.html")
form = ServerAddressForm()
form.fields["server_address_form"].initial = server_address
context = { context = {
"server_address": server_address, "server_address": server_address,
"is_hidden": is_hidden, "is_hidden": is_hidden,
@ -63,6 +74,24 @@ def index(request):
"current_scene": { "current_scene": {
"title": tracker_current_scene, "title": tracker_current_scene,
"data": tracker_current_scene_data "data": tracker_current_scene_data
} },
"form": form
} }
return HttpResponse(template.render(context, request)) return HttpResponse(template.render(context, request))
def set_address(request):
if request.method == "POST":
form = ServerAddressForm(request.POST)
form.label_classes = ("p-2")
if form.is_valid():
with open("tracker/static/tracker/data/listen_address.json", "r") as la:
listen_address = loads(la.read())
listen_address["address"]["user"] = form.cleaned_data["server_address_form"]
with open("tracker/static/tracker/data/listen_address.json", "w") as la:
la.write(dumps(listen_address))
return HttpResponseRedirect("/")
else:
form = ServerAddressForm()
return render(request, "tracker/index.html", {"form": form})

View File

@ -23,9 +23,12 @@ BASE_DIR = Path(__file__).resolve().parent.parent
SECRET_KEY = 'django-insecure-ae-fwu3z$wexeiac4ggt0l@x1*uq5v9-q&$y#frf85xli)bo8f' SECRET_KEY = 'django-insecure-ae-fwu3z$wexeiac4ggt0l@x1*uq5v9-q&$y#frf85xli)bo8f'
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True DEBUG = False
ALLOWED_HOSTS = [] ALLOWED_HOSTS = [
"localhost",
"127.0.0.1"
]
# Application definition # Application definition
@ -118,7 +121,13 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.0/howto/static-files/ # https://docs.djangoproject.com/en/5.0/howto/static-files/
STATIC_URL = 'static/' STATIC_URL = '/static/'
STATIC_ROOT = "tracker/static/"
STATICFILES_DIRS = [
BASE_DIR / "static/"
]
# Default primary key field type # Default primary key field type
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field # https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field