-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathcontainer.js
More file actions
85 lines (72 loc) · 2.14 KB
/
container.js
File metadata and controls
85 lines (72 loc) · 2.14 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* container.js: Instance of a single Rackspace Cloudfiles container
*
* (C) 2010 Nodejitsu Inc.
* MIT LICENSE
*
*/
var cloudfiles = require('../cloudfiles');
var Container = exports.Container = function (client, details) {
if (!details) {
throw new Error("Container must be constructed with at least basic details.")
}
if(typeof details !== 'object') {
details = {name: details};
}
this.files = [];
this.client = client;
this._setProperties(details);
};
Container.prototype = {
addFile: function (file, local, options, callback) {
if(!options && !callback) {
options = {};
}
if (typeof options === 'function' && !callback) {
callback = options;
options = {};
}
options.remote = file;
options.local = local;
return this.client.addFile(this.name, options, callback);
},
destroy: function (callback) {
this.client.destroyContainer(this.name, callback);
},
getFiles: function (download, callback) {
var self = this;
// download can be omitted: (...).getFiles(callback);
// In this case first argument will be a function
if (typeof download === 'function' && !(download instanceof RegExp)) {
callback = download;
download = false;
}
this.client.getFiles(this.name, download, function (err, files) {
if (err) {
return callback(err);
}
self.files = files;
callback(null, files);
});
},
removeFile: function (file, callback) {
this.client.destroyFile(this.name, file, callback);
},
// Remark: Not fully implemented
updateCdn: function (options, callback) {
if (!this.cdnEnabled) {
callback(new Error('Cannot call updateCdn on a container that is not CDN enabled'));
}
// TODO: Write the rest of this method
},
_setProperties: function (details) {
this.name = details.name;
this.cdnEnabled = details.cdnEnabled || false;
this.cdnUri = details.cdnUri;
this.cdnSslUri = details.cdnSslUri;
this.ttl = details.ttl;
this.logRetention = details.logRetention;
this.count = details.count || 0;
this.bytes = details.bytes || 0;
}
};