cs3org / wopiserver

A vendor-neutral application gateway compatible with the WOPI specifications.
Apache License 2.0
55 stars 26 forks source link

Use endpoint for cs3ref + use parent_id for relative paths in CS3Iface #67

Closed dragotin closed 2 years ago

glpatcern commented 2 years ago

@dragotin and @wkloucek, shall we schedule some discussion to see how to proceed? I guess you're trying to support spaces, but the key point here is first to define how the /openinapp endpoint is (going to be) called from Reva within a space. Afterwards, we can see how to internally map the space id to an endpoint.

glpatcern commented 2 years ago

Update: following yesterday's "hackathon", this is feasible with some more extensions and after https://github.com/cs3org/cs3apis/pull/167 is implemented in Reva. Shouldn't take much effort, we have already sketched the code for cs3iface.py yesterday.

labkode commented 2 years ago

@glpatcern the parent_id is now merged upstream and cs3apis binding should be there for Python. Note that we require Reva-side implementation as well to return this value.

wkloucek commented 2 years ago

@glpatcern please feel free to try https://github.com/cs3org/reva/pull/2691. That should unblock the WOPI server on REVA edge.

glpatcern commented 2 years ago

@glpatcern please feel free to try cs3org/reva#2691. That should unblock the WOPI server on REVA edge.

Thanks, looks good indeed but I won't have time to test it before Thursday I fear. Will do the equivalent code on Reva master for the eos provider - actually that PR could target Reva master and then get merged to Reva edge.

wkloucek commented 2 years ago

I tried it today with the latest oCIS and needed to merge master into this branch and apply following patch to make it work:

diff --git a/src/core/cs3iface.py b/src/core/cs3iface.py
index c51de8c..962ca42 100644
--- a/src/core/cs3iface.py
+++ b/src/core/cs3iface.py
@@ -95,8 +95,7 @@ def stat(endpoint, fileref, userid, versioninv=1):
         inode = common.encodeinode(statInfo.info.id.storage_id, statInfo.info.id.opaque_id)
         # in case we got a relative path, build an hybrid path that can be used to reference the file:
         # note that as per specs the parent_id MUST be available in this case
-        filepath = statInfo.info.path if statInfo.info.path[0] == '/' else \
-                        statInfo.info.parent_id.opaque_id + '/' + os.path.basename(statInfo.info.path)
+        filepath = statInfo.info.parent_id.opaque_id + '/' + os.path.basename(statInfo.info.path)
         log.info('msg="Invoked stat" fileref="%s" inode="%s" filepath="%s" elapsedTimems="%.1f"' %
                  (fileref, inode, filepath, (tend-tstart)*1000))
         return {
@@ -257,7 +256,7 @@ def readfile(endpoint, filepath, userid, lockid):

     # Download
     try:
-        protocol = [p for p in initfiledownloadres.protocols if p.protocol == "simple"][0]
+        protocol = [p for p in initfiledownloadres.protocols if p.protocol == "simple" or p.protocol == "spaces"][0]
         headers = {
             'x-access-token': userid,
             'x-reva-transfer': protocol.token        # needed if the downloads pass through the data gateway in reva
@@ -304,7 +303,7 @@ def writefile(endpoint, filepath, userid, content, lockid, islock=False):
     # Upload
     try:
         # Get the endpoint for simple protocol
-        protocol = [p for p in initfileuploadres.protocols if p.protocol == "simple"][0]
+        protocol = [p for p in initfileuploadres.protocols if p.protocol == "simple" or p.protocol == "spaces"][0]
         headers = {
             'x-access-token': userid,
             'Upload-Length': size,

Also I had to ensure that external locks are disabled (detectexternallocks = False).

Then I could open files in edit mode, though I didn't succeed on saving files. This was most likely caused by the Set/GetXattr logic. From the logs I see that Set/GetXattr on REVA edge might be broken. Also I am not sure why a stat on current REVA edge returns a full path (it didn't the last time I checked)

glpatcern commented 2 years ago

@wkloucek thanks for this, you can definitely push the patch on p.protocol == "spaces". Otherwise, the first patch won't be needed once Reva returns a relative path instead of a full path (yeah that does not sound correct), and the xattr logic must also work for save (PutFile) to work indeed.