Manage the data cache with the last modified date
Currently the cache is persistent, once a file is downloaded and cached, it is never updated.
The idea here is to fetch the last modified date of a file on Nextcloud, compare it with the date of the cached file and only update the cache if necessary.
When you display the content of a directory on Nextcloud, the javascript in the webpage fetch an XML files formatted as this:
<d:multistatus xmlns:d="DAV:"
xmlns:s="http://sabredav.org/ns"
xmlns:oc="http://owncloud.org/ns"
xmlns:nc="http://nextcloud.org/ns">
<d:response>
<d:href>/public.php/webdav/</d:href>
<d:propstat>
<d:prop>
<d:getlastmodified>Tue, 30 Jan 2024 15:46:25 GMT</d:getlastmodified>
<d:getetag>"65b919d1847ee"</d:getetag>
<d:resourcetype>
<d:collection/>
</d:resourcetype>
<oc:fileid>94059696</oc:fileid>
<oc:permissions>RMG</oc:permissions>
<oc:size>21877340931</oc:size>
<d:quota-available-bytes>0</d:quota-available-bytes>
<nc:has-preview>false</nc:has-preview>
<nc:mount-type>external</nc:mount-type>
<nc:is-encrypted>0</nc:is-encrypted>
<nc:share-attributes>[]</nc:share-attributes>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
<d:propstat>
<d:prop>
<d:getcontenttype/>
<d:getcontentlength/>
<x1:share-permissions xmlns:x1="http://open-collaboration-services.org/ns"/>
</d:prop>
<d:status>HTTP/1.1 404 Not Found</d:status>
</d:propstat>
</d:response>
...
<d:response>
<d:href>/public.php/webdav/test.RDS</d:href>
<d:propstat>
<d:prop>
<d:getlastmodified>Mon, 29 Jan 2024 17:52:41 GMT</d:getlastmodified>
<d:getetag>""49263511c92d3095340908cbb0c30f6d-1""</d:getetag>
<d:getcontenttype>application/octet-stream</d:getcontenttype>
<d:resourcetype/>
<oc:fileid>123611282</oc:fileid>
<oc:permissions>RMG</oc:permissions>
<oc:size>148288540</oc:size>
<d:getcontentlength>148288540</d:getcontentlength>
<nc:has-preview>false</nc:has-preview>
<nc:mount-type>external</nc:mount-type>
<nc:share-attributes>[]</nc:share-attributes>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
<d:propstat>
<d:prop>
<d:quota-available-bytes/>
<nc:is-encrypted/>
<x1:share-permissions xmlns:x1="http://open-collaboration-services.org/ns"/>
</d:prop>
<d:status>HTTP/1.1 404 Not Found</d:status>
</d:propstat>
</d:response>
<d:response>
<d:href>/public.php/webdav/test.png</d:href>
<d:propstat>
<d:prop>
<d:getlastmodified>Mon, 29 Jan 2024 17:52:41 GMT</d:getlastmodified>
<d:getetag>""3c933f8c774ce7b963ad9ea84fb4214b""</d:getetag>
<d:getcontenttype>image/png</d:getcontenttype>
<d:resourcetype/>
<oc:fileid>117938340</oc:fileid>
<oc:permissions>RMG</oc:permissions>
<oc:size>109015</oc:size>
<d:getcontentlength>109015</d:getcontentlength>
<nc:has-preview>false</nc:has-preview>
<nc:mount-type>external</nc:mount-type>
<nc:share-attributes>[]</nc:share-attributes>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
<d:propstat>
<d:prop>
<d:quota-available-bytes/>
<nc:is-encrypted/>
<x1:share-permissions xmlns:x1="http://open-collaboration-services.org/ns"/>
</d:prop>
<d:status>HTTP/1.1 404 Not Found</d:status>
</d:propstat>
</d:response>
</d:multistatus>
To be able to fetch this file, one needs to catch the cookie produced during the fetch of the folder content page and transmit it with the request.