Skip to content

Commit

Permalink
FEATURE: Add a resource to an item (as a file).
Browse files Browse the repository at this point in the history
  • Loading branch information
benel committed Apr 20, 2022
1 parent 464c03e commit c7a470b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,11 @@ db.auth('alice', 'whiterabbit')
.then(_log)
.catch(_error);
```

```js
db.auth('alice', 'whiterabbit')
.item({_id:'007', item_corpus:'agents'})
.setResource('hello.txt', 'text/plain', 'My name is Bond, James Bond.')
.then(_log)
.catch(_error);
```
13 changes: 13 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ module.exports = function Hypertopic(services) {
})
.then(db.post);

this.setResource = (resource_id, content_type, raw_data) => item
.then(o => ({
...o,
_attachments: {
...o._attachments,
[resource_id]: {
content_type,
data: Buffer.from(raw_data).toString('base64')
}
}
}))
.then(db.post)

this.then = x => item.then(x);

return this;
Expand Down

0 comments on commit c7a470b

Please sign in to comment.