From f99e5be0ca1895c97f7668ac5af7b6245e6239e8 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Sun, 4 Jul 2021 19:42:20 +0200 Subject: [PATCH] bin: rework syncthing api script --- .local/bin/scripts/st | 18 ++++++++++++++++++ .local/bin/scripts/synct | 9 --------- 2 files changed, 18 insertions(+), 9 deletions(-) create mode 100755 .local/bin/scripts/st delete mode 100755 .local/bin/scripts/synct diff --git a/.local/bin/scripts/st b/.local/bin/scripts/st new file mode 100755 index 0000000..bc0e111 --- /dev/null +++ b/.local/bin/scripts/st @@ -0,0 +1,18 @@ +#!/bin/sh +# Query local syncthing REST API +subscript="$(which "$(basename $0)-$1" 2>/dev/null)" +if test -f "$subscript" +then shift && $subscript "$@" +else + apikey=$(grep apikey $XDG_CONFIG_HOME/syncthing/config.xml | cut -d '>' -f2 | cut -d '<' -f1) + case "$1" in + (browse|need) + for arg in "${@:2}" + do case "$arg" in ([0-9]) depth=$arg;; (*) path="$arg";; esac + done + query="db/$1?folder=$(test -n "$path" && echo "${path%%/*}" || echo "data")&levels=${depth:-1}$(case "$path" in (*/*) echo "&prefix=${path#*/}";; esac)";; + (*) query="$1";; + esac + shift + curl --silent -H 'Content-Type: application/json' -H "X-API-Key: $apikey" "http://localhost:8384/rest/$query" "$@" | bat --style=numbers -l json +fi diff --git a/.local/bin/scripts/synct b/.local/bin/scripts/synct deleted file mode 100755 index 5c75c7f..0000000 --- a/.local/bin/scripts/synct +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -apikey=$(grep apikey $XDG_CONFIG_HOME/syncthing/config.xml | cut -d '>' -f2 | cut -d '<' -f1) -curl -H 'Content-Type: application/json' -H "X-API-Key: $apikey" "http://localhost:8384/rest/$1" "${@:2}" | bat --style=numbers -l json - -# https://docs.syncthing.net/rest/db-browse-get.html -# synct 'db/browse?folder=data&levels=1' - -# https://docs.syncthing.net/rest/db-need-get.html -# synct 'db/need?folder=music'