wala.js (614B)
1 function Wala(url) { 2 this._url = url; 3 } 4 5 Wala.prototype.put = async function(v, filename, mimetype) { 6 let headers = {}; 7 if (filename !== undefined) { 8 headers['X-Filename'] = filename; 9 } 10 let r = await fetch(this._url, { 11 method: 'put', 12 headers: headers, 13 body: v, 14 }); 15 if (!r.ok) { 16 throw ('failed put'); 17 } 18 return r.text(); 19 } 20 21 Wala.prototype.get = async function(k, binary=false) { 22 const url = this.url(k) 23 let r = await fetch(url); 24 if (!r.ok) { 25 throw ('failed get'); 26 } 27 if (binary) { 28 return r.blob(); 29 } 30 return r.text(); 31 } 32 33 Wala.prototype.url = function(k) { 34 return this._url + '/' + k; 35 }