sachet-server/contrib/testcmds.fish

65 lines
2.3 KiB
Fish
Raw Permalink Normal View History

2023-04-26 19:52:31 -04:00
#!/bin/fish
# random httpie commands to mess around with
set -gx BASENAME localhost:5000
function sachet_init_db -d "initialize db"
flask --debug --app sachet.server user create --username admin --admin yes --password password123
flask --debug --app sachet.server user create --username user --admin no --password password123
end
function sachet_init_sess -d "initialize sessions in httpie"
set TOKEN (http post $BASENAME/users/login username=user password=password123 | jq -r .auth_token)
set ADMIN_TOKEN (http post $BASENAME/users/login username=admin password=password123 | jq -r .auth_token)
http --session=sachet-admin get $BASENAME/users/user Authorization:"Bearer $ADMIN_TOKEN"
http --session=sachet-user get $BASENAME/users/user Authorization:"Bearer $TOKEN"
end
function sachet_set_perms -d "setup permissions"
http --session=sachet-admin patch $BASENAME/users/user permissions:='["READ", "CREATE", "LIST", "DELETE"]'
end
2023-04-27 20:32:46 -04:00
function sachet_anon -d "setup anonymous user's permissions"
if test -z $argv
set argv '["READ", "CREATE", "LIST", "DELETE"]'
end
http --session=sachet-admin patch $BASENAME/admin/settings default_permissions:=$argv
end
2023-04-26 19:52:31 -04:00
function sachet_upload -d "uploads a file"
2023-04-27 20:32:46 -04:00
argparse 's/session=?' -- $argv
2023-04-26 20:51:13 -04:00
set FNAME (basename $argv)
2023-05-07 22:14:15 -04:00
set URL (http --session=$_flag_session post $BASENAME/files file_name=$FNAME | tee /dev/tty | jq -r .url)
http --session=$_flag_session -f post $BASENAME/$URL/content \
upload@$argv \
dzuuid=(cat /dev/urandom | base64 | head -c 32) \
2023-05-07 22:14:15 -04:00
dzchunkindex=0 \
dztotalchunks=1
2023-04-26 19:52:31 -04:00
end
function sachet_upload_meme -d "uploads a random meme"
2023-05-07 22:14:15 -04:00
argparse 's/session=?' -- $argv
2023-04-26 19:52:31 -04:00
set MEME ~/med/memes/woof/(ls ~/med/memes/woof | shuf | head -n 1)
2023-05-07 22:14:15 -04:00
sachet_upload -s$_flag_session $MEME
2023-04-26 19:52:31 -04:00
end
2023-04-26 20:51:13 -04:00
function sachet_list -d "lists files on a given page"
2023-04-27 20:32:46 -04:00
argparse 'P/per-page=!_validate_int' 's/session=?' -- $argv
2023-04-26 19:52:31 -04:00
if not set -q _flag_per_page
set _flag_per_page 5
end
http --session=$_flag_session get localhost:5000/files per_page==$_flag_per_page page==$argv[1]
2023-04-26 19:52:31 -04:00
end
function sachet_download -d "downloads a given file id"
2023-04-27 20:32:46 -04:00
argparse 's/session=?' -- $argv
http --session=$_flag_session -f -d get $BASENAME/files/$argv/content
2023-04-26 19:52:31 -04:00
end
2023-04-26 20:51:13 -04:00
function sachet_delete -d "delete given file ids"
2023-04-27 20:32:46 -04:00
argparse 's/session=?' -- $argv
2023-04-26 20:51:13 -04:00
for file in $argv
2023-04-27 20:32:46 -04:00
http --session=$_flag_session delete $BASENAME/files/$file
2023-04-26 20:51:13 -04:00
end
2023-04-26 19:52:31 -04:00
end