Skip to content

Commit de36187

Browse files
committed
Add subcommand to get url for a media file
1 parent e0b65a0 commit de36187

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

ctfcli/cli/media.py

+19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import os
22

3+
import click
4+
35
from ctfcli.core.api import API
46
from ctfcli.core.config import Config
57

@@ -53,3 +55,20 @@ def rm(self, path):
5355
del config["media"][path]
5456
with open(config.config_path, "w+") as f:
5557
config.write(f)
58+
59+
def url(self, path):
60+
"""Get server URL for a file key"""
61+
config = Config()
62+
63+
if config.config.has_section("media") is False:
64+
config.config.add_section("media")
65+
66+
try:
67+
location = config["media"][path]
68+
except KeyError:
69+
click.secho(f"Could not locate media '{path}'", fg="red")
70+
return 1
71+
72+
base_url = config["config"]["url"]
73+
base_url = base_url.rstrip("/")
74+
return f"{base_url}{location}"

0 commit comments

Comments
 (0)