getting there

This commit is contained in:
Q
2023-08-19 19:42:31 +03:00
parent bdacb80c43
commit cfee5287d5
9 changed files with 332 additions and 254 deletions

View File

@@ -65,7 +65,7 @@ _qCol() {
}
cont() {
_cont() {
set +x
_qCol G
echo Continue
@@ -76,6 +76,13 @@ cont() {
_qCol z
set -x
}
_title() {
_qCol G
echo "$1"
_qCol Y
echo =========================================
_qCol z
}
set -e
@@ -86,82 +93,184 @@ SMALL="small file"
SMALLS="small_file"
IMAGE="image.jpg"
test -f "$BIG" || dd if=/dev/zero of="$BIG" bs=8192 count=40000
test -f "$SMALL" ||dd if=/dev/urandom of="$SMALL" bs=4096 count=400
test -f "$IMAGE" || convert -size 640x480 xc:gray $IMAGE
set -x
#~ cont
ROOTURL="http://localhost:8136"
. ../.env
if false; then
pv "$IMAGE" | \
curl -fL -w "\n" -F file="@-" -X POST \
-H "Name: $IMAGE" \
-H "Max-Downloads: 4" \
-H "Expires-Days: 14" \
-H "Secret: dff789f0bbe8183d3254258b33a147d580c1131f39a698c56d3f640ac8415714" \
"$ROOTURL"/upload
fi
function t00-rebuild-docker() {
CWD=$PWD
cd ..
docker-compose up --build -d --force-recreate
cd "$CWD"
}
if false; then
pv "$SMALL" | \
curl -fL -w "\n" -F file="@-" -X POST \
-H "Name: $SMALL" \
-H "Max-Downloads: 4000" \
-H "Expires-Days: 14" \
-H "Secret: dff789f0bbe8183d3254258b33a147d580c1131f39a698c56d3f640ac8415714" \
"$ROOTURL"/upload
function t01-maintenance-begin() {
curl -fL -w "\n" \
-H "Secret: $FLASK_ACCESS_TOKEN" \
"$FLASK_PUBLIC_URL"/maintenance
}
pv "$BIG" | \
curl -fL -w "\n" -F file="@-" -X POST \
-H "Name: $BIG" \
-H "Max-Downloads: 4000" \
-H "Expires-Days: 14" \
-H "Secret: dff789f0bbe8183d3254258b33a147d580c1131f39a698c56d3f640ac8415714" \
"$ROOTURL"/upload
fi
function t02-upload-small-image() {
sqlite3 ../data/flees.db "select * FROM files"
pv "$IMAGE" | \
curl -fL -w "\n" -F file="@-" -X POST \
-H "Name: $IMAGE" \
-H "Max-Downloads: 4" \
-H "Expires-Days: 1" \
-H "Secret: $FLASK_ACCESS_TOKEN" \
"$FLASK_PUBLIC_URL"/upload
}
if false; then
curl -fL -w "\n" \
-H "Secret: dff789f0bbe8183d3254258b33a147d580c1131f39a698c56d3f640ac8415714" \
"$ROOTURL"/details/OdD7X0aKOGM/big_file1.ext
function t03-upload-small-file() {
pv "$SMALL" | \
curl -fL -w "\n" -F file="@-" -X POST \
-H "Name: $SMALL" \
-H "Secret: $FLASK_ACCESS_TOKEN" \
"$FLASK_PUBLIC_URL"/upload
fi
}
if false; then
rm -f big_file1.ext
wget \
"$ROOTURL"/dl/OdD7X0aKOGM/big_file1.ext
fi
function t04-upload-large-file() {
pv "$BIG" | \
curl -fL -w "\n" -F file="@-" -X POST \
-H "Name: $BIG" \
-H "Max-Downloads: 4" \
-H "Expires-Days: 1" \
-H "Secret: $FLASK_ACCESS_TOKEN" \
"$FLASK_PUBLIC_URL"/upload
}
if false; then
function t05-check-db-manually() {
sqlite3 ../data/flees.db "select * FROM files"
}
function t06-list-files() {
curl -fL -w "\n" \
-H "Secret: $FLASK_ACCESS_TOKEN" \
"$FLASK_PUBLIC_URL"/ls
}
function t07-file-download() {
download_url=$( curl -fL -w "\n" \
-H "Secret: $FLASK_ACCESS_TOKEN" \
"$FLASK_PUBLIC_URL"/ls | grep "$BIGS" | tail -n 1 | sed s,.*http,http, )
rm -f "$BIGS"
wget "$download_url"
}
function t08-file-details() {
download_url=$( curl -fL -w "\n" \
-H "Secret: $FLASK_ACCESS_TOKEN" \
"$FLASK_PUBLIC_URL"/ls | grep "$BIGS" | tail -n 1 | sed s,.*http,http, )
token_name=$( echo $download_url | sed s,.*/dl/,, )
curl -fL -w "\n" \
-H "Secret: $FLASK_ACCESS_TOKEN" \
"$FLASK_PUBLIC_URL"/details/"$token_name"
}
function t09-file-delete() {
download_url=$( curl -fL -w "\n" \
-H "Secret: $FLASK_ACCESS_TOKEN" \
"$FLASK_PUBLIC_URL"/ls | grep "$BIGS" | tail -n 1 | sed s,.*http,http, )
token_name=$( echo $download_url | sed s,.*/dl/,, )
curl -fL -w "\n" \
-H "Secret: $FLASK_ACCESS_TOKEN" \
"$FLASK_PUBLIC_URL"/delete/"$token_name"
}
function t09-unlimited-downloads() {
pv "$SMALL" | \
curl -fL -w "\n" -F file="@-" -X POST \
-H "Name: $SMALL" \
-H "Max-Downloads: -1" \
-H "Expires-Days: 1" \
-H "Secret: $FLASK_ACCESS_TOKEN" \
"$FLASK_PUBLIC_URL"/upload
download_url=$( curl -fL -w "\n" \
-H "Secret: $FLASK_ACCESS_TOKEN" \
"$FLASK_PUBLIC_URL"/ls | grep "$SMALLS" | tail -n 1 | sed s,.*http,http, )
token_name=$( echo $download_url | sed s,.*/dl/,, )
for ((i=0;i<10;i++)); do
curl -fL -w "\n" \
-H "Secret: dff789f0bbe8183d3254258b33a147d580c1131f39a698c56d3f640ac8415714" \
"$ROOTURL"/delete/SKDMsQ3ifx8/image.jpg
fi
if true; then
-H "Secret: $FLASK_ACCESS_TOKEN" \
"$FLASK_PUBLIC_URL"/dl/"$token_name" > /dev/null
curl -fL -w "\n" \
-H "Secret: dff789f0bbe8183d3254258b33a147d580c1131f39a698c56d3f640ac8415714" \
"$ROOTURL"/ls
fi
-H "Secret: $FLASK_ACCESS_TOKEN" \
"$FLASK_PUBLIC_URL"/details/"$token_name"
done
}
if true; then
pv "$SMALL" | \
curl -fL -w "\n" -F file="@-" -X POST \
-H "Name: $SMALL" \
-H "Max-Downloads: 4000" \
-H "Expires-Days: -5" \
-H "Secret: dff789f0bbe8183d3254258b33a147d580c1131f39a698c56d3f640ac8415714" \
"$ROOTURL"/upload
function t10-maintenance-post() {
pv "$SMALL" | \
curl -fL -w "\n" -F file="@-" -X POST \
-H "Name: $SMALL" \
-H "Max-Downloads: 4" \
-H "Expires-Days: -5" \
-H "Secret: $FLASK_ACCESS_TOKEN" \
"$FLASK_PUBLIC_URL"/upload
pv "$SMALL" | \
curl -fL -w "\n" -F file="@-" -X POST \
-H "Name: $SMALL" \
-H "Max-Downloads: 0" \
-H "Expires-Days: 3" \
-H "Secret: $FLASK_ACCESS_TOKEN" \
"$FLASK_PUBLIC_URL"/upload
curl -fL -w "\n" \
-H "Secret: $FLASK_ACCESS_TOKEN" \
"$FLASK_PUBLIC_URL"/maintenance
curl -fL -w "\n" \
-H "Secret: $FLASK_ACCESS_TOKEN" \
"$FLASK_PUBLIC_URL"/ls
}
_getlist() {
declare -F | awk '{ print $3 }' | grep -v ^_
echo exit
}
_getnext() {
hitfound=0
for line in $( _getlist ); do
if [[ $hitfound -eq 1 ]]; then
echo "$line"
return
fi
if [[ "$line" = "$1" ]]; then
hitfound=1
fi
done
}
curl -fL -w "\n" \
-H "Secret: dff789f0bbe8183d3254258b33a147d580c1131f39a698c56d3f640ac8415714" \
"$ROOTURL"/maintenance
fi
_getchoice() {
_getlist | \
smenu -m "Pick task" -n 20 -t 1 -a c:2,b m:3,b -s '/'$1
}
next_task=0
while true; do
choice=$( _getchoice $next_task )
if [[ -z "$choice" ]]; then break; fi
_title "$choice"
set -x
"$choice"
set +x
_title ""
#~ next_task=$(( next_task + 1 ))
next_task=$( _getnext "$choice" )
done