javascript-ampache
Version:
A JS library for the Ampache API
3 lines (2 loc) • 20.8 kB
JavaScript
const t={albums(t){return this.call("albums",t)},album(t){return this.call("album",t)},artistAlbums(t){return this.call("artist_albums",t)},genreAlbums(t){return this.call("genre_albums",t)}},e={artists(t){return this.call("artists",t)},artist(t){return this.call("artist",t)},genreArtists(t){return this.call("genre_artists",t)},labelArtists(t){return this.call("label_artists",t)}};var r=Object.prototype.hasOwnProperty;function s(t){try{return encodeURIComponent(t)}catch(t){return null}}var n=function(t,e){e=e||"";var n,l,i=[];for(l in"string"!=typeof e&&(e="?"),t)if(r.call(t,l)){if((n=t[l])||null!=n&&!isNaN(n)||(n=""),l=s(l),n=s(n),null===l||null===n)continue;i.push(l+"="+n)}return i.length?e+i.join("&"):""},l={__proto__:null,default:function(t,e){return e=e||{},new Promise(function(r,s){var n=new XMLHttpRequest,l=[],i=[],a={},o=function(){return{ok:2==(n.status/100|0),statusText:n.statusText,status:n.status,url:n.responseURL,text:function(){return Promise.resolve(n.responseText)},json:function(){return Promise.resolve(n.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([n.response]))},clone:o,headers:{keys:function(){return l},entries:function(){return i},get:function(t){return a[t.toLowerCase()]},has:function(t){return t.toLowerCase()in a}}}};for(var u in n.open(e.method||"get",t,!0),n.onload=function(){n.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,function(t,e,r){l.push(e=e.toLowerCase()),i.push([e,r]),a[e]=a[e]?a[e]+","+r:r}),r(o())},n.onerror=s,n.withCredentials="include"==e.credentials,e.headers)n.setRequestHeader(u,e.headers[u]);n.send(e.body||null)})}},i=self.fetch||(self.fetch=l.default||l);const a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o="ARRAYBUFFER not supported by this environment",u="UINT8ARRAY not supported by this environment";function h(t,e,r,s){let n,l,i;const a=e||[0],o=(r=r||0)>>>3,u=-1===s?3:0;for(n=0;n<t.length;n+=1)i=n+o,l=i>>>2,a.length<=l&&a.push(0),a[l]|=t[n]<<8*(u+s*(i%4));return{value:a,binLen:8*t.length+r}}function c(t,e,r){switch(e){case"UTF8":case"UTF16BE":case"UTF16LE":break;default:throw new Error("encoding must be UTF8, UTF16BE, or UTF16LE")}switch(t){case"HEX":return function(t,e,s){return function(t,e,r,s){let n,l,i,a;if(0!=t.length%2)throw new Error("String of HEX type must be in byte increments");const o=e||[0],u=(r=r||0)>>>3,h=-1===s?3:0;for(n=0;n<t.length;n+=2){if(l=parseInt(t.substr(n,2),16),isNaN(l))throw new Error("String of HEX type contains invalid characters");for(a=(n>>>1)+u,i=a>>>2;o.length<=i;)o.push(0);o[i]|=l<<8*(h+s*(a%4))}return{value:o,binLen:4*t.length+r}}(t,e,s,r)};case"TEXT":return function(t,s,n){return function(t,e,r,s,n){let l,i,a,o,u,h,c,d,p=0;const f=r||[0],g=(s=s||0)>>>3;if("UTF8"===e)for(c=-1===n?3:0,a=0;a<t.length;a+=1)for(l=t.charCodeAt(a),i=[],128>l?i.push(l):2048>l?(i.push(192|l>>>6),i.push(128|63&l)):55296>l||57344<=l?i.push(224|l>>>12,128|l>>>6&63,128|63&l):(a+=1,l=65536+((1023&l)<<10|1023&t.charCodeAt(a)),i.push(240|l>>>18,128|l>>>12&63,128|l>>>6&63,128|63&l)),o=0;o<i.length;o+=1){for(h=p+g,u=h>>>2;f.length<=u;)f.push(0);f[u]|=i[o]<<8*(c+n*(h%4)),p+=1}else for(c=-1===n?2:0,d="UTF16LE"===e&&1!==n||"UTF16LE"!==e&&1===n,a=0;a<t.length;a+=1){for(l=t.charCodeAt(a),!0===d&&(o=255&l,l=o<<8|l>>>8),h=p+g,u=h>>>2;f.length<=u;)f.push(0);f[u]|=l<<8*(c+n*(h%4)),p+=2}return{value:f,binLen:8*p+s}}(t,e,s,n,r)};case"B64":return function(t,e,s){return function(t,e,r,s){let n,l,i,o,u,h,c,d=0;const p=e||[0],f=(r=r||0)>>>3,g=-1===s?3:0,m=t.indexOf("=");if(-1===t.search(/^[a-zA-Z0-9=+/]+$/))throw new Error("Invalid character in base-64 string");if(t=t.replace(/=/g,""),-1!==m&&m<t.length)throw new Error("Invalid '=' found in base-64 string");for(l=0;l<t.length;l+=4){for(u=t.substr(l,4),o=0,i=0;i<u.length;i+=1)n=a.indexOf(u.charAt(i)),o|=n<<18-6*i;for(i=0;i<u.length-1;i+=1){for(c=d+f,h=c>>>2;p.length<=h;)p.push(0);p[h]|=(o>>>16-8*i&255)<<8*(g+s*(c%4)),d+=1}}return{value:p,binLen:8*d+r}}(t,e,s,r)};case"BYTES":return function(t,e,s){return function(t,e,r,s){let n,l,i,a;const o=e||[0],u=(r=r||0)>>>3,h=-1===s?3:0;for(l=0;l<t.length;l+=1)n=t.charCodeAt(l),a=l+u,i=a>>>2,o.length<=i&&o.push(0),o[i]|=n<<8*(h+s*(a%4));return{value:o,binLen:8*t.length+r}}(t,e,s,r)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(t){throw new Error(o)}return function(t,e,s){return function(t,e,r,s){return h(new Uint8Array(t),e,r,s)}(t,e,s,r)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(t){throw new Error(u)}return function(t,e,s){return h(t,e,s,r)};default:throw new Error("format must be HEX, TEXT, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}function d(t,e,r,s){switch(t){case"HEX":return function(t){return function(t,e,r,s){const n="0123456789abcdef";let l,i,a="";const o=e/8,u=-1===r?3:0;for(l=0;l<o;l+=1)i=t[l>>>2]>>>8*(u+r*(l%4)),a+=n.charAt(i>>>4&15)+n.charAt(15&i);return s.outputUpper?a.toUpperCase():a}(t,e,r,s)};case"B64":return function(t){return function(t,e,r,s){let n,l,i,o,u,h="";const c=e/8,d=-1===r?3:0;for(n=0;n<c;n+=3)for(o=n+1<c?t[n+1>>>2]:0,u=n+2<c?t[n+2>>>2]:0,i=(t[n>>>2]>>>8*(d+r*(n%4))&255)<<16|(o>>>8*(d+r*((n+1)%4))&255)<<8|u>>>8*(d+r*((n+2)%4))&255,l=0;l<4;l+=1)h+=8*n+6*l<=e?a.charAt(i>>>6*(3-l)&63):s.b64Pad;return h}(t,e,r,s)};case"BYTES":return function(t){return function(t,e,r){let s,n,l="";const i=e/8,a=-1===r?3:0;for(s=0;s<i;s+=1)n=t[s>>>2]>>>8*(a+r*(s%4))&255,l+=String.fromCharCode(n);return l}(t,e,r)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(t){throw new Error(o)}return function(t){return function(t,e,r){let s;const n=e/8,l=new ArrayBuffer(n),i=new Uint8Array(l),a=-1===r?3:0;for(s=0;s<n;s+=1)i[s]=t[s>>>2]>>>8*(a+r*(s%4))&255;return l}(t,e,r)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(t){throw new Error(u)}return function(t){return function(t,e,r){let s;const n=e/8,l=-1===r?3:0,i=new Uint8Array(n);for(s=0;s<n;s+=1)i[s]=t[s>>>2]>>>8*(l+r*(s%4))&255;return i}(t,e,r)};default:throw new Error("format must be HEX, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}const p=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],f=[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428],g=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225];function m(t){const e={outputUpper:!1,b64Pad:"=",outputLen:-1},r=t||{},s="Output length must be a multiple of 8";if(e.outputUpper=r.outputUpper||!1,r.b64Pad&&(e.b64Pad=r.b64Pad),r.outputLen){if(r.outputLen%8!=0)throw new Error(s);e.outputLen=r.outputLen}else if(r.shakeLen){if(r.shakeLen%8!=0)throw new Error(s);e.outputLen=r.shakeLen}if("boolean"!=typeof e.outputUpper)throw new Error("Invalid outputUpper formatting option");if("string"!=typeof e.b64Pad)throw new Error("Invalid b64Pad formatting option");return e}class _{constructor(t,e,r){const s=r||{};if(this.t=e,this.i=s.encoding||"UTF8",this.numRounds=s.numRounds||1,isNaN(this.numRounds)||this.numRounds!==parseInt(this.numRounds,10)||1>this.numRounds)throw new Error("numRounds must a integer >= 1");this.o=t,this.h=[],this.u=0,this.l=!1,this.A=0,this.p=!1,this.U=[],this.R=[]}update(t){let e,r=0;const s=this.T>>>5,n=this.F(t,this.h,this.u),l=n.binLen,i=n.value,a=l>>>5;for(e=0;e<a;e+=s)r+this.T<=l&&(this.m=this.g(i.slice(e,e+s),this.m),r+=this.T);return this.A+=r,this.h=i.slice(r>>>5),this.u=l%this.T,this.l=!0,this}getHash(t,e){let r,s,n=this.H;const l=m(e);if(this.B){if(-1===l.outputLen)throw new Error("Output length must be specified in options");n=l.outputLen}const i=d(t,n,this.v,l);if(this.p&&this.C)return i(this.C(l));for(s=this.Y(this.h.slice(),this.u,this.A,this.S(this.m),n),r=1;r<this.numRounds;r+=1)this.B&&n%32!=0&&(s[s.length-1]&=16777215>>>24-n%32),s=this.Y(s,n,0,this.I(this.o),n);return i(s)}setHMACKey(t,e,r){if(!this.L)throw new Error("Variant does not support HMAC");if(this.l)throw new Error("Cannot set MAC key after calling update");const s=c(e,(r||{}).encoding||"UTF8",this.v);this.M(s(t))}M(t){const e=this.T>>>3,r=e/4-1;let s;if(1!==this.numRounds)throw new Error("Cannot set numRounds with MAC");if(this.p)throw new Error("MAC key already set");for(e<t.binLen/8&&(t.value=this.Y(t.value,t.binLen,0,this.I(this.o),this.H));t.value.length<=r;)t.value.push(0);for(s=0;s<=r;s+=1)this.U[s]=909522486^t.value[s],this.R[s]=1549556828^t.value[s];this.m=this.g(this.U,this.m),this.A=this.T,this.p=!0}getHMAC(t,e){const r=m(e);return d(t,this.H,this.v,r)(this.N())}N(){let t;if(!this.p)throw new Error("Cannot call getHMAC without first setting MAC key");const e=this.Y(this.h.slice(),this.u,this.A,this.S(this.m),this.H);return t=this.g(this.R,this.I(this.o)),t=this.Y(e,this.H,this.T,t,this.H),t}}function y(t,e){return t>>>e|t<<32-e}function b(t,e){return t>>>e}function w(t,e,r){return t&e^~t&r}function v(t,e,r){return t&e^t&r^e&r}function A(t){return y(t,2)^y(t,13)^y(t,22)}function E(t,e){const r=(65535&t)+(65535&e);return(65535&(t>>>16)+(e>>>16)+(r>>>16))<<16|65535&r}function T(t,e,r,s){const n=(65535&t)+(65535&e)+(65535&r)+(65535&s);return(65535&(t>>>16)+(e>>>16)+(r>>>16)+(s>>>16)+(n>>>16))<<16|65535&n}function R(t,e,r,s,n){const l=(65535&t)+(65535&e)+(65535&r)+(65535&s)+(65535&n);return(65535&(t>>>16)+(e>>>16)+(r>>>16)+(s>>>16)+(n>>>16)+(l>>>16))<<16|65535&l}function U(t){return y(t,7)^y(t,18)^b(t,3)}function k(t){return y(t,6)^y(t,11)^y(t,25)}function S(t){let e;return e="SHA-224"==t?f.slice():g.slice(),e}function L(t,e){let r,s,n,l,i,a,o,u,h,c,d;const f=[];for(r=e[0],s=e[1],n=e[2],l=e[3],i=e[4],a=e[5],o=e[6],u=e[7],d=0;d<64;d+=1)f[d]=d<16?t[d]:T(y(g=f[d-2],17)^y(g,19)^b(g,10),f[d-7],U(f[d-15]),f[d-16]),h=R(u,k(i),w(i,a,o),p[d],f[d]),c=E(A(r),v(r,s,n)),u=o,o=a,a=i,i=E(l,h),l=n,n=s,s=r,r=E(h,c);var g;return e[0]=E(r,e[0]),e[1]=E(s,e[1]),e[2]=E(n,e[2]),e[3]=E(l,e[3]),e[4]=E(i,e[4]),e[5]=E(a,e[5]),e[6]=E(o,e[6]),e[7]=E(u,e[7]),e}class B extends _{constructor(t,e,r){if("SHA-224"!==t&&"SHA-256"!==t)throw new Error("Chosen SHA variant is not supported");super(t,e,r);const s=r||{};this.C=this.N,this.L=!0,this.v=-1,this.F=c(this.t,this.i,this.v),this.g=L,this.S=function(t){return t.slice()},this.I=S,this.Y=function(e,r,s,n){return function(t,e,r,s,n){let l,i;const a=15+(e+65>>>9<<4),o=e+r;for(;t.length<=a;)t.push(0);for(t[e>>>5]|=128<<24-e%32,t[a]=4294967295&o,t[a-1]=o/4294967296|0,l=0;l<t.length;l+=16)s=L(t.slice(l,l+16),s);return i="SHA-224"===n?[s[0],s[1],s[2],s[3],s[4],s[5],s[6]]:s,i}(e,r,s,n,t)},this.m=S(t),this.T=512,this.H="SHA-224"===t?224:256,this.B=!1,s.hmacKey&&this.M(function(t,e,r,s){const n="hmacKey must include a value and format";if(!e)throw new Error(n);if(void 0===e.value||!e.format)throw new Error(n);return c(e.format,e.encoding||"UTF8",r)(e.value)}(0,s.hmacKey,this.v))}}function C(t,e){let r="javascript-ampache query URL";e.useBearerToken&&(r="(Using Bearer token, auth added for debugging) - "+r,t+="&auth="+e.sessionKey),console.debug(r+" %c"+t,"color: black; font-style: italic; background-color: orange;padding: 2px")}const H={handshake(t){let e=t.auth;t.timestamp||(t.timestamp=Math.floor((new Date).getTime()/1e3)),t.version&&(this.version=t.version),t.user||delete t.timestamp,this.useBearerToken&&delete t.auth;let r=this.url+"/server/json.server.php?action=handshake";return r+=n(t,"&"),this.debug&&C(r,this),i(r,{method:"GET",headers:this.useBearerToken?{Authorization:"Bearer "+e}:{}}).then(t=>t.json()).then(t=>(t.auth&&(this.sessionKey=t.auth),t))},ping(t){return this.call("ping",t)},goodbye(t){return this.call("goodbye",t)},lostPassword(t){return this.call("lost_password",t)},encryptPassword:t=>function(t,e){let r=s(t);return s(e+r);function s(t){let e=new B("SHA-256","TEXT",{encoding:"UTF8"});return e.update(t),e.getHash("HEX")}}(t.password,t.time)},F={bookmark(t){return this.call("bookmark",t)},bookmarks(t){return this.call("bookmarks",t)},getBookmark(t){return this.call("get_bookmark",t)},bookmarkCreate(t){return this.call("bookmark_create",t)},bookmarkEdit(t){return this.call("bookmark_edit",t)},bookmarkDelete(t){return this.call("bookmark_delete",t)}},P={catalogs(t){return this.call("catalogs",t)},catalog(t){return this.call("catalog",t)},catalogAction(t){return this.call("catalog_action",t)},catalogFile(t){return this.call("catalog_file",t)},catalogFolder(t){return this.call("catalog_folder",t)},catalogAdd(t){return this.call("catalog_add",t)},catalogDelete(t){return this.call("catalog_delete",t)}},x={genres(t){return this.call("genres",t)},genre(t){return this.call("genre",t)}},Y={labels(t){return this.call("labels",t)},label(t){return this.call("label",t)}},I={licenses(t){return this.call("licenses",t)},license(t){return this.call("license",t)}},N={liveStreams(t){return this.call("live_streams",t)},liveStream(t){return this.call("live_stream",t)},liveStreamCreate(t){return this.call("live_stream_create",t)},liveStreamEdit(t){return this.call("live_stream_edit",t)},liveStreamDelete(t){return this.call("live_stream_delete",t)}},M={playlists(t){return this.call("playlists",t)},smartlists(t){return this.call("smartlists",t)},playlist(t){return this.call("playlist",t)},smartlist(t){return this.call("smartlist",t)},userPlaylists(t){return this.call("user_playlists",t)},userSmartlists(t){return this.call("user_smartlists",t)},playlistCreate(t){return this.call("playlist_create",t)},playlistAdd(t){return this.call("playlist_add",t)},playlistEdit(t){return this.call("playlist_edit",t)},playlistDelete(t){return this.call("playlist_delete",t)},smartlistDelete(t){return this.call("smartlist_delete",t)},playlistAddSong(t){return this.call("playlist_add_song",t)},playlistRemoveSong(t){return this.call("playlist_remove_song",t)},playlistGenerate(t){return this.call("playlist_generate",t)},playlistHash(t){return this.call("playlist_hash",t)}},K={podcasts(t){return this.call("podcasts",t)},podcast(t){return this.call("podcast",t)},podcastCreate(t){return this.call("podcast_create",t)},podcastEdit(t){return this.call("podcast_edit",t)},podcastDelete(t){return this.call("podcast_delete",t)},podcastEpisodes(t){return this.call("podcast_episodes",t)},podcastEpisode(t){return this.call("podcast_episode",t)},podcastEpisodeDelete(t){return this.call("podcast_episode_delete",t)},updatePodcast(t){return this.call("update_podcast",t)},deletedPodcastEpisodes(t){return this.call("deleted_podcast_episodes",t)}},j={systemPreferences(){return this.call("system_preferences")},systemPreference(t){return this.call("system_preference",t)},userPreferences(){return this.call("user_preferences")},userPreference(t){return this.call("user_preference",t)},preferenceCreate(t){return this.call("preference_create",t)},preferenceEdit(t){return this.call("preference_edit",t)},preferenceDelete(t){return this.call("preference_delete",t)}},D={shares(t){return this.call("shares",t)},share(t){return this.call("share",t)},shareCreate(t){return this.call("share_create",t)},shareEdit(t){return this.call("share_edit",t)},shareDelete(t){return this.call("share_delete",t)}},q={last_shouts(t){return this.call("last_shouts",t)}},X={songs(t){return this.call("songs",t)},song(t){return this.call("song",t)},artistSongs(t){return this.call("artist_songs",t)},albumSongs(t){return this.call("album_songs",t)},genreSongs(t){return this.call("genre_songs",t)},playlistSongs(t){return this.call("playlist_songs",t)},smartlistSongs(t){return this.call("smartlist_songs",t)},licenseSongs(t){return this.call("license_songs",t)},songDelete(t){return this.call("song_delete",t)},songTags(t){return this.call("song_tags",t)},getLyrics(t){return this.call("get_lyrics",t)},urlToSong(t){let e="url_to_song";const r={...t};return null!=r.url&&(r.url=encodeURIComponent(r.url)),e+=n(r,"&"),this.request(e)},searchSongs(t){return this.call("search_songs",t)},deletedSongs(t){return this.call("deleted_songs",t)}},O=new Set(["song","album","artist","album_artist","song_artist","playlist","podcast","podcast_episode","live_stream","catalog"]),G=new Set(["song","artist"]),z=new Set(["song","album","artist","video","playlist","podcast","podcast_episode"]),V=new Set(["song","album","artist","album_artist","song_artist","label","playlist","podcast","podcast_episode","genre","user","video"]),J={systemUpdate(){return this.call("system_update")},getIndexes(t){if(!O.has(t.type))return!1;const e="get_indexes"+n(t,"&");return this.request(e)},list(t){return this.call("list",t)},index(t){return this.call("index",t)},browse(t){return this.call("browse",t)},getSimilar(t){if(!G.has(t.type))return!1;const e="get_similar"+n(t,"&");return this.request(e)},stats(t){if(!z.has(t.type))return!1;const e="stats"+n(t,"&");return this.request(e)},rate(t){return this.call("rate",t)},flag(t){return this.call("flag",t)},recordPlay(t){return this.call("record_play",t)},scrobble(t){return this.call("scrobble",t)},updateFromTags(t){return this.call("update_from_tags",t)},updateArtistInfo(t){return this.call("update_artist_info",t)},updateArt(t){return this.call("update_art",t)},stream(t){const e="stream"+(null!=t?n(t,"&"):"");return this.binary(e)},download(t){const e="download"+(null!=t?n(t,"&"):"");return this.binary(e)},getArt(t){const e="get_art"+(null!=t?n(t,"&"):"");return this.binary(e)},localplay(t){return this.call("localplay",t)},localplaySongs(){return this.call("localplay_songs")},democratic(t){return this.call("democratic",t)},nowPlaying(){return this.call("now_playing")},player(t){return this.call("player",t)},getExternalMetadata(t){return this.call("get_external_metadata",t)},searchRules(t){return this.call("search_rules",t)},advancedSearch(t){for(let e=0;e<t.rules.length;e++){const r=t.rules[e],s=e+1;t["rule_"+s]=r[0],t["rule_"+s+"_operator"]=r[1],t["rule_"+s+"_input"]=r[2],"metadata"===r[0]&&(t["rule_"+s+"_subtype"]=r[3])}if(delete t.rules,!V.has(t.type))return!1;const e="advanced_search"+n(t,"&");return this.request(e)},search(t){return this.advancedSearch(t)},searchGroup(t){for(let e=0;e<t.rules.length;e++){const r=t.rules[e],s=e+1;t["rule_"+s]=r[0],t["rule_"+s+"_operator"]=r[1],t["rule_"+s+"_input"]=r[2],"metadata"===r[0]&&(t["rule_"+s+"_subtype"]=r[3])}delete t.rules;const e="search_group"+n(t,"&");return this.request(e)}},Z={users(){return this.call("users")},user(t){return this.call("user",t)},userCreate(t){return this.call("user_create",t)},register(t){return this.call("register",t)},userUpdate(t){return this.call("user_update",t)},userEdit(t){return this.call("user_edit",t)},userDelete(t){return this.call("user_delete",t)},followers(t){return this.call("followers",t)},following(t){return this.call("following",t)},toggleFollow(t){return this.call("toggle_follow",t)},timeline(t){return this.call("timeline",t)},friendsTimeline(t){return this.call("friends_timeline",t)}},$={videos(t){return this.call("videos",t)},video(t){return this.call("video",t)},deletedVideos(t){return this.call("deleted_videos",t)}};class Q{constructor(t){this.sessionKey=t.sessionKey||null,this.url=t.url,this.version="6.6.8",this.useBearerToken=t.useBearerToken||!1,this.debug=t.debug||!1}call(t,e){const r=t+(null!=e?n(e,"&"):"");return this.request(r)}_buildURL(t){let e=this.url+"/server/json.server.php?action="+t+"&version="+this.version;return this.useBearerToken||(e+="&auth="+this.sessionKey),this.debug&&C(e,this),e}request(t){const e=this._buildURL(t);return i(e,{method:"GET",headers:this.useBearerToken?{Authorization:"Bearer "+this.sessionKey}:{}}).then(function(t){try{function e(){const e=new Error(t.statusText);throw e.status=t.status,e.body=r,e}if(t.ok)return Promise.resolve(t.json());let r=t.statusText;const s=t.headers.get("content-type"),n=function(t,e){try{var r=t()}catch(t){return}return r&&r.then?r.then(void 0,function(){}):r}(function(){return Promise.resolve(s&&s.includes("application/json")?t.json():t.text()).then(function(t){r=t})});return Promise.resolve(n&&n.then?n.then(e):e())}catch(l){return Promise.reject(l)}})}binary(t){const e=this._buildURL(t);return i(e,{method:"GET",headers:this.useBearerToken?{Authorization:"Bearer "+this.sessionKey}:{}}).then(t=>t.blob())}setSessionKey(t){this.sessionKey=t}rawURL(t,e){const r=t+(null!=e?n(e,"&"):"");return this._buildURL(r)}}class W extends Q{}Object.assign(W.prototype,t,e,H,F,P,x,Y,I,N,M,K,j,D,q,X,J,Z,$),module.exports=W;
//# sourceMappingURL=index.js.map