mirror of
http://gitea.phreedom.club/localhost_frssoft/pleroma-cli
synced 2024-11-21 19:41:30 +00:00
upload
This commit is contained in:
commit
c1c6228ed4
7
LICENSE
Normal file
7
LICENSE
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
Copyright (c) 2022 localhost_frssoft
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
6
config.json
Normal file
6
config.json
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"instance": "soc.phreedom.club",
|
||||||
|
"max_statuses": 40,
|
||||||
|
"default_content_type": "text/markdown",
|
||||||
|
"default_visibility": "unlisted"
|
||||||
|
}
|
227
pleroma-cli.sh
Executable file
227
pleroma-cli.sh
Executable file
|
@ -0,0 +1,227 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
instance=$(jj -i config.json instance)
|
||||||
|
instance_point="https://$instance/api/v1"
|
||||||
|
instance_hist='instance.hist'
|
||||||
|
max_statuses=$(jj -i config.json max_statuses)
|
||||||
|
default_visibility=$(jj -i config.json default_visibility)
|
||||||
|
default_content_type=$(jj -i config.json default_content_type)
|
||||||
|
|
||||||
|
mkdir -m 711 -p .app_sessions
|
||||||
|
touch .auth.json
|
||||||
|
chmod 600 .auth.json
|
||||||
|
auth="$(jj -i .auth.json "$(echo $instance | sed 's/\./\\\./g')")"
|
||||||
|
echo "Instance: $instance"
|
||||||
|
if [ -n "$auth" ]; then
|
||||||
|
default_curl_opt()
|
||||||
|
{
|
||||||
|
curl -s --compressed -H "Authorization: Bearer $auth" $1
|
||||||
|
}
|
||||||
|
echo '+Authorized account+'
|
||||||
|
else
|
||||||
|
default_curl_opt()
|
||||||
|
{
|
||||||
|
curl -s --compressed $1
|
||||||
|
}
|
||||||
|
echo 'Please make auth and restart'
|
||||||
|
fi
|
||||||
|
|
||||||
|
auth_api_create_client()
|
||||||
|
{
|
||||||
|
curl -s --compressed --url $instance_point/apps \
|
||||||
|
--data-urlencode 'client_name=pleroma-cli' \
|
||||||
|
--data-urlencode 'redirect_uris=urn:ietf:wg:oauth:2.0:oob' \
|
||||||
|
--data-urlencode 'scopes=read write follow' \
|
||||||
|
--data-urlencode 'website=https://gitea.phreedom.club/localhost_frssoft/pleroma-cli' \
|
||||||
|
--output .app_sessions/$instance
|
||||||
|
chmod 600 .app_sessions/$instance
|
||||||
|
}
|
||||||
|
|
||||||
|
auth_api_get_code()
|
||||||
|
{
|
||||||
|
auth_api_create_client
|
||||||
|
client_id=$(jj -i .app_sessions/$instance client_id)
|
||||||
|
links "https://$instance/oauth/authorize?client_id=$client_id&response_type=code&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=read+write+follow"
|
||||||
|
echo 'Input token-code:'
|
||||||
|
read pass
|
||||||
|
}
|
||||||
|
|
||||||
|
auth_api_get_token()
|
||||||
|
{
|
||||||
|
auth_api_get_code
|
||||||
|
clear
|
||||||
|
client_id=$(jj -i .app_sessions/$instance client_id)
|
||||||
|
client_secret=$(jj -i .app_sessions/$instance client_secret)
|
||||||
|
token=$(curl -s --compressed --url https://$instance/oauth/token \
|
||||||
|
--data-urlencode 'grant_type=authorization_code' \
|
||||||
|
--data-urlencode "client_id=$client_id" \
|
||||||
|
--data-urlencode "client_secret=$client_secret" \
|
||||||
|
--data-urlencode "redirect_uri=urn:ietf:wg:oauth:2.0:oob" \
|
||||||
|
--data-urlencode 'scope=read write follow' \
|
||||||
|
--data-urlencode "code=$pass" | jj access_token)
|
||||||
|
jj -p -i .auth.json -v "$token" "$(echo $instance | sed 's/\./\\\./g')" -o .auth.json
|
||||||
|
}
|
||||||
|
|
||||||
|
timeline_api()
|
||||||
|
{
|
||||||
|
default_curl_opt "$instance_point/$timeline?limit=$max_statuses&max_id=$1" | tee preload
|
||||||
|
}
|
||||||
|
|
||||||
|
timeline_menu()
|
||||||
|
{
|
||||||
|
json=$(timeline_api)
|
||||||
|
indexator=$(expr $max_statuses - 1)
|
||||||
|
sub_menu_lvl=1
|
||||||
|
echo '#EXTM3U' > attachments.m3u8
|
||||||
|
while [ $sub_menu_lvl -eq 1 ]; do
|
||||||
|
|
||||||
|
while [ $indexator -gt 0 ]; do
|
||||||
|
status=$(echo $json | jj $indexator)
|
||||||
|
uri=$(echo $status | jj uri)
|
||||||
|
dateutc=$(echo $status | jj created_at)
|
||||||
|
echo "$(date -d $dateutc) <-> $uri"
|
||||||
|
echo $status | jj content | sed -e 's/<br[^>]*>/\n/g ; s/<[^>]*>//g ; s/>*/>/g ; s/<*/</g ; s/"/"/g'
|
||||||
|
attachments=$(echo $status | jj -l media_attachments.#.remote_url | sed 's/"//g')
|
||||||
|
if [ -n "$attachments" ]; then
|
||||||
|
echo "#EXTINF:-1, $uri" >> attachments.m3u8
|
||||||
|
echo "$attachments" >> attachments.m3u8
|
||||||
|
fi
|
||||||
|
indexator=$(expr $indexator - 1)
|
||||||
|
echo '_____'
|
||||||
|
done
|
||||||
|
indexator=$(expr $max_statuses - 1)
|
||||||
|
menu=$(echo 'Prev\nNext\nMain menu' | fzy)
|
||||||
|
case $menu in
|
||||||
|
"Prev")
|
||||||
|
echo '#EXTM3U' > attachments.m3u8
|
||||||
|
clear
|
||||||
|
offset=$(jj -i preload 39.id)
|
||||||
|
json=$(timeline_api $offset)
|
||||||
|
;;
|
||||||
|
"Next")
|
||||||
|
echo '#EXTM3U' > attachments.m3u8
|
||||||
|
clear
|
||||||
|
offset=$(jj -i preload 0.id)
|
||||||
|
json=$(timeline_api $offset)
|
||||||
|
;;
|
||||||
|
"Main menu")
|
||||||
|
sub_menu_lvl=0 ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
write_api_status()
|
||||||
|
{
|
||||||
|
curl -s --compressed -H "Authorization: Bearer $auth" --url $instance_point/statuses \
|
||||||
|
--data-urlencode "status=$1" \
|
||||||
|
--data-urlencode "content_type=$content_type" \
|
||||||
|
--data-urlencode "visibility=$status_visibility"
|
||||||
|
}
|
||||||
|
|
||||||
|
write_status_menu()
|
||||||
|
{
|
||||||
|
touch tmp_status.md
|
||||||
|
content_type="$default_content_type"
|
||||||
|
status_visibility="$default_visibility"
|
||||||
|
sub_menu_lvl=1
|
||||||
|
while [ $sub_menu_lvl -eq 1 ]; do
|
||||||
|
clear
|
||||||
|
echo 'Status:'
|
||||||
|
cat tmp_status.md
|
||||||
|
echo '\==========/'
|
||||||
|
echo "Chars: $(cat tmp_status.md | wc -m)"
|
||||||
|
echo "Visiblity: $status_visibility"
|
||||||
|
echo "Content type: $content_type"
|
||||||
|
wrirepostmenu=$(echo "Write\nSend\nChange type\nVisiblity\nMain menu" | fzy)
|
||||||
|
case $wrirepostmenu in
|
||||||
|
"Write") echo > tmp_status.md; $EDITOR tmp_status.md ;;
|
||||||
|
"Send") write_api_status "$(cat tmp_status.md)" | jj -p ;;
|
||||||
|
"Change type") content_type=$(echo 'text/plain\ntext/markdown\ntext/html' | fzy) ;;
|
||||||
|
"Visiblity")
|
||||||
|
status_visibility=$(echo 'public\nunlisted\nlocal\nprivate\ndirect\nlist' | fzy)
|
||||||
|
;;
|
||||||
|
"Main menu") sub_menu_lvl=0 ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
notif_api_get_all()
|
||||||
|
{
|
||||||
|
default_curl_opt "$instance_point/notifications" | jj -p
|
||||||
|
}
|
||||||
|
|
||||||
|
notif_api_remove_all()
|
||||||
|
{
|
||||||
|
curl -X POST --compressed -H "Authorization: Bearer $auth" --url $instance_point/notifications/clear
|
||||||
|
}
|
||||||
|
|
||||||
|
menu_write_status='Write status'
|
||||||
|
menu_timeline='Timelines'
|
||||||
|
notif='Notifications (raw)'
|
||||||
|
clrnotif='Clear all notifications'
|
||||||
|
authmake='Auth'
|
||||||
|
switchinstance='Switch instance'
|
||||||
|
Exit='Exit'
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
if [ -n "$auth" ]; then
|
||||||
|
main_menu=$(echo "$menu_write_status\n$menu_timeline\n$notif\n$clrnotif\n$switchinstance\n$Exit" | fzy)
|
||||||
|
else
|
||||||
|
main_menu=$(echo "$menu_write_status\n$menu_timeline\n$notif\n$clrnotif\n$authmake\n$switchinstance\n$Exit" | fzy)
|
||||||
|
fi
|
||||||
|
case $main_menu in
|
||||||
|
"$menu_write_status") write_status_menu ;;
|
||||||
|
"$menu_timeline")
|
||||||
|
timeline=$(echo 'timelines/home\nfavourites\ntimelines/direct\ntimelines/public' | fzy)
|
||||||
|
timeline_menu
|
||||||
|
;;
|
||||||
|
"$notif") notif_api_get_all | more ;;
|
||||||
|
"$clrnotif") notif_api_remove_all ;;
|
||||||
|
"$switchinstance")
|
||||||
|
empty=0
|
||||||
|
case $(echo 'Recently used\nChoice from list\nManual input' | fzy) in
|
||||||
|
"Recently used")
|
||||||
|
if [ -s $instance_hist ]; then
|
||||||
|
touch $instance_hist && instance=$(cat $instance_hist | fzy)
|
||||||
|
else
|
||||||
|
echo 'No recently used instances...'
|
||||||
|
empty=1
|
||||||
|
fi ;;
|
||||||
|
|
||||||
|
"Choice from list") instance=$(jj -l -i config.json public_list_instances | sed 's/"//g' | fzy) ;;
|
||||||
|
|
||||||
|
"Manual input") echo "Type instance (ex. $instance):" && read instance ;;
|
||||||
|
esac
|
||||||
|
if [ $empty -eq 0 ]; then
|
||||||
|
echo $instance >> $instance_hist
|
||||||
|
cat $instance_hist | sort | uniq | tee $instance_hist 1>>/dev/null
|
||||||
|
export instance
|
||||||
|
export instance_point="https://$instance/api/v1"
|
||||||
|
conf_instance_state=$(echo 'Permanent\nTemporaly' | fzy)
|
||||||
|
if [ "$conf_instance_state" = 'Permanent' ]; then
|
||||||
|
jj -i config.json instance -v $instance -o config.json
|
||||||
|
else
|
||||||
|
echo ''
|
||||||
|
fi
|
||||||
|
clear
|
||||||
|
auth="$(jj -i .auth.json "$(echo $instance | sed 's/\./\\\./g')")"
|
||||||
|
echo "Instance: $instance"
|
||||||
|
if [ -n "$auth" ]; then
|
||||||
|
default_curl_opt()
|
||||||
|
{
|
||||||
|
curl -s --compressed -H "Authorization: Bearer $auth" $1
|
||||||
|
}
|
||||||
|
echo '+Authorized account+'
|
||||||
|
else
|
||||||
|
default_curl_opt()
|
||||||
|
{
|
||||||
|
curl -s --compressed $1
|
||||||
|
}
|
||||||
|
echo 'Please make auth and restart'
|
||||||
|
fi
|
||||||
|
fi ;;
|
||||||
|
"$authmake") auth_api_get_token ;;
|
||||||
|
"$Exit") exit 0 ;;
|
||||||
|
esac
|
||||||
|
done
|
Loading…
Reference in a new issue