Motivation: creating Dropbox shared private links with the expiry time
Problems: file on Dropbox only has one valid shared private link
Solution:
a. Administrator
While choosing the file for the downloadable WooCommerce product, Dropbox will generate a “direct” link type. There are two kinds of the link are “direct” and “preview”. (Link types – https://www.dropbox.com/developers/chooser).
b. Customer
When the customer clicks on the WooCommerce download link, the request is handled by PDA Dropbox Integration plugin. It will ask the Dropbox whether this file has a shared link. If there is no existing one, a new shared link is created by Dropbox. Otherwise, it will check the link’s validation by the formula:
current_time <= time_to_expiry – x seconds
x is a pre-defined number of seconds to prevent the race condition.
If the link is invalid, the plugin will ask Dropbox to delete the invalid shared link and create a new one. On the other hand, the shared link is returned from Dropbox.
After all, Woo will receive the shared link and return the content to the customer.
c. Race condition
We have Product A with the file im-the-file.pdf on Dropbox without the shared link. Son is the first customer ordering the Product A, the plugin will give him the first shared link from 14:01:00 to 14:02:00. At 14:54:00, Dung is the second one purchasing the Product A. Dung only has 6 seconds for the request to reach Dropbox which is quite risky and not fair to Dung. That’s a reason why we stole x seconds from Son and give it to Dung. Now, Dung has 6 + x seconds to reach the Dropbox file.
By default, x is 5 seconds.
d. Notes:
+ Customer cannot download the file in the Dropbox UI when the shared link is expired.
+ It takes 3 seconds to enable the Download URL button for the next click.