UNPKG

edgecast-purge

Version:

a service to purge media from edgecast's cache

2 lines (1 loc) 1.32 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t():"function"==typeof define&&define.amd?define(t):t()}(0,function(){"use strict";var e=require("https"),t=require("path"),n=require("winston"),o=new n.Logger({transports:[new n.transports.Console({timestamp:function(){return(new Date).toLocaleTimeString()},colorize:!0})]}),r=function(){function n(e,o){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,n),this.token=e,this.customerId=o,this.endpoint=t.join("/v2","mcc","customers",o,"edge","purge"),this.headers={Authorization:"tok: "+e,Accept:"application/json","Content-Type":"application/json"}}return n.prototype.purge=function(e){var t=this,n="string"==typeof e?[e]:e;return Promise.all(n.map(function(e){return t.purgeRsource(e)}))},n.prototype.purgeRsource=function(t){var n=this;return new Promise(function(r,i){var s={MediaPath:t,MediaType:"3"},u=[],a=e.request({method:"PUT",hostname:"api.edgecast.com",port:443,path:n.endpoint,headers:n.headers},function(e){e.on("data",function(e){u.push(e)}),e.on("end",function(){var n=u.join();return e.statusCode>=200&&e.statusCode<300?(o.info("purged: "+t),r(n)):(o.error("error purging: "+t+"; err="+(n.Message||n.toString())),i(n))})});a.write(JSON.stringify(s)),a.end()})},n}();module.exports=r});