Repository navigation
Expand file tree
/
Copy pathbundle.js
More file actions
1 lines (1 loc) · 4.94 KB
/
Copy pathbundle.js
File metadata and controls
1 lines (1 loc) · 4.94 KB
1
(()=>{"use strict";var t={743:function(t,e,n){var o=this&&this.__awaiter||function(t,e,n,o){return new(n||(n=Promise))((function(i,s){function r(t){try{a(o.next(t))}catch(t){s(t)}}function c(t){try{a(o.throw(t))}catch(t){s(t)}}function a(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(r,c)}a((o=o.apply(t,e||[])).next())}))},i=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const s=i(n(943));function r(t,e,n){return o(this,void 0,void 0,(function*(){let o=0,i=1;const s=[];let r=0;for(;i>0&&r<n;){const n=new URL(t);n.searchParams.set("offset",o.toString());const c=yield fetch(n,e).then((t=>t.json()));for(const t of c)s.push(t);i=c.length,o+=i,r++}return s}))}e.default=class{constructor(t,e){this.endpoint=t,this.authStatus="none",this.onAuth=null,e&&(this.credentials=e,this.onAuth=fetch(this.endpoint+"/login/oauth/access-token",{method:"POST",body:"username="+encodeURIComponent(e.username)+"&password="+encodeURIComponent(e.password),headers:{"Content-Type":"application/x-www-form-urlencoded"}}).catch((t=>{console.log(t),this.authStatus="failed"})).then((t=>t.json())).catch((t=>{console.log(t),this.authStatus="failed"})).then((t=>{this.authStatus="succeeded",this.authToken=t.access_token})))}get tags(){return new Promise(((t,e)=>o(this,void 0,void 0,(function*(){fetch(this.endpoint+"/tags/").catch(e).then((n=>n.json().catch(e).then(t)))}))))}get categories(){return new Promise(((t,e)=>o(this,void 0,void 0,(function*(){fetch(this.endpoint+"/categories/").catch(e).then((n=>n.json().catch(e).then(t)))}))))}get owners(){return new Promise(((t,e)=>o(this,void 0,void 0,(function*(){fetch(this.endpoint+"/owners/").catch(e).then((n=>n.json().catch(e).then(t)))}))))}getPublicSatellites(t){return o(this,void 0,void 0,(function*(){return(yield r(this.endpoint+"/satellites/public/",{},t||1)).map((t=>new s.default(t.norad_cat_id,t.object_name,t.object_id,t.object_type)))}))}getPrivateSatellites(t){return o(this,void 0,void 0,(function*(){if("succeeded"!==this.authStatus)throw new Error("Authentication required for listing private satellites");return(yield r(this.endpoint+"/satellites/private/",{headers:{Authorization:"Basic "+btoa(this.credentials.username+":"+this.credentials.password)}},t||1)).map((t=>new s.default(t.norad_cat_id,t.object_name,t.object_id,t.object_type)))}))}}},171:function(t,e){var n=this&&this.__awaiter||function(t,e,n,o){return new(n||(n=Promise))((function(i,s){function r(t){try{a(o.next(t))}catch(t){s(t)}}function c(t){try{a(o.throw(t))}catch(t){s(t)}}function a(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(r,c)}a((o=o.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.default=class{constructor(t){this.sources=t}get tags(){return new Promise(((t,e)=>n(this,void 0,void 0,(function*(){for(const n of this.sources)try{t(yield n.tags);break}catch(t){e(t)}e("All sources failed")}))))}get categories(){return new Promise(((t,e)=>n(this,void 0,void 0,(function*(){for(const n of this.sources)try{t(yield n.categories);break}catch(t){e(t)}e("All sources failed")}))))}get owners(){return new Promise(((t,e)=>n(this,void 0,void 0,(function*(){for(const n of this.sources)try{t(yield n.owners);break}catch(t){e(t)}e("All sources failed")}))))}getPublicSatellites(t){return new Promise(((e,o)=>n(this,void 0,void 0,(function*(){for(const n of this.sources)try{e(yield n.getPublicSatellites(t));break}catch(t){o(t)}o("All sources failed")}))))}getPrivateSatellites(t){return new Promise(((e,o)=>n(this,void 0,void 0,(function*(){for(const n of this.sources){console.log("Trying source with endpoint "+n.endpoint+"..."),console.log("Auth status: "+n.authStatus);try{e(yield n.getPrivateSatellites(t));break}catch(t){}}o("All sources failed")}))))}}},943:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=class{constructor(t,e,n,o){this.noradCatId=t,this.name=e,this.id=n,this.objectType=o}}},156:function(t,e,n){var o=this&&this.__awaiter||function(t,e,n,o){return new(n||(n=Promise))((function(i,s){function r(t){try{a(o.next(t))}catch(t){s(t)}}function c(t){try{a(o.throw(t))}catch(t){s(t)}}function a(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(r,c)}a((o=o.apply(t,e||[])).next())}))},i=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const s=i(n(743)),r=i(n(171)),c=new s.default("http://localhost:3000/https://api.spaceforce.sh",{username:"alice",password:"secret"}),a=new s.default("https://spaseforse.example");Promise.all([a.onAuth,c.onAuth]).then((()=>o(void 0,void 0,void 0,(function*(){console.log("Listing private satellites...");const t=new r.default([a,c]);window.src=t,console.log(yield t.getPrivateSatellites(3))}))))}},e={};!function n(o){var i=e[o];if(void 0!==i)return i.exports;var s=e[o]={exports:{}};return t[o].call(s.exports,s,s.exports,n),s.exports}(156)})();