Skip to content

Commit 01d4459

Browse files
committed
Require that local file exists on remote when use ctf media url
1 parent de36187 commit 01d4459

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

ctfcli/cli/media.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,22 @@ def rm(self, path):
5959
def url(self, path):
6060
"""Get server URL for a file key"""
6161
config = Config()
62+
api = API()
6263

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

6667
try:
6768
location = config["media"][path]
6869
except KeyError:
69-
click.secho(f"Could not locate media '{path}'", fg="red")
70+
click.secho(f"Could not locate local media '{path}'", fg="red")
7071
return 1
7172

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

0 commit comments

Comments
 (0)