made api/history/add easier to script
This commit is contained in:
parent
20ddbb1a1f
commit
68228294b0
2 changed files with 10 additions and 5 deletions
|
|
@ -614,19 +614,24 @@ class HttpAPI(Common):
|
||||||
|
|
||||||
preset = request.query.get("preset")
|
preset = request.query.get("preset")
|
||||||
if preset:
|
if preset:
|
||||||
exists = Presets.get_instance().get(preset)
|
exists = Presets.get_instance().get(name=preset)
|
||||||
if not exists:
|
if not exists:
|
||||||
return web.json_response(
|
return web.json_response(
|
||||||
data={"error": f"Preset '{preset}' does not exist."}, status=web.HTTPBadRequest.status_code
|
data={"status": False, "message": f"Preset '{preset}' does not exist."},
|
||||||
|
status=web.HTTPBadRequest.status_code,
|
||||||
)
|
)
|
||||||
data["preset"] = preset
|
data["preset"] = preset
|
||||||
|
|
||||||
try:
|
try:
|
||||||
status = await self.add(**self.format_item(data))
|
status = await self.add(**self.format_item(data))
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
return web.json_response(data={"error": str(e)}, status=web.HTTPBadRequest.status_code)
|
return web.json_response(data={"status": False, "message": str(e)}, status=web.HTTPBadRequest.status_code)
|
||||||
|
|
||||||
return web.json_response(data=status, status=web.HTTPOk.status_code, dumps=self.encoder.encode)
|
return web.json_response(
|
||||||
|
data={"status": True, "message": "URL added", "item": status},
|
||||||
|
status=web.HTTPOk.status_code,
|
||||||
|
dumps=self.encoder.encode,
|
||||||
|
)
|
||||||
|
|
||||||
@route("POST", "api/history")
|
@route("POST", "api/history")
|
||||||
async def history_item_add(self, request: Request) -> Response:
|
async def history_item_add(self, request: Request) -> Response:
|
||||||
|
|
|
||||||
|
|
@ -251,7 +251,7 @@ class Presets(metaclass=Singleton):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(self._file, "w") as f:
|
with open(self._file, "w") as f:
|
||||||
json.dump(obj=[preset.serialize() for preset in presets], fp=f, indent=4)
|
json.dump(obj=[preset.serialize() for preset in presets if preset.default is False], fp=f, indent=4)
|
||||||
|
|
||||||
LOG.info(f"Presets saved to '{self._file}'.")
|
LOG.info(f"Presets saved to '{self._file}'.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue