owncloud / owncloud-sdk

:cloud: ownCloud client library for JavaScript
https://owncloud.dev/owncloud-sdk/
MIT License
75 stars 33 forks source link

fetch shares using json instead of XML #1147

Open butonic opened 2 years ago

butonic commented 2 years ago

We should use JSON to fetch shares instead of XML. With hundreds of shares (in this case 500) the savings become noticeable:

vscode ➜ ~/repositories/reva (prefer-return-minimal ✗) $ curl -k https://cloud.ocis.test/ocs/v1.php/apps/files_sharing/api/v1/shares\?include_tags\=false\&state\=all\&shared_with_me\=true -u marie:radioactivity | wc -c
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  719k    0  719k    0     0  65986      0 --:--:--  0:00:11 --:--:--  183k
736536
vscode ➜ ~/repositories/reva (prefer-return-minimal ✗) $ curl -k https://cloud.ocis.test/ocs/v1.php/apps/files_sharing/api/v1/shares\?include_tags\=false\&state\=all\&shared_with_me\=true\&format\=json -u marie:radioactivity | wc -c 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  554k    0  554k    0     0  54360      0 --:--:--  0:00:10 --:--:--  132k
567465

roughly 1/3 the size...

butonic commented 2 years ago

also supported by oc10:

$ curl https://demo.owncloud.com/ocs/v1.php/apps/files_sharing/api/v1/shares\?include_tags\=false\&state\=all\&shared_with_me\=true\&format\=json -u demo:demo                   
{"ocs":{"meta":{"status":"ok","statuscode":100,"message":null,"totalitems":"","itemsperpage":""},"data":[]}}
kulmann commented 2 years ago

Would need to add a format param to https://github.com/owncloud/owncloud-sdk/blob/1fa10b001dc47b7116f41646352961eb3a879113/src/helperFunctions.js#L215 , use it in that function for the request and the parsing preference. Then use it in getShares and getShare of the shareManagement.js file. Very straightforward.