-
Notifications
You must be signed in to change notification settings - Fork 373
/
files.js
47 lines (42 loc) · 1.3 KB
/
files.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
/*
* files.js: Instance methods for working with files from Rackspace Cloudfiles
*
* (C) 2013 Rackspace, Ken Perkins
* MIT LICENSE
*
*/
//
// ### function purgeFileFromCdn (container, file, emails, callback)
// #### @container {string} Name of the container to destroy the file in
// #### @file {string} Name of the file to destroy.
// #### @emails {Array} Optional array of emails to notify on purging
// #### @callback {function} Continuation to respond to when complete.
// Destroys the `file` in the specified `container`.
//
exports.purgeFileFromCdn = function (container, file, emails, callback) {
var containerName = container instanceof this.models.Container ? container.name : container,
fileName = file instanceof this.models.File ? file.name : file;
if (typeof emails === 'function') {
callback = emails;
emails = [];
}
else if (typeof emails === 'string') {
emails = emails.split(',');
}
var purgeOptions = {
method: 'DELETE',
container: containerName,
path: fileName,
serviceType: this.cdnServiceType
};
if (emails.length) {
purgeOptions.headers = {};
purgeOptions.headers['x-purge-email'] = emails.join(',');
}
this._request(purgeOptions, function (err) {
return err
? callback(err)
: callback(null, true);
}
);
};