nakabonne / pbgopy

Copy and paste between devices
MIT License
807 stars 30 forks source link

Feat/lastupdated #16

Closed faithfulnessalamu closed 3 years ago

faithfulnessalamu commented 3 years ago

This PR is useful to extensions such as pbgopy-clip. Currently, the only way to tell if the server has new data is to compare the content at a time byte by byte with content at another time. This PR exposes a 'lastUpdated' endpoint for programs that want to sync data using pbgopy. It fits into the codebase well enough and has tests passing, but if you need to see it in action, I merged this PR on my pbgopy-diverge branch.

nakabonne commented 3 years ago

Nice tool! I gave it a try and pretty like it, but I'm not sure why this change is needed. Could you let me know what this endpoint gives us?

Also, I'm planning to support the built-in feature for putting the clipboard contents: https://github.com/nakabonne/pbgopy/issues/17

faithfulnessalamu commented 3 years ago

This PR exposes a new endpoint /lastupdated which returns the timestamp at which the server's cache was last updated. This is required for any program that needs to tell if the server has had new data since the last time they checked. Without this endpoint, the program would have to download all the content from the server everytime just to check if the server has had new data.

The timestamp is saved on the server's cache just like the data and salt, it is updated anytime there's a put to the server.

nakabonne commented 3 years ago

Thank you, I completely got what the /lastupdated endpoint does. Just curious about what use case actually needs this endpoint. Please let me know what case you use it in specifically 😃

faithfulnessalamu commented 3 years ago

Oh of course, pbgopy-clip needs to frequently check if there is new data on the server. If there's new data, it makes a GET request and puts it in the local clipboard. The timestamp is actually used for two different things in pbgopy-clip.

  1. To tell if the server has new data
  2. To tell which has the most recent data - the local clipboard or the server. If the local clipboard has the most recent change, the data on the server is overwritten in that case.
nakabonne commented 3 years ago

That makes sense. Okay, I don't mind merging this in that case.

faithfulnessalamu commented 3 years ago

Awesome, thanks!