a
This commit is contained in:
parent
8629a2c9b8
commit
5f5c1f3c80
|
@ -1,3 +1,5 @@
|
|||
import sys
|
||||
|
||||
from izzylib import Path
|
||||
|
||||
try:
|
||||
|
@ -8,4 +10,7 @@ except ImportError:
|
|||
pass
|
||||
|
||||
|
||||
tpl_path = Path(__file__).resolve().parent.join('frontend')
|
||||
try:
|
||||
tpl_path = Path(sys._MEIPASS).join('frontend')
|
||||
except AttributeError:
|
||||
tpl_path = Path(__file__).resolve().parent.join('frontend')
|
||||
|
|
|
@ -13,6 +13,9 @@ from .watcher import SaveWatcher
|
|||
@click.option('--no-access-log', '-a', is_flag=True, default=True, help='Enable the server\'s access logging')
|
||||
@click.pass_context
|
||||
def cli(ctx, host, port, save, no_access_log):
|
||||
if save:
|
||||
save = save.expanduser().resolve()
|
||||
|
||||
ctx.obj = Server(host, port, save, no_access_log)
|
||||
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ function update_save(id) {
|
|||
save.getElementsByClassName('name')[0].innerHTML = data.name;
|
||||
|
||||
save.getElementsByClassName('level')[0]
|
||||
.getElementsByClassName('value')[0].innerHTML = data.name;
|
||||
.getElementsByClassName('value')[0].innerHTML = data.level;
|
||||
|
||||
save.getElementsByClassName('xp')[0]
|
||||
.getElementsByClassName('value')[0].innerHTML = data.xp;
|
||||
|
@ -54,7 +54,7 @@ function update_save(id) {
|
|||
.getElementsByClassName('value')[0].innerHTML = data.eridium;
|
||||
|
||||
save.getElementsByClassName('readonly')[0]
|
||||
.getElementsByClassName('value')[0].innerHTML = data.readonly;
|
||||
.getElementsByClassName('value')[0].innerHTML = data.readonly ? 'Yes' : 'No';
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ function toggle_readonly(id) {
|
|||
}).then((data) => {
|
||||
const save = document.getElementById(id)
|
||||
.getElementsByClassName('readonly')[0]
|
||||
.getElementsByClassName('value')[0].innerHTML = data.readonly;
|
||||
.getElementsByClassName('value')[0].innerHTML = data.readonly ? 'Yes' : 'No';
|
||||
|
||||
});
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
%tr.readonly
|
||||
%td.key << Read-Only
|
||||
%td.value -> =save.readonly
|
||||
%td.value << {{'Yes' if save.readonly else 'No'}}
|
||||
|
||||
%tr.filename
|
||||
%td.key << Filename
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import sys
|
||||
|
||||
from bl2_save_edit import Bl2Save
|
||||
from izzylib import Path, Url
|
||||
from izzylib_http_async import Application
|
||||
from izzylib_http_async.server.application import Application
|
||||
from izzylib_http_async.server.error import Forbidden
|
||||
|
||||
from . import views, tpl_path
|
||||
|
@ -9,7 +11,7 @@ from .functions import get_save_path
|
|||
|
||||
class Server(Application):
|
||||
def __init__(self, listen='0.0.0.0', port=8080, save_path=None, access_log=False):
|
||||
Application.__init__(self,
|
||||
options = dict(
|
||||
appname = 'bl2tools',
|
||||
name = 'BL2 Tools',
|
||||
title = 'BL2 Tools',
|
||||
|
@ -17,17 +19,17 @@ class Server(Application):
|
|||
git_repo = 'https://git.barkshark.xyz/izaliamae/bl2tools',
|
||||
listen = listen,
|
||||
port = port,
|
||||
tpl_search = [Path(__file__).resolve().parent.join('frontend')],
|
||||
access_log = access_log
|
||||
access_log = access_log,
|
||||
tpl_search = [tpl_path]
|
||||
)
|
||||
|
||||
if hasattr(sys, 'frozen'):
|
||||
options['frontend_path'] = Path(sys._MEIPASS).join('izzylib_frontend')
|
||||
|
||||
Application.__init__(self, **options)
|
||||
|
||||
self.saves = []
|
||||
|
||||
if save_path:
|
||||
self.save_path = Path(save_path).expanduser().resolve()
|
||||
|
||||
else:
|
||||
self.save_path = get_save_path()
|
||||
self.save_path = save_path or get_save_path()
|
||||
|
||||
## Frontend paths
|
||||
self.add_view(views.Home)
|
||||
|
|
|
@ -1,24 +1,42 @@
|
|||
from izzylib import DotDict
|
||||
from izzylib_http_async import View
|
||||
from izzylib_http_async.server.view import View
|
||||
|
||||
from . import tpl_path
|
||||
|
||||
|
||||
class Home(View):
|
||||
class BaseView(View):
|
||||
def get_save(self, saveid):
|
||||
try:
|
||||
save = self.app.get_save_by_id(saveid)
|
||||
|
||||
except KeyError as e:
|
||||
return response.set_json({'error': e}, status=404)
|
||||
|
||||
data = DotDict(save.props.to_dict())
|
||||
data['xp'] = f'{data.xp:,d}'
|
||||
data['money'] = f'${data.money:,d}'
|
||||
data['path'] = save.path
|
||||
data['filename'] = save.path.name
|
||||
data['readonly'] = save.path.permissions()['user'] == 4
|
||||
|
||||
return data
|
||||
|
||||
|
||||
class Home(BaseView):
|
||||
__path__ = ['/']
|
||||
|
||||
async def get(self, request, response):
|
||||
response.set_template('home.haml')
|
||||
|
||||
|
||||
class Style(View):
|
||||
class Style(BaseView):
|
||||
__path__ = ['/style.css']
|
||||
|
||||
async def get(self, request, response):
|
||||
response.set_template('style.css', content_type='text/css')
|
||||
|
||||
|
||||
class Javascript(View):
|
||||
class Javascript(BaseView):
|
||||
__path__ = ['/functions.js']
|
||||
jspath = tpl_path.join('functions.js')
|
||||
jsfile = None
|
||||
|
@ -35,7 +53,7 @@ class Javascript(View):
|
|||
response.content_type = 'application/javascript'
|
||||
|
||||
|
||||
class ApiList(View):
|
||||
class ApiList(BaseView):
|
||||
__path__ = ['/api/list']
|
||||
|
||||
async def get(self, request, response):
|
||||
|
@ -43,58 +61,30 @@ class ApiList(View):
|
|||
response.set_json(save_list)
|
||||
|
||||
|
||||
class ApiSave(View):
|
||||
class ApiSave(BaseView):
|
||||
__path__ = ['/api/save/{saveid:int}']
|
||||
|
||||
async def get(self, request, response, saveid):
|
||||
try:
|
||||
save = self.app.get_save_by_id(saveid)
|
||||
|
||||
except KeyError as e:
|
||||
return response.set_json({'error': str(e)}, status=404)
|
||||
|
||||
return response.set_json(parse_save(save))
|
||||
return response.set_json(self.get_save(saveid))
|
||||
|
||||
|
||||
class ApiSaveToggle(View):
|
||||
class ApiSaveToggle(BaseView):
|
||||
__path__ = ['/api/save/{saveid:int}/toggle']
|
||||
|
||||
async def get(self, request, response, saveid):
|
||||
try:
|
||||
save = self.app.get_save_by_id(saveid)
|
||||
save = self.get_save(saveid)
|
||||
|
||||
except KeyError as e:
|
||||
return response.set_json({'error': e}, status=404)
|
||||
|
||||
readonly = save.path.permissions()['user'] == 4
|
||||
|
||||
if readonly:
|
||||
if save.readonly:
|
||||
save.path.chmod(644)
|
||||
|
||||
else:
|
||||
save.path.chmod(444)
|
||||
|
||||
return response.set_json({'readonly': not readonly})
|
||||
return response.set_json({'readonly': not save.readonly})
|
||||
|
||||
|
||||
class ApiSaveHtml(View):
|
||||
class ApiSaveHtml(BaseView):
|
||||
__path__ = ['/api/save/{saveid:int}/html']
|
||||
|
||||
async def get(self, request, response, saveid):
|
||||
try:
|
||||
save = self.app.get_save_by_id(saveid)
|
||||
|
||||
except KeyError as e:
|
||||
return response.set_json({'error': str(e)}, status=404)
|
||||
|
||||
return response.set_template('save.haml', {'save': parse_save(save)})
|
||||
|
||||
|
||||
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
|
||||
return response.set_template('save.haml', {'save': self.get_save(saveid)})
|
||||
|
|
Loading…
Reference in a new issue