From 458ef670fdc786a8bffdf28b57b4b24f69920d0d Mon Sep 17 00:00:00 2001 From: simoniz0r Date: Sun, 19 Aug 2018 02:10:02 -0500 Subject: [PATCH] Clean up ascii escapes in uploads from stdin --- filebiner | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/filebiner b/filebiner index a5d8eb6..acdbcca 100755 --- a/filebiner +++ b/filebiner @@ -30,11 +30,16 @@ uploadfile() { if [[ ! "$UPLOAD_FILE" == "-" ]]; then # use readlink -f to find full path of UPLOAD_FILE UPLOAD_FILE="$(readlink -f "$UPLOAD_FILE")" - # exit if file doesn't exist - if [[ ! -f "$UPLOAD_FILE" ]]; then - echo "$UPLOAD_FILE not found!" - exit 1 - fi + else + rm -f /tmp/.filebinerpipe8845 + UPLOAD_FILE="/tmp/.filebinerpipe8845" + # get rid of ascii escapes when reading fron stdin + cat | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" > /tmp/.filebinerpipe8845 + fi + # exit if file doesn't exist + if [[ ! -f "$UPLOAD_FILE" ]]; then + echo "$UPLOAD_FILE not found!" + exit 1 fi # set BIN_NAME to $USER if empty if [[ -z "$BIN_NAME" ]]; then @@ -46,6 +51,7 @@ uploadfile() { fi if [[ $(echo "$BIN_NAME" | wc -m) -lt 9 ]]; then echo "Error using '$BIN_NAME' as bin name; bin name must be at least 8 characters in length." + rm -f /tmp/.filebinerpipe8845 exit 1 fi # if text being uploaded via pipe and FILE_NAME is empty, set random file name @@ -56,7 +62,8 @@ uploadfile() { FILE_NAME="$(echo "$UPLOAD_FILE" | rev | cut -f1 -d'/' | rev)" fi # upload UPLOAD_FILE to filebin.net - curl -s --data-binary "@$UPLOAD_FILE" -H "bin: $BIN_NAME" -H "filename: $FILE_NAME" https://filebin.net 2>&1 > /dev/null || { echo "Failed to upload $UPLOAD_FILE"; exit 1; } + curl -s --data-binary "@$UPLOAD_FILE" -H "bin: $BIN_NAME" -H "filename: $FILE_NAME" https://filebin.net 2>&1 > /dev/null || { echo "Failed to upload $UPLOAD_FILE"; rm -f /tmp/.filebinerpipe8845; exit 1; } + rm -f /tmp/.filebinerpipe8845 # find url of uploaded file using filebin.net's list of uploads to BIN_NAME UP_URL="$(curl -s -H "Accept: application/json" https://filebin.net/"$BIN_NAME" | grep ""$BIN_NAME"/"$FILE_NAME"" | cut -f4 -d'"' | head -n 1)" if [[ -z "$UP_URL" ]]; then @@ -225,7 +232,7 @@ deletefile() { } # show filebiner help filebinerhelp() { -printf "filebiner v0.0.3 - https://www.simonizor.net +printf "filebiner v0.0.4 - https://www.simonizor.net Uploads and manages files on https://filebin.net Usage: filebiner [subarguments]