Skip to content

Commit

Permalink
Clean up ascii escapes in uploads from stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
simoniz0r committed Aug 19, 2018
1 parent b1c4bc4 commit 458ef67
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions filebiner
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 <argument> [subarguments]
Expand Down

0 comments on commit 458ef67

Please sign in to comment.