From ad9cf023d2c853f833d6c9097b86360da55002a8 Mon Sep 17 00:00:00 2001 From: Jianhui Yuan Xu <107997665+NeumoNeumo@users.noreply.github.com> Date: Fri, 9 Aug 2024 23:39:02 +0800 Subject: [PATCH 1/3] Fix: encode URL in the bash client curl sometimes cannot work when encountering commands with special characters like `curl -s 'https://domain/filename with spaces.txt' > filename with spaces.txt` Before outputting the command, we need to encode the URL first. --- client/plik.sh | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/client/plik.sh b/client/plik.sh index 77b57e22..76d6ccb0 100755 --- a/client/plik.sh +++ b/client/plik.sh @@ -33,6 +33,27 @@ function setTtl() { esac return } +# The following snippet is modified from +# https://stackoverflow.com/a/10660730/17792535 +# Snippet Start +function rawURLEncode() { + local string="${1}" + local strlen=${#string} + local encoded="" + local pos c o + + for (( pos=0 ; pos Date: Wed, 21 Aug 2024 23:41:24 +0800 Subject: [PATCH 2/3] Fix: json parse error when `video` is in the json response --- client/plik.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client/plik.sh b/client/plik.sh index 76d6ccb0..7d3c21f0 100755 --- a/client/plik.sh +++ b/client/plik.sh @@ -12,8 +12,7 @@ set -e green='\e[0;32m' endColor='\e[0m' function jsonValue() { - KEY=$1 - sed -e "s/,/\n/g" | sed -e "s/[\"{}]//g" | grep $KEY | cut -d ":" -f2- + echo $(cat | sed -n "s/.*\"$1\":\"\([^\"]*\)\".*/\1/p") } function qecho(){ From 54a6aadb01f781136055d936cb8e4caa68fa89d1 Mon Sep 17 00:00:00 2001 From: Jianhui Yuan Xu <107997665+NeumoNeumo@users.noreply.github.com> Date: Wed, 6 Nov 2024 14:10:45 +0800 Subject: [PATCH 3/3] Fix: URL encoding of Unicode --- client/plik.sh | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/client/plik.sh b/client/plik.sh index 7d3c21f0..a179640b 100755 --- a/client/plik.sh +++ b/client/plik.sh @@ -32,10 +32,8 @@ function setTtl() { esac return } -# The following snippet is modified from -# https://stackoverflow.com/a/10660730/17792535 -# Snippet Start -function rawURLEncode() { + +function rawurlencode() { local string="${1}" local strlen=${#string} local encoded="" @@ -45,14 +43,12 @@ function rawURLEncode() { c=${string:$pos:1} case "$c" in [-_.~a-zA-Z0-9:/] ) o="${c}" ;; - * ) printf -v o '%%%02x' "'$c" + * ) o=$(printf "$c" | hexdump -e '/1 "%02X\n"' | tr '\n' '%' | sed 's/^/%/; s/.$//') esac encoded+="${o}" done - echo "${encoded}" # You can either set a return variable (FASTER) - REPLY="${encoded}" #+or echo the result (EASIER)... or both... :p + echo "${encoded}" } -# Snippet End # ## Vars @@ -64,7 +60,7 @@ PASSPHRASE="" ARCHIVE=false ONESHOT=false REMOVABLE=false -TTL=0 +TTL=604800 # a week # ## Read ~/.plikrc file @@ -243,7 +239,7 @@ do FILE_URL="$DOWNLOAD_DOMAIN/file/$UPLOAD_ID/$FILE_ID/$FILE_NAME" # Compute get command - rawURLEncode "$FILE_URL" + REPLY=$(rawurlencode "$FILE_URL") COMMAND="curl -s '$REPLY'" if [ "$SECURE" == true ]; then @@ -251,7 +247,7 @@ do fi if [ "$ARCHIVE" == true ]; then - COMMAND+=" | tar zxvf -" + COMMAND+=" | tar zxf -" else COMMAND+=" > '$FILE_NAME'" fi @@ -262,5 +258,6 @@ do else echo "$COMMAND" fi + echo -n "$PLIK_URL/#/?id=$UPLOAD_ID" done qecho