Create a file

Each Markdown file you create will be stored inside a new versioned structured data. In order for you to be able to retrieve your files, the app needs to add the filename of each file you create to your file index.

Contents

Create a file

Create file

The app creates a versioned structured data (type tag 501) with an ID based on your user prefix and the filename. This structured data will contain all the different versions of your file. The first version is encrypted using the cipher options handle previously obtained.

POST /structured-data

safeStructuredData.create(ACCESS_TOKEN,
  // trying to come up with a name that is super unlikely to clash ever.
  btoa(`${USER_PREFIX}:${filename}`),
  // 501 => we want this versioned
  501, payload, SYMETRIC_CYPHER_HANDLE)

Each 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 first version of your file by sending a PUT request to the SAFE Network.

PUT /structured-data/:handleId

safeStructuredData.put(ACCESS_TOKEN, handle)

Get a data ID handle

The app obtains a data ID handle for the versioned structured data that contains the file you just created.

GET /structured-data/data-id/:handleId

safeStructuredData.getDataIdHandle(ACCESS_TOKEN, handle)

The app adds the filename and the data ID handle to the global variable representing your file index.

FILE_INDEX[filename] = dataHandleId;

Update the file index

The app updates the structured data that contains your file index. The updated file index contains the name of the file you just created.

PATCH /structured-data/:handleId

safeStructuredData.updateData(ACCESS_TOKEN,
  INDEX_HANDLE,
  new Buffer(JSON.stringify(FILE_INDEX)).toString('base64'),
  SYMETRIC_CYPHER_HANDLE)

The app saves your file index by sending a POST request to the SAFE Network.

POST /structured-data/:handleId

safeStructuredData.post(ACCESS_TOKEN, INDEX_HANDLE)

Fetch file index

The app refetches your file index in order to update the list of files in the UI.

Fetch file index

Last updated

Was this helpful?