feat(lander): store filename if provided

This commit is contained in:
Jef Roosens 2023-11-12 16:13:54 +01:00
parent 04aef2643f
commit 6a5b23afaa
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
6 changed files with 71 additions and 95 deletions

View file

@ -3,53 +3,49 @@
API_KEY=test
URL=http://localhost:18080
if [[ "$2" != '-' ]]; then
filename="$2"
content_type="$(file --mime-type --brief $2)"
fi
if [ "$1" = g ]; then
curl -is "$URL/$2" |
sed -En 's/^[lL]ocation: (.*)/\1/p'
elif [ "$1" = s ]; then
elif [ "$1" = s ] || [ "$1" = sl ]; then
curl \
--fail \
-w "${URL}%header{location}" \
-XPOST \
-d "$2" \
-H "X-Api-Key: $API_KEY" \
"$URL/s/$3"
"$URL/$1/$3"
elif [ "$1" = sl ]; then
curl \
-w "${URL}%header{location}" \
-XPOST \
-d "$2" \
-H "X-Api-Key: $API_KEY" \
"$URL/sl/$3"
elif [ "$1" = p ]; then
elif [ "$1" = p ] || [ "$1" = pl ]; then
curl \
--fail \
-w "${URL}%header{location}" \
-XPOST \
-H "X-Api-Key: $API_KEY" \
-H "X-Lander-Filename: ${filename}" \
--data-binary @"$2" \
"$URL/p/$3"
"$URL/$1/$3"
elif [ "$1" = pl ]; then
elif [ "$1" = f ] || [ "$1" = fl ]; then
curl \
--fail \
-w "${URL}%header{location}" \
-XPOST \
-H "X-Api-Key: $API_KEY" \
-H "X-Lander-Content-Type: ${content_type}" \
-H "X-Lander-Filename: ${filename}" \
--data-binary @"$2" \
"$URL/pl/$3"
elif [ "$1" = f ]; then
curl \
-w "${URL}%header{location}" \
-XPOST \
-H "X-Api-Key: $API_KEY" \
-H "X-Lander-Content-Type: $(file --mime-type --brief $2)" \
--data-binary @"$2" \
"$URL/f/$3"
"$URL/$1/$3"
elif [ "$1" = d ]; then
curl \
--fail \
-XDELETE \
-H "X-Api-Key: $API_KEY" \
"$URL/$2"