Skip to content

Commit

Permalink
Require that local file exists on remote when use ctf media url
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdHeat committed Aug 24, 2024
1 parent de36187 commit 01d4459
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions ctfcli/cli/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,22 @@ def rm(self, path):
def url(self, path):
"""Get server URL for a file key"""
config = Config()
api = API()

if config.config.has_section("media") is False:
config.config.add_section("media")

try:
location = config["media"][path]
except KeyError:
click.secho(f"Could not locate media '{path}'", fg="red")
click.secho(f"Could not locate local media '{path}'", fg="red")
return 1

base_url = config["config"]["url"]
base_url = base_url.rstrip("/")
return f"{base_url}{location}"
remote_files = api.get("/api/v1/files?type=page").json()["data"]
for remote_file in remote_files:
if f"/files/{remote_file['location']}" == location:
base_url = config["config"]["url"]
base_url = base_url.rstrip("/")
return f"{base_url}{location}"
click.secho(f"Could not locate remote media '{path}'", fg="red")
return 1

0 comments on commit 01d4459

Please sign in to comment.