Add sidecar method to check if a file is present

This commit is contained in:
Johannes M. Scheuermann 2022-04-29 13:10:05 +01:00
parent 154de018ff
commit d1c71a7903
1 changed files with 11 additions and 1 deletions

View File

@ -518,10 +518,16 @@ class Server(BaseHTTPRequestHandler):
return
if self.path.startswith("/check_hash/"):
try:
self.send_text(check_hash(self.path[12:]), add_newline=False)
self.send_text(check_hash(os.path.basename(self.path)), add_newline=False)
except FileNotFoundError:
self.send_error(404, "Path not found")
self.end_headers()
if self.path.startswith("/is_present/"):
if is_present(os.path.basename(self.path))):
self.send_text("OK")
else:
self.send_error(404, "Path not found")
self.end_headers()
elif self.path == "/ready":
self.send_text(ready())
elif self.path == "/substitutions":
@ -599,6 +605,10 @@ def check_hash(filename):
return m.hexdigest()
def is_present(filename):
return os.path.exists(os.path.join(Config.shared().output_dir, filename))
def copy_files():
config = Config.shared()
if config.require_not_empty: