summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Schuster <git@rationality.eu>2020-10-06 23:10:03 +0200
committerFlorian Pritz <bluewind@xinu.at>2020-10-07 14:53:09 +0200
commitc41bb16e376332dc353d0edbcdc75ded5cc0996e (patch)
tree1f8f3cd65ee2f11df3d649f3785107a121f78d7f
parent3260da2f55078d6a73729cbbe89ecbc4cd86fe89 (diff)
Support requesting ids of a minimum lengthv2.1.0
Uses the new 'minimum-id-length' post parameter to ensure minimum id lengths for created file and multipaste urls. Changes by Florian Pritz: - Raise required API version to 2.2.0 - Rename CLI option to from `--min-url-length` to `--min-id-length` and adjust documentation Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r--fb.13
-rwxr-xr-xfb.py15
2 files changed, 15 insertions, 3 deletions
diff --git a/fb.1 b/fb.1
index 56cb2d3..249a23d 100644
--- a/fb.1
+++ b/fb.1
@@ -92,6 +92,9 @@ always, but then creates a multipaste combining all of them. URLs starting with
the pastebin URL will have their ID extracted and will not be downloaded. Only
the multipaste URL will be displayed and copied to the clipboard. This option
is enabled automatically if multiple files are uploaded.
+.It Fl M Ar <length>, Fl -min-id-length Ar <length>
+Request the server to generate IDs of at least <length> characters. The minimum
+supported length are two characters.
.It Fl h, -help
Display a short help message.
.It Fl t, -tar
diff --git a/fb.py b/fb.py
index d6de696..94b021f 100755
--- a/fb.py
+++ b/fb.py
@@ -79,7 +79,7 @@ class APIException(Exception):
self.error_id = error_id
class CURLWrapper:
- def __init__(self, config):
+ def __init__(self, config, args):
c = pycurl.Curl()
c.setopt(c.USERAGENT, config['useragent'])
c.setopt(c.HTTPHEADER, [
@@ -91,6 +91,7 @@ class CURLWrapper:
c.setopt(c.VERBOSE, 1)
self.config = config
+ self.args = args
self.curl = c
self.post = []
self.progressBar = ProgressBar()
@@ -126,6 +127,9 @@ class CURLWrapper:
if len(files) > self.config["min_files_per_request_default"]:
self.getServerConfig()
+ if self.args.min_id_length:
+ self.post.append(("minimum-id-length", self.args.min_id_length))
+
for file in files:
if file.should_upload():
filesize = os.stat(file.path).st_size
@@ -195,6 +199,9 @@ class CURLWrapper:
self.curl.setopt(pycurl.POST, 1)
self.__add_post(data)
+ if self.args.min_id_length:
+ self.post.append(("minimum-id-length", self.args.min_id_length))
+
self.addAPIKey()
ret = self.perform()
self.post = []
@@ -441,7 +448,7 @@ class FBClient:
def parseConfig(self, file, ignoreMissing=False):
c = ConfigParser(file, ignoreMissing=ignoreMissing)
self.config = c.get_config()
- self.config["api_url"] = self.config["pastebin"]+"/api/v2.0.0"
+ self.config["api_url"] = self.config["pastebin"]+"/api/v2.2.0"
self.config["warnsize"] = 10*1024*1024
self.config["min_files_per_request_default"] = 5
self.config["min_variables_per_request_default"] = 20
@@ -490,6 +497,8 @@ class FBClient:
help="File name to use for upload when reading from stdin (default: stdin)")
upload_options.add_argument("-e", "--extension", default="", action="store",
help="extension for default highlighting (e.g. \"diff\")")
+ upload_options.add_argument("-M", "--min-id-length", default="", action="store",
+ help="minimum length for the generated ID in the paste url")
parser.add_argument("-c", "--compress", default=0, action="count",
help="Compress the file being uploaded with gz or xz if used 2 times. "
@@ -516,7 +525,7 @@ class FBClient:
self.config["debug"] = self.args.debug
- self.curlw = CURLWrapper(self.config)
+ self.curlw = CURLWrapper(self.config, self.args)
functions = {
self.modes.upload: self.upload,