How to get “needFiles” on a remote device?
Assuming I have a local machine and a remote device (“server”) and I can get files that need to be updated on the local machine through the event FolderSummary (the “needFiles” can tell). What I also need is similarly how to determine the number of files that need to be upated on the “Server”. Thanks!
Rest API was the keyword I was missing
A list of needed files is available through the
/rest/db/remoteneed endpoint which is apparently undocumented and works just like
/rest/db/need just with an additional device parameter. If you’d care to document it, a PR would be highly welcome
In the document it says that “total” is included as the returned information. Unfortunately my test shows only: “page” “perpage” “progress” “sequence” “rest”
total seems not included?
Yes, that’s apparently also outdated documentation. You need to query without
perpage, then you get all needed items (and perpage is thus the total). But if you aren’t interested in the individual files, there’s a better endpoint (which has an
needItems field that isn’t in the docs either): https://docs.syncthing.net/rest/db-completion-get.html
It seems that this /rest/db/completion only works for remote device, but cannot be used to find the needItems for local machine?(my test showed it always return a large number and the actual needItems locally should be 0).
That might be a bug, where we do not translate the real local device ID given in the rest call to the internal local device ID - I don’t see why it shouldn’t work otherwise. Can’t check right now, you can test by giving the following device ID when querying completion:
7777777-777777N-7777777-777777N-7777777-777777N-7777777-77777Q4 and see whether it gives sensible results for local.
EDIT: Actually I’d expect it to fail then, not show a too large number, so I might be wrong.
OK. I will try the ID and report back when I have the result
Ok. After I changed the ID to be 7777777-777777N-7777777-777777N-7777777-777777N-7777777-77777Q4 in /rest/db/need, it seems that needItems return 0; not a large number anymore.
erhh, just noticed that you said querying in completion rather than /rest/db/need?
Yes, you were talking about db/completion in your last post and db/need has no device paramater. db/remoteneed does, but by definition it cannot give you the local results (that’s what db/need is for).
After a long day of testing, I am confusing myself— I need a cup of coffee to wake me up. Yes, I am talking /rest/db/completion; it does not work with local deviceID.
So, It seems that this is a bug? At this moment (before it is fixed), Can I use this 7777777-777777N-7777777-777777N-7777777-777777N-7777777-77777Q4 for querying local machine completion information?
(it seems that this is a “magic” ID?) Thanks a lot for your patience.
Yes, that’s magic aka internal. You shouldn’t ever have to use it, I just gave it to you for debugging, i.e. to establish whether it works at all. Actually it’s a bit unfair to let you do it, I could probably establish whether/how it works without much effort, I just really shouldn’t/can’t (? xD ) use time and I know for a fact that the rest interface (especially its documentation) has potential for improvement (and thus to eat time).
I am pretty sure you don’t need a magic id for local completion. Check how web ui does it.
Web ui gets it from folder summary events, it doesn’t query
db/completion for the local device.
Right, so that’s what the user should use.
Actually my first approach was using FolderSummary event to collect the information. However the test results showed that it is not always accurate (and sometimes it is not as frequent as we wanted).
Then I decided to look into /rest/db/completion.
I will give FolderSummary another try…