This commit is contained in:
Izalia Mae 2022-04-21 13:59:49 -04:00
parent 01fc4e6c7e
commit 5a2804f997
7 changed files with 46 additions and 62 deletions

View file

@ -10,7 +10,7 @@ from .watcher import SaveWatcher
@click.option('--host', '-h', default='0.0.0.0', help='Address the web server should listen on')
@click.option('--port', '-p', default=8080, help='Port the web server should listen on')
@click.option('--save', '-s', type=Path, help='Path to Borderlands 2 game saves')
@click.option('--access-log', '-a', is_flag=True, help='Enable the server\'s access logging')
@click.option('--access-log', '-a', is_flag=True, default=True, help='Enable the server\'s access logging')
@click.pass_context
def cli(ctx, host, port, save, access_log):
ctx.obj = Server(host, port, save, access_log)

View file

@ -1,21 +1,3 @@
function merp() {
console.log('Merp!');
}
function toggle_all_details(state) {
const elements = document.getElementsByTagName('details');
for (let element of elements) {
if (state && !element.hasAttribute('open')) {
element.setAttribute('open', null);
} else if (!state && element.hasAttribute('open')) {
element.removeAttribute('open');
}
}
}
function fetch_saves() {
const saves = document.getElementById('saves');
@ -27,6 +9,7 @@ function fetch_saves() {
return resp.json();
}).then((data) => {
data.sort();
data.map((id) => {
fetch(`/api/save/${id}/html`).then((resp) => {
if (!resp.ok) {

View file

@ -6,10 +6,6 @@
%script type='application/javascript' src='/functions.js'
-block content
#save-buttons
%a.button onclick='toggle_all_details(true);' << Open
%a.button onclick='toggle_all_details(false);' << Close
#saves
%script

View file

@ -2,29 +2,34 @@
.name -> =save.name
%table.data
%tr.level
%td.key << Level
%td.value -> =save.level
%colgroup
%col style='width: max-content;'
%col style='width: auto;'
%tr.xp
%td.key << XP
%td.value -> =save.xp
%tbody
%tr.level
%td.key << Level
%td.value -> =save.level
%tr.money
%td.key << Money
%td.value -> =save.money
%tr.xp
%td.key << XP
%td.value -> =save.xp
%tr.eridium
%td.key << Eridium
%td.value -> =save.eridium
%tr.money
%td.key << Money
%td.value -> =save.money
%tr.readonly
%td.key << Read-Only
%td.value -> =save.readonly
%tr.eridium
%td.key << Eridium
%td.value -> =save.eridium
%tr.filename
%td.key << Filename
%td.value -> =save.filename
%tr.readonly
%td.key << Read-Only
%td.value -> =save.readonly
%tr.filename
%td.key << Filename
%td.value -> =save.filename
.buttons
%a.button onclick='update_save({{save.id}});' << Refresh

View file

@ -31,22 +31,16 @@ table {
color: var(--primary);
}
.save:not(:first-child) {
margin-top: 8px;
}
.save:not(:last-child) {
margin-bottom: 8px;
}
.save table {
width: 100%;
}
.save td {
background: var(--ui-background);
}
.save td {
padding: 5px;
}
.save .key {
white-space: nowrap;
font-weight: bold;
}

View file

@ -63,3 +63,6 @@ class Server(Application):
async def check_address_type(request):
if not Url.new(request.remote).is_address_type('private'):
raise Forbidden('Only private access allowed')
if request.path.startswith('/api') or request.path.endswith(('js', 'css')):
request.log = False

View file

@ -1,3 +1,4 @@
from izzylib import DotDict
from izzylib_http_async import View
from . import tpl_path
@ -39,7 +40,7 @@ class ApiList(View):
async def get(self, request, response):
save_list = [save.id for save in self.app.saves]
response.set_json(sorted(save_list))
response.set_json(save_list)
class ApiSave(View):
@ -52,11 +53,7 @@ class ApiSave(View):
except KeyError as e:
return response.set_json({'error': str(e)}, status=404)
data = save.props.to_dict()
data['filename'] = save.path.name
data['readonly'] = save.path.permissions()['user'] == 4
return response.set_json(data)
return response.set_json(parse_save(save))
class ApiSaveToggle(View):
@ -90,8 +87,14 @@ class ApiSaveHtml(View):
except KeyError as e:
return response.set_json({'error': str(e)}, status=404)
data = save.props.to_dict()
data['filename'] = save.path.name
data['readonly'] = str(save.path.permissions()['user'] == 4).lower()
return response.set_template('save.haml', {'save': parse_save(save)})
return response.set_template('save.haml', {'save': data})
def parse_save(save):
data = DotDict(save.props.to_dict())
data['xp'] = f'{data.xp:,d}'
data['money'] = f'${data.money:,d}'
data['filename'] = save.path.name
data['readonly'] = save.path.permissions()['user'] == 4
return data