slouch/scripts/attachment.js
Geoff Cox da7ca1123e 100% coverage (#4)
* doc(readme): clean up reasons

* doc(motto)

* test(db-and-doc): more coverage

* test(create-or-update-ignore-conflict)

* test(upsert)

* test(ignore-missing)

* test(post-and-ignore-conflict)

* test(get-merge-put)

* refactor(all): rename post and put

* test(get-merge-create-or-update)

* test(get-merge-update-ignore-conflict)

* test(get-merge-upsert)

* test(get-modify-upsert)

* refactor(doc): redundant code

* test(destroy-ignore-conflict)

* test(get-and-destroy)

* test(mark-as-destroyed)

* test(set-destroyed)

* refactor(attachment)

* test(doc): 100% coverage

* test(attachment): create with base 64

* test(attachment): clean up binary code

* test(attachment): get

* test(attachment): destroy

* test(system): is couchdb 1

* test(system): get

* test(system): reset

* test(updates)

* test(updates)

* test(all): unique DB names

* test(system): reactivate tests

* test(user): add role

* test(user): downsert role

* feat(stream-iterator): indefinite

* test(user): 100% coverage

* test(request-class)

* test(request-class): 100% coverage

* test(config)

* test(config): more coverage

* test(config): more coverage

* test(config): 100% coverage

* test(all): 100% coverage

* refactor(beautify)

* test(coverage): enforce 100%

* test(system): fix race condition

* test(user): shortcut for browser

* test(updates): test continuous stream in phantomjs

* test(updates): test continuous stream in phantomjs

* test(continuous): mock for phantomjs

* test(system): abort iterators

* test(system): fake abort
2017-07-18 07:45:32 -07:00

54 lines
1.3 KiB
JavaScript

'use strict';
var promisedRequest = require('./request');
var Attachment = function (slouch) {
this._slouch = slouch;
};
// TODO
// Attachment.prototype.create = function (dbName, docId, attachmentName, data, contentType, rev) {
// var formData = {
// custom_file: {
// value: data,
// options: {
// filename: attachmentName,
// contentType: contentType
// }
// }
// };
//
// return promisedRequest.request({
// uri: this._slouch._url + '/' + dbName + '/' + docId + '/' + attachmentName +
// '?rev=' + encodeURIComponent(rev),
// method: 'PUT',
// // raw: true,
// // encoding: null,
// formData: formData
// }).then(function (response) {
// return response.body;
// });
// };
Attachment.prototype.get = function (dbName, docId, attachmentName) {
return promisedRequest.request({
uri: this._slouch._url + '/' + dbName + '/' + docId + '/' + attachmentName,
method: 'GET',
raw: true,
encoding: null
}).then(function (response) {
return response.body;
});
};
Attachment.prototype.destroy = function (dbName, docId, attachmentName, rev) {
return promisedRequest.request({
uri: this._slouch._url + '/' + dbName + '/' + docId + '/' + attachmentName,
method: 'DELETE',
qs: {
rev: rev
}
});
};
module.exports = Attachment;