nextcloud / whiteboard

Create & collaborate on an infinite canvas!
https://apps.nextcloud.com/apps/whiteboard
GNU Affero General Public License v3.0
44 stars 3 forks source link

Saving issues #60

Closed juliushaertl closed 2 months ago

juliushaertl commented 3 months ago

It seems we still have hardcoded dev environemnt credentials for saving back the file. We should instead rather also use the JWT token there, as currently saving fails with that.

hweihwang commented 3 months ago

@juliushaertl

Thanks for pointing this out!

To clarify, are we aiming for headless BE to BE communication (Node => Nextcloud PHP)? Via:

Since the roomData is already validated and authenticated at the time of writing.

If we use JWT for writing, we should consider the following:

// Called when there's nobody in the room (No one keeping the latest data), BE to BE communication
export const saveRoomDataToFile = async (roomID, data) => {
    console.log(`[${roomID}] Saving room data to file: ${roomID}`)
    const url = `${NEXTCLOUD_URL}/index.php/apps/whiteboard/${roomID}`
    const body = { data: { elements: data } }
    const options = fetchOptions('PUT', '', body)

    await fetchData(url, options)
}

// TODO: Should be called when the server is shutting down and a should be a BE to BE (or OS) communication
//  in batch operation, run in background and check if it's necessary to save for each room.
//  And can be called periodically and saved somewhere else for preventing data loss (memory loss, server crash, electricity cut, etc.)
export const saveAllRoomsData = async () => {
}
juliushaertl commented 2 months ago

Thanks for the good summary. As discussed in the call let's go for a shared token authentication so the node backend can authenticate towards the PHP backend with that. We should keep track of users on the board and save the file in the scope of a random user (maybe the last one with edit permissions) as the file system currently does not support saving in scope of an app or multiple users.