dzserver/dist/worker.js

3 lines
48 KiB
JavaScript
Raw Normal View History

2021-01-26 11:55:28 +00:00
!function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){const n=r(1),s=r(2);addEventListener("fetch",t=>{t.respondWith(async function(t){const e=new n;e.get("/track/.*",()=>h("track",t)),e.get("/album/.*",()=>h("album",t)),e.get("/playlist/.*",()=>h("playlist",t));return await e.route(t)}(t.request))});const o=[106,111,54,97,101,121,54,104,97,105,100,50,84,101,105,104];const a={64:"10",128:"1",320:"3",flac:"9",misc:"0"};async function h(t,e){if(access_token=await KV.get("access_token"),null===access_token){const t=await fetch("https://connect.deezer.com/oauth/access_token.php?grant_type=client_credentials&client_id=447462&client_secret=a83bf7f38ad2f137e444727cfc3775cf&output=json"),e=await t.json();if(void 0!==e.error)return new Response("Couldn't get access token from Deezer",{status:500,headers:{"content-type":"text/plain"}});access_token=e.access_token,await KV.put("access_token",access_token,{expirationTtl:Number(e.expires)})}const r=new URL(e.url),n=r.pathname.split("/")[2];if(""===n)return new Response("ID needs to be specified",{status:400,headers:{"content-type":"text/plain"}});if(format=r.searchParams.get("f"),null===format)"-"!==n[0]?format="320":format="misc";else if(format=format.toLowerCase(),void 0===a[format]){if(index=Object.values(a).indexOf(format),-1===index)return new Response("Invalid format",{status:400,headers:{"content-type":"text/plain"}});format=Object.keys(a)[index]}switch(t){case"track":return await async function(t,e,r){const n=await fetch(`https://api.deezer.com/track/${t}?access_token=${r}`),i=await n.json();if(void 0!==i.error)return new Response(JSON.stringify(i.error),{status:403,headers:{"content-type":"application/json"}});if(result=await c(i,e),"object"==typeof result)return result;return new Response(null,{status:302,headers:{location:result}})}(n,format,access_token);case"album":case"playlist":return await async function(t,e,r,n){const i=await fetch(`https://api.deezer.com/${t}/${e}?access_token=${n}&limit=-1`),s=await i.json();if(void 0!==s.error)return new Response(JSON.stringify(s.error),{status:403,headers:{"content-type":"application/json"}});var o="#EXTM3U\n";for(const t of s.tracks.data){const e=await c(t,r);if("object"==typeof e)return e;o+=`#EXTINF:${t.duration},${t.title}\n${e}\n`}return new Response(o,{status:200,headers:{"content-type":"audio/mpegurl"}})}(t,n,format,access_token)}}async function c(t,e){const r=t.id,n=t.md5_origin,h=t.media_version;return"0"===t["filesize_"+e]?new Response("Format unavailable",{status:403,headers:{"content-type":"text/plain"}}):(e=a[e],await async function(t,e,r,n){const a=new s.ModeOfOperation.ecb(o);for(result=[t,e,r,n].join("¤"),buf=new ArrayBuffer(result.length),result_hash=new Uint8Array(buf),i=0;i<result.length;i++)result_hash[i]=result.charCodeAt(i);return result_hash=await crypto.subtle.digest("MD5",result_hash),result_hash=Array.from(new Uint8Array(result_hash)),result_hash=result_hash.reduce((function(t,e){return t+"0".concat(e.toString(16)).substr(-2,2)}),""),result=result_hash+"¤"+result+"¤",result+="\0".repeat(result.length%16?16-result.length%16:0),result=Array.from(result).map((function(t){return t.charCodeAt(0)})),result=(result=a.encrypt(result)).reduce((function
2021-01-25 00:39:01 +00:00
/*! MIT License. Copyright 2015-2018 Richard Moore <me@ricmoo.com>. See LICENSE.txt. */
2021-01-26 11:55:28 +00:00
!function(e){"use strict";function r(t){return parseInt(t)===t}function n(t){if(!r(t.length))return!1;for(var e=0;e<t.length;e++)if(!r(t[e])||t[e]<0||t[e]>255)return!1;return!0}function i(t,e){if(t.buffer&&"Uint8Array"===t.name)return e&&(t=t.slice?t.slice():Array.prototype.slice.call(t)),t;if(Array.isArray(t)){if(!n(t))throw new Error("Array contains invalid value: "+t);return new Uint8Array(t)}if(r(t.length)&&n(t))return new Uint8Array(t);throw new Error("unsupported array-like object")}function s(t){return new Uint8Array(t)}function o(t,e,r,n,i){null==n&&null==i||(t=t.slice?t.slice(n,i):Array.prototype.slice.call(t,n,i)),e.set(t,r)}var a,h={toBytes:function(t){var e=[],r=0;for(t=encodeURI(t);r<t.length;){var n=t.charCodeAt(r++);37===n?(e.push(parseInt(t.substr(r,2),16)),r+=2):e.push(n)}return i(e)},fromBytes:function(t){for(var e=[],r=0;r<t.length;){var n=t[r];n<128?(e.push(String.fromCharCode(n)),r++):n>191&&n<224?(e.push(String.fromCharCode((31&n)<<6|63&t[r+1])),r+=2):(e.push(String.fromCharCode((15&n)<<12|(63&t[r+1])<<6|63&t[r+2])),r+=3)}return e.join("")}},c=(a="0123456789abcdef",{toBytes:function(t){for(var e=[],r=0;r<t.length;r+=2)e.push(parseInt(t.substr(r,2),16));return e},fromBytes:function(t){for(var e=[],r=0;r<t.length;r++){var n=t[r];e.push(a[(240&n)>>4]+a[15&n])}return e.join("")}}),u={16:10,24:12,32:14},l=[1,2,4,8,16,32,64,128,27,54,108,216,171,77,154,47,94,188,99,198,151,53,106,212,179,125,250,239,197,145],f=[99,124,119,123,242,107,111,197,48,1,103,43,254,215,171,118,202,130,201,125,250,89,71,240,173,212,162,175,156,164,114,192,183,253,147,38,54,63,247,204,52,165,229,241,113,216,49,21,4,199,35,195,24,150,5,154,7,18,128,226,235,39,178,117,9,131,44,26,27,110,90,160,82,59,214,179,41,227,47,132,83,209,0,237,32,252,177,91,106,203,190,57,74,76,88,207,208,239,170,251,67,77,51,133,69,249,2,127,80,60,159,168,81,163,64,143,146,157,56,245,188,182,218,33,16,255,243,210,205,12,19,236,95,151,68,23,196,167,126,61,100,93,25,115,96,129,79,220,34,42,144,136,70,238,184,20,222,94,11,219,224,50,58,10,73,6,36,92,194,211,172,98,145,149,228,121,231,200,55,109,141,213,78,169,108,86,244,234,101,122,174,8,186,120,37,46,28,166,180,198,232,221,116,31,75,189,139,138,112,62,181,102,72,3,246,14,97,53,87,185,134,193,29,158,225,248,152,17,105,217,142,148,155,30,135,233,206,85,40,223,140,161,137,13,191,230,66,104,65,153,45,15,176,84,187,22],p=[82,9,106,213,48,54,165,56,191,64,163,158,129,243,215,251,124,227,57,130,155,47,255,135,52,142,67,68,196,222,233,203,84,123,148,50,166,194,35,61,238,76,149,11,66,250,195,78,8,46,161,102,40,217,36,178,118,91,162,73,109,139,209,37,114,248,246,100,134,104,152,22,212,164,92,204,93,101,182,146,108,112,72,80,253,237,185,218,94,21,70,87,167,141,157,132,144,216,171,0,140,188,211,10,247,228,88,5,184,179,69,6,208,44,30,143,202,63,15,2,193,175,189,3,1,19,138,107,58,145,17,65,79,103,220,234,151,242,207,206,240,180,230,115,150,172,116,34,231,173,53,133,226,249,55,232,28,117,223,110,71,241,26,113,29,41,197,137,111,183,98,14,170,24,190,27,252,86,62,75,198,210,121,32,154,219,192,254,120,205,90,244,31,221,168,51,136,7,199,49,177,18,16,89,39,128,236,95,96,81,127,169,25,181,74,13,45,229,122,159,147,201,156,239,160,224,59,77,174,42,245,176,200,235,187,60,131,83,153,97,23,43,4,126,186,119,214,38,225,105,20,99,85,33,12,125],d=[3328402341,4168907908,4000806809,4135287693,4294111757,3597364157,3731845041,2445657428,1613770832,33620227,3462883241,1445669757,3892248089,3050821474,1303096294,3967186586,2412431941,528646813,2311702848,4202528135,4026202645,2992200171,2387036105,4226871307,1101901292,3017069671,1604494077,1169141738,597466303,1403299063,3832705686,2613100635,1974974402,3791519004,1033081774,1277568618,1815492186,2118074177,4126668546,2211236943,1748251740,1369810420,3521504564,4193382664,3799085459,2883115123,1647391059,706024767,134480908,2512897874,1176707941,2646852446,806885416,932615841,168101135,798661301,235341577,605164086,461406363,3756188221,3454790438,1311188841,2142417613,3933566367,302582043,495158174,1479289972,874125870,907746093,3698224818,3025820398,1537253627,2756858614,1983593293,3084310113,