Save a new version

When you edit an existing file, a new version is stored inside the structured data associated with that file.

Contents

Save a new version

Get a data ID handle

The app obtains a data ID handle for the versioned structured data (type tag 501) that contains the file you just edited. The ID of this structured data is based on your user prefix and the name of the file.

POST /data-id/structured-data

safeDataId.getStructuredDataHandle(ACCESS_TOKEN, btoa(`${USER_PREFIX}:${filename}`), 501)

Get a structured data handle

The app obtains a structured data handle using the data ID handle of the file you just edited.

GET /structured-data/handle/:dataIdHandle

safeStructuredData.getHandle(ACCESS_TOKEN, dataIdHandle)

After obtaining a structured data handle, the app drops the data ID handle of the file you just edited.

DELETE /data-id/:handleId

safeDataId.dropHandle(ACCESS_TOKEN, dataIdHandle)

Update the file

The app stores a new version inside the structured data associated with the file you just edited. It's encrypted using the cipher options handle previously obtained.

PATCH /structured-data/:handleId

safeStructuredData.updateData(ACCESS_TOKEN, handleId, payload, SYMETRIC_CYPHER_HANDLE)

This new version includes the Markdown content and the current time (encoded as a base 64 string).

const payload = new Buffer(JSON.stringify({
  ts: (new Date()).getTime(),
  content: data
})).toString('base64');

The app saves the new version of your file by sending a POST request to the SAFE Network.

POST /structured-data/:handleId

safeStructuredData.post(ACCESS_TOKEN, handleId)

Fetch all versions

The app refetches all the versions of the file and displays them in the UI.

Fetch all versions

Last updated

Was this helpful?