Web-Archives-Misc/public/Archive/retrogamesbot.com/20.chunk.js
2023-01-16 18:46:17 +01:00

1 line
9.6 KiB
JavaScript

(window.webpackJsonp=window.webpackJsonp||[]).push([[20],{25:function(t,e,n){"use strict";n.d(e,"a",(function(){return d}));var r=n(4),o=n(9);class s{constructor(t,e,n,r){this._name=t,this._size=e,this._path=n,this._archiveRef=r}get name(){return this._name}get size(){return this._size}extract(){return this._archiveRef.extractSingleFile(this._path)}}class i{static init(t={}){return i._options={workerUrl:"../dist/worker-bundle.js",...t},i._options}static open(t,e=null){e=e||i._options||i.init()&&console.warn("Automatically initializing using options: ",i._options);return new i(t,e).open()}constructor(t,e){this._worker=n(48)(),this._worker.addEventListener("message",this._workerMsg.bind(this)),this._callbacks=[],this._content={},this._processed=0,this._file=t}async open(){return await this._postMessage({type:"HELLO"},(t,e,n)=>{"READY"===n.type&&t()}),await this._postMessage({type:"OPEN",file:this._file},(t,e,n)=>{"OPENED"===n.type&&t(this)})}close(){this._worker.terminate(),this._worker=null}hasEncryptedData(){return this._postMessage({type:"CHECK_ENCRYPTION"},(t,e,n)=>{"ENCRYPTION_STATUS"===n.type&&t(n.status)})}usePassword(t){return this._postMessage({type:"SET_PASSPHRASE",passphrase:t},(t,e,n)=>{"PASSPHRASE_STATUS"===n.type&&t(n.status)})}getFilesObject(){return this._processed>0?Promise.resolve().then(()=>this._content):this._postMessage({type:"LIST_FILES"},(t,e,n)=>{if("ENTRY"===n.type){const t=n.entry,[e,r]=this._getProp(this._content,t.path);return"FILE"===t.type&&(e[r]=new s(t.fileName,t.size,t.path,this)),!0}"END"===n.type&&(this._processed=1,t(this._cloneContent(this._content)))})}getFilesArray(){return this.getFilesObject().then(t=>this._objectToArray(t))}extractSingleFile(t){if(null===this._worker)throw new Error("Archive already closed");return this._postMessage({type:"EXTRACT_SINGLE_FILE",target:t},(t,e,n)=>{if("FILE"===n.type){t(new File([n.entry.fileData],n.entry.fileName,{type:"application/octet-stream"}))}})}extractFiles(t){return this._processed>1?Promise.resolve().then(()=>this._content):this._postMessage({type:"EXTRACT_FILES"},(e,n,r)=>{if("ENTRY"===r.type){const[e,n]=this._getProp(this._content,r.entry.path);return"FILE"===r.entry.type&&(e[n]=new File([r.entry.fileData],r.entry.fileName,{type:"application/octet-stream"}),void 0!==t&&setTimeout(t.bind(null,{file:e[n],path:r.entry.path}))),!0}"END"===r.type&&(this._processed=2,this._worker.terminate(),e(this._cloneContent(this._content)))})}_cloneContent(t){if(t instanceof File||t instanceof s||null===t)return t;const e={};for(const n of Object.keys(t))e[n]=this._cloneContent(t[n]);return e}_objectToArray(t,e=""){const n=[];for(const r of Object.keys(t))t[r]instanceof File||t[r]instanceof s||null===t[r]?n.push({file:t[r]||r,path:e}):n.push(...this._objectToArray(t[r],`${e}${r}/`));return n}_getProp(t,e){const n=e.split("/");""===n[n.length-1]&&n.pop();let r=t,o=null;for(const t of n)r[t]=r[t]||{},o=r,r=r[t];return[o,n[n.length-1]]}_postMessage(t,e){return this._worker.postMessage(t),new Promise((t,n)=>{this._callbacks.push(this._msgHandler.bind(this,e,t,n))})}_msgHandler(t,e,n,r){if("BUSY"===r.type)n("worker is busy");else{if("ERROR"!==r.type)return t(e,n,r);n(r.error)}}_workerMsg({data:t}){(0,this._callbacks[this._callbacks.length-1])(t)||this._callbacks.pop()}}var a=[],c=function(t,e,n,r){return new(n||(n=Promise))((function(o,s){function i(t){try{c(r.next(t))}catch(t){s(t)}}function a(t){try{c(r.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(i,a)}c((r=r.apply(t,e||[])).next())}))},u=function(t,e){var n,r,o,s,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(s){return function(a){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,r=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=e.call(t,i)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}};i.init();var l={smc:"snes",sfc:"snes",bin:"genesis",smd:"genesis",a26:"stella"};function h(t){return c(this,void 0,void 0,(function(){return u(this,(function(e){switch(e.label){case 0:return[4,Object(r.request)({url:t,method:"GET",responseType:"blob"})];case 1:return[2,p(e.sent())]}}))}))}function p(t){return c(this,void 0,void 0,(function(){var e,n,r,o,s,a;return u(this,(function(c){switch(c.label){case 0:return[4,i.open(t)];case 1:return[4,(e=c.sent()).extractFiles()];case 2:for(s in n=c.sent())if(n[s]instanceof File){r=n[s],o=s;break}return e.close(),a={name:o},[4,f(r)];case 3:return[2,(a.data=c.sent(),a)]}}))}))}function f(t){return new Promise((function(e,n){var r=new FileReader;r.onload=function(){return e(r.result)},r.onerror=n,r.readAsArrayBuffer(t)}))}function _(t){for(var e,n=t.length-1;n>0;n--){var r=Math.floor(Math.random()*(n+1));e=[t[r],t[n]],t[n]=e[0],t[r]=e[1]}}var d=new(function(){function t(){}return t.prototype.getROM=function(t){var e;return c(this,void 0,void 0,(function(){var n;return u(this,(function(o){switch(o.label){case 0:return this._token===t&&this._rom?[2,this._rom]:(this._token=t,n=this,[4,Object(r.request)({method:"GET",url:"https://europe-west3-retro-games-257212.cloudfunctions.net/session/"+t})]);case 1:if(n._rom=o.sent(),!(null===(e=this._rom)||void 0===e?void 0:e.url))throw new Error("invalid token");return[2,this.loadRom(this._rom)]}}))}))},t.prototype.loadRom=function(t){return c(this,void 0,void 0,(function(){var e,n;return u(this,(function(r){switch(r.label){case 0:return e=this,[4,h(t.url)];case 1:return e._rom=r.sent(),this._rom.platform=t.platform,Object(o.f)(this._rom.platform)&&(n=Object(o.d)(this._rom.name),this._rom.platform=l[n]||n),this._rom.platform=this._rom.platform.toLowerCase(),[2,this._rom]}}))}))},t.prototype.loadSearchRom=function(t){return c(this,void 0,void 0,(function(){return u(this,(function(e){switch(e.label){case 0:return this._token="local",[4,this.loadRom(t)];case 1:return e.sent(),[2]}}))}))},t.prototype.loadLocalFile=function(t){return c(this,void 0,void 0,(function(){var e,n,r,s,i;return u(this,(function(a){switch(a.label){case 0:return e=t.name.split(".")[0],"zip"!==(n=Object(o.d)(t.name))&&"7z"!==n&&"rar"!==n?[3,2]:(r=this,[4,p(t)]);case 1:return r._rom=a.sent(),n=Object(o.d)(this._rom.name),[3,4];case 2:return s=this,i={name:e},[4,f(t)];case 3:s._rom=(i.data=a.sent(),i),a.label=4;case 4:return this._rom.platform=l[n]||n,this._token="local",[2]}}))}))},t.prototype.getPopularRequests=function(){return c(this,void 0,void 0,(function(){return u(this,(function(t){return _(a),[2,a.slice(0,10)]}))}))},t.prototype.getRandomRequest=function(){return c(this,void 0,void 0,(function(){return u(this,(function(t){return _(a),[2,a[0]]}))}))},t}())},299:function(t,e,n){"use strict";n.r(e),n.d(e,"GameComponent",(function(){return u}));var r=n(4),o=n(25),s=n(6),i=function(t,e,n,r){return new(n||(n=Promise))((function(o,s){function i(t){try{c(r.next(t))}catch(t){s(t)}}function a(t){try{c(r.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(i,a)}c((r=r.apply(t,e||[])).next())}))},a=function(t,e){var n,r,o,s,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(s){return function(a){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,r=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=e.call(t,i)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}},c=["gb","gbc","gba","nes","snes","sms","genesis","stella","sgx","ngp"],u=function(){function t(){}return t.prototype.oninit=function(t){return i(this,void 0,void 0,(function(){var e,n,i;return a(this,(function(a){switch(a.label){case 0:e=t.attrs.token,a.label=1;case 1:return a.trys.push([1,3,,4]),[4,o.a.getROM(e)];case 2:return n=a.sent(),[3,4];case 3:return i=a.sent(),console.warn(i),s.a.show('Looks like game session is expired. Please <a href="/">go to start screen</a> to create new game session'),[2];case 4:return"atari2600"===n.platform?n.platform="stella":"pce"===n.platform?n.platform="sgx":"ngc"===n.platform&&(n.platform="ngp"),c.includes(n.platform)?(r.route.set("/"+n.platform+"/"+e),[2]):(s.a.show("Sorry, "+n.platform+" files are not supported for now"),[2])}}))}))},t.prototype.view=function(){},t}()},48:function(t,e,n){t.exports=function(){return new Worker(n.p+"52f0f27e6712ae78b884.worker.js")}}}]);