forked from finn/tinyboard
syncthing.sh: add ignored folder display and un-ignore option to pending folders menu
This commit is contained in:
64
syncthing.sh
64
syncthing.sh
@@ -84,6 +84,59 @@ for device_id, info in devices.items():
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
show_ignored_folders() {
|
||||||
|
local config
|
||||||
|
config=$(st_get /rest/config)
|
||||||
|
local ignored
|
||||||
|
ignored=$(echo "$config" | python3 -c '
|
||||||
|
import sys,json
|
||||||
|
d=json.load(sys.stdin)
|
||||||
|
folders = d.get("ignoredFolders", [])
|
||||||
|
for f in folders:
|
||||||
|
print(f.get("id","?") + " — " + f.get("label","(no label)"))
|
||||||
|
' 2>/dev/null || true)
|
||||||
|
if [ -z "$ignored" ]; then
|
||||||
|
info "No ignored folders."
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
warn "Ignored folders (click Ignore in WUI causes this):"
|
||||||
|
echo "$ignored" | sed 's/^/ /'
|
||||||
|
echo ""
|
||||||
|
read -rp "Un-ignore a folder? [y/N]: " UNIGNORE
|
||||||
|
UNIGNORE="${UNIGNORE:-n}"
|
||||||
|
if [[ "${UNIGNORE,,}" != "y" ]]; then return; fi
|
||||||
|
|
||||||
|
local folder_ids
|
||||||
|
folder_ids=$(echo "$config" | python3 -c '
|
||||||
|
import sys,json
|
||||||
|
d=json.load(sys.stdin)
|
||||||
|
for f in d.get("ignoredFolders",[]):
|
||||||
|
print(f.get("id",""))
|
||||||
|
' 2>/dev/null || true)
|
||||||
|
|
||||||
|
echo "Ignored folder IDs:"
|
||||||
|
local i=1
|
||||||
|
while IFS= read -r fid; do
|
||||||
|
echo " $i) $fid"
|
||||||
|
i=$((i+1))
|
||||||
|
done <<< "$folder_ids"
|
||||||
|
read -rp "Choose folder number to un-ignore: " CHOICE
|
||||||
|
local TARGET_ID
|
||||||
|
TARGET_ID=$(echo "$folder_ids" | sed -n "${CHOICE}p")
|
||||||
|
[ -n "$TARGET_ID" ] || { warn "Invalid choice."; return; }
|
||||||
|
|
||||||
|
local new_config
|
||||||
|
new_config=$(echo "$config" | python3 -c "
|
||||||
|
import sys,json
|
||||||
|
d=json.load(sys.stdin)
|
||||||
|
d['ignoredFolders'] = [f for f in d.get('ignoredFolders',[]) if f.get('id') != sys.argv[1]]
|
||||||
|
print(json.dumps(d))
|
||||||
|
" "$TARGET_ID")
|
||||||
|
st_put /rest/config "$new_config"
|
||||||
|
info "Folder $TARGET_ID removed from ignored list. It should now appear as pending."
|
||||||
|
}
|
||||||
|
|
||||||
show_pending_folders() {
|
show_pending_folders() {
|
||||||
header "Pending Folders"
|
header "Pending Folders"
|
||||||
local pending
|
local pending
|
||||||
@@ -92,6 +145,11 @@ show_pending_folders() {
|
|||||||
count=$(echo "$pending" | python3 -c 'import sys,json; d=json.load(sys.stdin); print(len(d))')
|
count=$(echo "$pending" | python3 -c 'import sys,json; d=json.load(sys.stdin); print(len(d))')
|
||||||
if [ "$count" -eq 0 ]; then
|
if [ "$count" -eq 0 ]; then
|
||||||
warn "No pending folders."
|
warn "No pending folders."
|
||||||
|
echo ""
|
||||||
|
read -rp "Check ignored folders? [y/N]: " CHECK_IGNORED
|
||||||
|
if [[ "${CHECK_IGNORED,,}" == "y" ]]; then
|
||||||
|
show_ignored_folders
|
||||||
|
fi
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
echo "$pending" | python3 -c '
|
echo "$pending" | python3 -c '
|
||||||
@@ -103,8 +161,12 @@ for fid,info in d.items():
|
|||||||
print(f" Offered by: {offered_by}")
|
print(f" Offered by: {offered_by}")
|
||||||
print("")
|
print("")
|
||||||
'
|
'
|
||||||
read -rp "Accept a pending folder? [y/N]: " ACCEPT
|
read -rp "Accept a pending folder? [y/N/R (retry/check ignored)]: " ACCEPT
|
||||||
ACCEPT="${ACCEPT:-n}"
|
ACCEPT="${ACCEPT:-n}"
|
||||||
|
if [[ "${ACCEPT,,}" == "r" ]]; then
|
||||||
|
show_ignored_folders
|
||||||
|
return
|
||||||
|
fi
|
||||||
if [[ "${ACCEPT,,}" != "y" ]]; then return; fi
|
if [[ "${ACCEPT,,}" != "y" ]]; then return; fi
|
||||||
|
|
||||||
local folder_ids
|
local folder_ids
|
||||||
|
|||||||
Reference in New Issue
Block a user