text: var Promise=require("bluebird"),superagent=require("superagent"),helper=require("./Helper"),TurboStorage=function(e){var n=e;return{uploadFile:function(e,t){return new Promise(function(r,i){if(null==t)return void i(new Error("API Key required"));if(null==e)return void i(new Error("Missing file"));if(null==e.name)return void i(new Error("Missing file name"));if(null==e.type)return void i(new Error("Missing file type"));const o=e.type.toLowerCase();console.log("FILE TYPE: "+o);var s={site:n.site_id,exec:"upload-string",filename:e.name,filetype:o},u={"Content-Type":"application/json","Turbo-API-Key":"Bearer "+t};superagent.post(n.base_url+"/functions").send(s).set(u).end(function(t,s){if(t)return void i(t);var u=s.body;if("success"!=u.confirmation)return void i(new Error(u.message));var a=u.result;if(-1==e.type.indexOf("image"))return void superagent.put(a).send(e).set("Content-Type",e.type).end(function(t,o){if(t)return void i(t);var s={site:n.site_id,name:e.name,type:e.type,size:e.size,url:"https://storage.turbo360.co/"+u.site.slug+"/"+e.name};superagent.post(n.turbo_url+"/api/blob").send(s).set("Accept","application/json").end(function(e,n){if(e)return void i(e);r(n.body)})});if(o.indexOf("gif")>-1||o.indexOf("svg")>-1)return void superagent.put(a).send(e).set("Content-Type",e.type).end(function(t,o){if(t)return void i(t);var s={site:n.site_id,name:e.name,type:e.type,size:e.size,url:"https://storage.turbo360.co/"+u.site.slug+"/"+e.name};superagent.post(n.turbo_url+"/api/blob").send(s).set("Accept","application/json").end(function(e,n){if(e)return void i(e);r(n.body)})});var p=superagent.post(a);p.attach("file",e),p.end(function(t,o){if(t)return void i(t);var s=o.body.image,u={site:n.site_id,name:e.name,type:e.type,size:e.size,url:s.address};superagent.post(n.turbo_url+"/api/blob").send(u).set("Accept","application/json").end(function(e,n){if(e)return void i(e);r(n.body)})})})})}}};module.exports=TurboStorage;