/
attachment.js
54 lines (49 loc) · 1.39 KB
/
attachment.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict';
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 this._slouch._req({
// 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 this._slouch._req({
uri: this._slouch._url + '/' + encodeURIComponent(dbName) + '/' + encodeURIComponent(
docId) + '/' + encodeURIComponent(attachmentName),
method: 'GET',
raw: true,
encoding: null
}).then(function (response) {
return response.body;
});
};
Attachment.prototype.destroy = function (dbName, docId, attachmentName, rev) {
return this._slouch._req({
uri: this._slouch._url + '/' + encodeURIComponent(dbName) + '/' + encodeURIComponent(
docId) + '/' + encodeURIComponent(attachmentName),
method: 'DELETE',
qs: {
rev: rev
}
});
};
module.exports = Attachment;