Last active
January 30, 2017 16:11
-
-
Save siers/cb5d2accf2de923111934c6b871c48ef to your computer and use it in GitHub Desktop.
Print all files synchronized with syncthing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'json' | |
if ARGV.length == 0 | |
puts "usage: $0 '?folder=$FOLDERID'" | |
exit | |
end | |
key = %x{grep -Po '(?<=<apikey>)[^<]+' ~/.config/syncthing/config.xml}.strip | |
url = "http://localhost:8384/rest/db/browse#{ ARGV[0] }" | |
cmd = %{curl -sH "X-API-Key: #{ key }" "#{ url }"} | |
puts "In a second, going to request:\n#{ cmd }" | |
sleep 1 | |
def print_files(hash, prefix='') | |
hash.each do |name, contents| | |
if contents.is_a? Hash | |
print_files contents, "#{ prefix }#{ name }/" | |
else | |
puts "#{ prefix }#{ name }" | |
end | |
end | |
end | |
print_files(JSON.parse(%x{#{ cmd }})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pass "?folder=FOLDERID" in arguments.