We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e0b65a0 commit de36187Copy full SHA for de36187
ctfcli/cli/media.py
@@ -1,5 +1,7 @@
1
import os
2
3
+import click
4
+
5
from ctfcli.core.api import API
6
from ctfcli.core.config import Config
7
@@ -53,3 +55,20 @@ def rm(self, path):
53
55
del config["media"][path]
54
56
with open(config.config_path, "w+") as f:
57
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