github.com/cozy/cozy-stack@v0.0.0-20240603063001-31110fa4cae1/docs/office.md (about)

     1  [Table of contents](README.md#table-of-contents)
     2  
     3  # Collaborative edition of Office documents
     4  
     5  ## Diagrams
     6  
     7  ### Opening a document with OnlyOffice
     8  
     9  Reference: https://api.onlyoffice.com/editors/open
    10  
    11  ![Opening a document with OnlyOffice](diagrams/onlyoffice-open.png)
    12  
    13  1. The browser makes a request `GET /office/:id/open` to know the address of the OnlyOffice server
    14  2. The browser makes several HTTP requests to the Document Server
    15      1. Fetch the `api.js` script
    16      2. Open a websocket connection
    17      3. Send a command to load the office document
    18  3. The document server makes a request to the [callback URL](https://api.onlyoffice.com/editors/callback#status-1) with `status=1`
    19  4. The document server asks the file converter to load the document (via RabbitMQ?)
    20  5. The file converter loads the file content from the stack
    21  
    22  ### Saving a document with OnlyOffice
    23  
    24  Reference: https://api.onlyoffice.com/editors/save
    25  
    26  ![Saving a document with OnlyOffice](diagrams/onlyoffice-save.png)
    27  
    28  1. The browser makes requests to edit the document and close the connection when done
    29  2. The document server waits a bit after all clients have disconnected, and send a request to the callback URL
    30  3. The stack downloads the file from the document server and saves it
    31  
    32  ## Routes
    33  
    34  ### GET /office/:id/open
    35  
    36  This route returns the parameters to open an office document. There are two
    37  cases:
    38  
    39  1. The document is shared and should be opened on another instance (for
    40     collaborative edition)
    41  2. The document can be opened locally.
    42  
    43  In the first case, the response will contain the parameters of the other
    44  instance. In the second case, the parameters are for the document server of
    45  OnlyOffice.
    46  
    47  If the identifier doesn't give an office document or if there is no onlyoffice
    48  server configured, the response will be a `404 Page not found`.
    49  
    50  #### Request
    51  
    52  ```http
    53  GET /office/32e07d806f9b0139c541543d7eb8149c/open HTTP/1.1
    54  Host: bob.cozy.example
    55  ```
    56  
    57  #### Response (case 1)
    58  
    59  ```http
    60  HTTP/1.1 200 OK
    61  Content-Type: application/vnd.api+json
    62  ```
    63  
    64  ```json
    65  {
    66    "data": {
    67      "type": "io.cozy.office.url",
    68      "id": "32e07d806f9b0139c541543d7eb8149c",
    69      "attributes": {
    70        "document_id": "b05e7c306f9c0139c542543d7eb8149c",
    71        "subdomain": "flat",
    72        "protocol": "https",
    73        "instance": "alice.cozy.example",
    74        "sharecode": "543d7eb8149c",
    75        "public_name": "Bob"
    76      }
    77    }
    78  }
    79  ```
    80  
    81  #### Response (case 2)
    82  
    83  ```http
    84  HTTP/1.1 200 OK
    85  Content-Type: application/vnd.api+json
    86  ```
    87  
    88  ```json
    89  {
    90    "data": {
    91      "type": "io.cozy.office.url",
    92      "id": "32e07d806f9b0139c541543d7eb8149c",
    93      "attributes": {
    94        "document_id": "32e07d806f9b0139c541543d7eb8149c",
    95        "subdomain": "flat",
    96        "protocol": "https",
    97        "instance": "bob.cozy.example",
    98        "public_name": "Bob",
    99        "onlyoffice": {
   100          "url": "https://documentserver/",
   101          "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M",
   102          "documentType": "word",
   103          "document": {
   104            "filetype": "docx",
   105            "key": "7c7ccc2e7137ba774b7e44de",
   106            "title": "Letter.docx",
   107            "url": "https://bob.cozy.example/files/downloads/735e6cf69af2db82/Letter.docx?Dl=1",
   108            "info": {
   109              "owner": "Bob",
   110              "uploaded": "2010-07-07 3:46 PM"
   111            }
   112          },
   113          "editor": {
   114            "callbackUrl": "https://bob.cozy.example/office/callback",
   115            "lang": "en",
   116            "mode": "edit"
   117          }
   118        }
   119      }
   120    }
   121  }
   122  ```
   123  
   124  ### POST /office/keys/:key
   125  
   126  If a document is being edited while a new version is uploaded (via the desktop
   127  for example), the OO webapp should call this endpoint if the user chooses to
   128  continue editing the version on which they were working. A conflict file is
   129  created, so that no work is lost.
   130  
   131  #### Request
   132  
   133  ```http
   134  POST /office/keys/7c7ccc2e7137ba774b7e44de HTTP/1.1
   135  Host: bob.cozy.example
   136  ```
   137  
   138  #### Response
   139  
   140  ```http
   141  HTTP/1.1 200 OK
   142  Content-Type: application/vnd.api+json
   143  ```
   144  
   145  ```json
   146  {
   147    "data": {
   148      "type": "io.cozy.files",
   149      "id": "32e07d806f9b0139c541543d7eb8149c",
   150      "meta": {
   151        "rev": "3-18c04daba326"
   152      },
   153      "attributes": {
   154        "type": "file",
   155        "name": "slideshow (2).pptx",
   156        "trashed": false,
   157        "md5sum": "ODZmYjI2OWQxOTBkMmM4NQo=",
   158        "created_at": "2023-09-30T21:42:05Z",
   159        "updated_at": "2023-09-30T22:38:04Z",
   160        "tags": [],
   161        "metadata": {},
   162        "size": 12345,
   163        "executable": false,
   164        "class": "slide",
   165        "mime": "application/vnd.ms-powerpoint",
   166        "cozyMetadata": {
   167          "doctypeVersion": "1",
   168          "metadataVersion": 1,
   169          "createdAt": "2023-09-30T21:42:05Z",
   170          "createdByApp": "drive",
   171          "createdOn": "https://bob.cozy.example/",
   172          "updatedAt": "2023-09-30T22:38:04Z",
   173          "uploadedAt": "2023-09-30T22:38:04Z",
   174          "uploadedOn": "https://bob.cozy.example/",
   175          "uploadedBy": {
   176            "slug": "onlyoffice-server"
   177          }
   178        }
   179      }
   180    }
   181  }
   182  ```
   183  
   184  ### POST /office/callback
   185  
   186  This is the callback handler for OnlyOffice. It is called when the document
   187  server wants to save the file.
   188  
   189  See https://api.onlyoffice.com/editors/callback
   190  
   191  #### Request
   192  
   193  ```http
   194  POST /office/callback HTTP/1.1
   195  Host: bob.cozy.example
   196  Content-Type: application/json
   197  ```
   198  
   199  ```json
   200  {
   201      "actions": [{"type": 0, "userid": "78e1e841"}],
   202      "changesurl": "https://documentserver/url-to-changes.zip",
   203      "key": "7c7ccc2e7137ba774b7e44de",
   204      "status": 2,
   205      "url": "https://documentserver/url-to-edited-document.docx",
   206      "users": ["6d5a81d0"]
   207  }
   208  ```
   209  
   210  #### Response
   211  
   212  ```http
   213  HTTP/1.1 200 OK
   214  Content-Type: application/json
   215  ```
   216  
   217  ```json
   218  { "error": 0 }
   219  ```