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.


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
  // trying to come up with a name that is super unlikely to clash ever.
  // 501 => we want this versioned

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

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

Update structured data

PATCH /structured-data/:handleId
  new Buffer(JSON.stringify(FILE_INDEX)).toString('base64'),

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

Save structured data

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