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.

Create structured data

POST /structured-data
store.js
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).

store.js
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.

Save structured data

PUT /structured-data/:handleId
store.js
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 data ID handle

GET /structured-data/data-id/:handleId
store.js
safeStructuredData.getDataIdHandle(ACCESS_TOKEN, handle)

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

store.js
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.

Update structured data

PATCH /structured-data/:handleId
store.js
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.

Save structured data

POST /structured-data/:handleId
store.js
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

results matching ""

    No results matching ""