/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/jsnake@1.0.2/server.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
var http=require("http"),fs=require("fs"),url=require("url"),path=require("path"),mimeTypes={".js":"text/javascript",".html":"text/html",".css":"text/css",".jpg":"image/jpeg",".gif":"image/gif",".wav":"audio/wav",".json":"application/json",".ico":"image/gif"};function calculationRank(e){var n,t;(e[1]=+e[1],"string"==typeof e[0]&&"number"==typeof e[1]&&e[1]==e[1])&&(n={rank:11,name:decodeURIComponent(e[0]),score:e[1]},rank=JSON.parse(fs.readFileSync("./db/rank.json",{encoding:"utf-8"})),rank.push(n),rank.sort((t="score",function(e,n){return e[t]<n[t]?1:-1})).forEach((function(e,n){n>0&&(e.rank=n)})),rank=rank.slice(0,11),fs.writeFileSync("./db/rank.json",JSON.stringify(rank),{encoding:"utf-8"}))}http.createServer((function(e,n){var t=url.parse(e.url).pathname;"/"==t&&(t="/index.html");var r=path.extname(t),a=mimeTypes[path.extname(t)];if(t=t.substring(1,t.length),".wav"==r){var i=fs.readFileSync("./"+t);n.writeHead(200,{"Content-Type":a}),n.end(i,"binary")}else if("/submit"==e.url){var s="";e.on("data",(function(e){s+=e})),e.on("end",(function(){calculationRank(s.split(" ")),n.writeHead(200),n.end()}))}else fs.readFile(t,"utf8",(function(e,t){e?console.error("Open file."):(n.writeHead(200,{"Content-Type":a}),n.end(t))}))})).listen(8080);
//# sourceMappingURL=/sm/2ef2f2d84a79527e1bec70b51c5eb07df7327cacffe065227237228222fb5546.map