allow localhost and fix save id on load

This commit is contained in:
Izalia Mae 2022-04-23 09:42:07 -04:00
parent 5f5c1f3c80
commit 84f7007541
2 changed files with 14 additions and 4 deletions

View file

@ -1,7 +1,7 @@
import sys
from bl2_save_edit import Bl2Save
from izzylib import Path, Url
from izzylib import Path, Url, logging
from izzylib_http_async.server.application import Application
from izzylib_http_async.server.error import Forbidden
@ -61,6 +61,16 @@ class Server(Application):
save = Bl2Save(path)
try:
save_id = int(save.path.stem[4:], 16)
if save_id != save.id:
logging.warning('Save ID does not match savefile:', repr(save))
save.id = save_id
except ValueError:
pass
if int(save.path.permissions()) not in [644, 444]:
save.path.chmod(644)
@ -68,7 +78,7 @@ class Server(Application):
async def check_address_type(request):
if not Url.new(request.remote).is_address_type('private'):
if not any([request.remote.private, request.remote.loopback]):
raise Forbidden('Only private access allowed')
if request.path.startswith('/api') or request.path.endswith(('js', 'css')):

View file

@ -57,8 +57,8 @@ class ApiList(BaseView):
__path__ = ['/api/list']
async def get(self, request, response):
save_list = [save.id for save in self.app.saves]
response.set_json(save_list)
save_list = {save.id for save in self.app.saves}
response.set_json(list(save_list))
class ApiSave(BaseView):