From 35074b4dfc577093356cd6652bd509b1d42e1fa2 Mon Sep 17 00:00:00 2001 From: NiceygyLive Date: Thu, 1 Feb 2024 14:54:04 +0000 Subject: [PATCH] move visits recorder to one script (and bug squash) --- bun.lockb | Bin 0 -> 38711 bytes src/worker.js | 215 +++++++++++++++++++++++++++++++++----------------- wrangler.toml | 3 +- 3 files changed, 144 insertions(+), 74 deletions(-) create mode 100755 bun.lockb diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000000000000000000000000000000000000..1f75cd8ee017b61ed24375f780a7368ae30f4a13 GIT binary patch literal 38711 zcmeHw2{={38~3HFq#{yE5$)nyt|dE_6rmzfqAo73aCPssq!JPBkyP5Klr2d`h4!?o zv65_ z1uD1(_=$n1`LNvRI%_J-^inLP>~!4k1cc=|iEwWtbG?L-KK$ zT((ajlQIZ|L-mn>5a~$>LiiWv#o)4o{3sMV$PCahD&SDOAH$E$0+lnlt^q6`cZwt^ z73sAV3hM{qO9+u(OCdz@7XiG6ncp2oc_w<;#Ri ziVk>GKER0nA#u%Afx2&YV3nCSZ=3Ou`r|RnWmddh`RH*WCEPkeFNUV`^wnguWoIXs z6xtepoY4Q^Ma3OOf%8vSnN&SLZn3|p`gNY{8HJYOac9@$Zl3t$rfcAnWA8?7s;g0C z8AlIGGxNwYcI($)>0sQQH@vppTh#6K=jn0T#=qsm}j1gG$+(Up<+CnmPO z5pU1wt`|}kof4ZUelvU1s$1&vi3ftUgGIkwK?lX_S!`-QnaK@t2Cs*EuiLhACG~*UJW2iF=bL%&cbk09cOCGxr^Ha{&pz|_d@G4P zF@CJn7)_xyPj?sZ?kjg;OzpG`bCxs5Wb}?bX`$Y4MMvI#5aD62vAO&#>x5ydR(Ic; zbCkD}N7V|O_K`8G-E}bVlKO;g^Nw|w5Z*OdJ?~Df+nj-4zG&E9)nVEi-%=hTCz*1& z$Mh}cFMQ8=o>}cY*hDRF*w8J5$M%n{%h`6&-h>Ax1juctVOypY^*B+qW#eXkzp#zE10gUPoL=f;N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~#s&&l7;PT|*7f#MJS?{rS%d&fB9L<2xX2qmEd$&L}k=?EZ*5T-%RP9LJaXiD?t z68i6qz5Rg?nD!f(4&ix?Btx?v5#PZGCeqvR#7P~oZs`DG>ej(31gJ>QNx{+t)C~~xQl$@*}Q;DgFQ}1L$DJhNYP0SqBnLn z!L~~ZgzYy3c3dY4{=UwD|2_gusGavc{@E*l`4>c+5JGzd__^^|Y(E+_j(Z2K@?AdQ z`R*R-0d3StJ-*+#Vm-9&WNGN3Lv(-CP5A%YPt~o%ttCGbF!3*lof)A`#30yxcTgok z4#4A`It(B5_6}79@5|L-GtXhO+|f$*S8=d{#XLA?Fe#3_1ZvADh$QFpfR7|xxkM=> zG>#?bOh>f>)$0IwF%IW?tYi3y}f~_ z{pNRR_}vhi6F!U7uuz!lkMu+WlcWNwE=q;J1_Cg?goOvZ8A7WDVz&<~ zQl=jdR%x&dVQ?1F(89-$&GCg3yAURE*TM4zzZe91dKqWh<8mVsp2k8#>S)H$* z`LC=|;pl|}muL)P#f@Gf(Krl0Pi6;Yw`T%|_8S`UUKh!Ym*JfNKLG)mTsWSCJu2~T7Qe}3`}hR-3z%sH0e(l=QUBz000TifN+#qX z+UomUEI)6i8?S@j^sDSYmBnXi@2Bt{7WO#&w|FoYda~RE_5Y3yz2N9_b&1SB7EDA! zYr?mDo%Dt8Bm$c6?m;>5AwVY#`ZL*0R>=D z(EjLxsT)qY`Clb;&=BpP3;;v>4a{zWcfTEA$#wbeI|QKm?jF58Y b.count - a.count); // Sort repos by count in descending order + //PAGE VISITS ######################################################################## + + const Plist = await KV2.list(); + console.log("Key list aquired for pages"); + var total = 0; + var i = 0; + var len = Plist.keys.length; + for (const { name, expiration } of Plist.keys) { + i++; + console.log(`Getting value for ${name} (${i}/${len})`); + const value = await KV2.get(name); + if (name == "total" | name == undefined | name == "undefined") { + console.log("Invalid page, skipping"); + } else { + pages.push({ name: name, count: parseInt(value) }); + total += parseInt(value); + } + } + pages.sort((a, b) => b.count - a.count); // Sort repos by count in descending order let currentDate = new Date(); - + var message = "# Downloads as of " + currentDate.toUTCString() + "\n\n" + repos.map(repo => `Repo: ${repo.name}, Count: ${repo.count}\n`).join(""); var message = message + "\n\nTotal downloads: " + total; + var message = message + "\n\n# Page visits as of " + currentDate.toUTCString() + "\n\n" + pages.map(page => `Page: ${page.name}, Count: ${page.count}\n`).join(""); + var message = message + "\n\nTotal page visits: " + total; console.log("Message generated. Sending to Discord..."); console.log(message); - + if (sendMsg == false) { - await fetch(webhookURL, { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - content: message, - }), - }) - .then((response) => console.log(response)) - .catch((error) => console.error(error)); - console.log("Message sent to Discord"); - return "Complete! Message sent."; -} else { - console.log("Returning mesage"); - return message; + await fetch(webhookURL, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + content: message, + }), + }) + .then((response) => console.log(response)) + .catch((error) => console.error(error)); + console.log("Message sent to Discord"); + return "Complete! Message sent."; + } else { + console.log("Returning mesage"); + return message; + } } + +/** + * Function for recording a download. + * @param {URL} url The requested url. From request.url + * @param {env} env The ENV object, used for KV + * @returns Error or redirect + */ +async function recordDownload(url, env) { + print("Recording download"); + const KV = env.WDR; + console.log("Handling request for " + url); + const packNameRaw = url.split("/reder?url=")[1]; //pack name will include username, e.g niceygylive/example + const fileName = url.split("?file=")[1]; //e.g V1.1.2/download.zip + var packName = packNameRaw.split("?file=")[0]; //e.g niceygylive/example + if (packName == undefined | fileName == undefined) { + console.log("Invalid request, redirecting to 404") + return Response.redirect("https://thealiendoctor.com/404", 301); + } + + console.log("Parsed! Pack name is " + packName + " and file name is " + fileName); + + var oldNum = await KV.get(packName); + if (oldNum / oldNum != 1) { + console.log("Repo not found in KV"); + await KV.put(packName, 1); + console.log(packName + " added to KV"); + } else { + console.log("Found in KV"); + var newCount = oldNum * 1 + 1; + await KV.put(packName, newCount); + console.log(packName + " now has " + newCount + " downloads"); + } + + let oldTotal = await KV.get("total"); + await KV.put("total", oldTotal * 1 + 1);//for *1 is to make sure it is treated as a number + + // Redirect the user to the requested URL. + console.log("Redirecting the user to https://github.com/" + packName + "/releases/download/" + fileName) + return Response.redirect( + "https://github.com/" + packName + "/releases/download/" + fileName, + 301, + { + headers: { + "Cache-Control": "no-store", + }, + } + ); } +/** + * The function for recording a visit to a page. + * @param {string} url The url from request.url + * @param {object} env The ENV object, used for KV + * @returns Error or redirect + */ +async function recordVisit(url, env) { + let page = url.split("?page=")[1]; + if (page == void 0) { + return new Response("No page specified", { status: 400 }); + } + let count = await env.WVR.get(page); + if (count == null) { + count = 0; + } + count++; + await env.WVR.put(page, count); + return new Response("OK", { status: 200 }); +} export default { async fetch(request, env, ctx) { console.log("Worker is running..."); - console.log("Processing request for " + request.url) + console.log("Processing request for " + request.url); const url = request.url; - if (url.includes("testCron")) { console.log("testing cron func"); return new Response(await cron(env, true));} - if (url.includes("favicon.ico")) { - return new Response(null, { status: 404 }); + if (url.includes("test/cron")) { return new Response(await cron(env, true, false)) } + if (url.includes("test/db")) { return new Response(await cron(env, true, true)) } + if (url.includes("favicon.ico")) { return new Response(null, { status: 404 }) } + if (url.length < 1 | url == void 0) { + console.log("Invalid request, redirecting to 404"); + return Response.redirect("https://thealiendoctor.com/404", 301); } - if (url.length < 1 | url == undefined | url == "http://127.0.0.1:8787/") { //for local testing - console.log("Invalid request, redirecting to 404") - return await Response.redirect( - "https://thealiendoctor.com/404", 301 - ); - } - const KV = env.KV; - console.log("Handling request for " + url); - const packNameRaw = url.split("/reder?url=")[1]; //pack name will include username, e.g niceygylive/example - const fileName = url.split("?file=")[1]; //e.g V1.1.2/download.zip - var packName = packNameRaw.split("?file=")[0]; //e.g niceygylive/example - if (packName == undefined | fileName == undefined) { - console.log("Invalid request, redirecting to 404") - return await Response.redirect( - "https://thealiendoctor.com/404", 301 - ); - - } - console.log("Parsed! Pack name is " + packName + " and file name is " + fileName); - - var oldNum = await KV.get(packName); - if (oldNum / oldNum != 1) { - console.log("Repo not found in KV"); - await KV.put(packName, 1); - console.log(packName + " added to KV"); + if (url.includes("/reder?url=")) { + console.log("Request is for a download."); + return await recordDownload(request, env); + } else if (url.includes("?page=")) { + console.log("Request is for a page."); + recordVisit(url, env); } else { - console.log("Found in KV"); - var newCount = oldNum * 1 + 1; - await KV.put(packName, newCount); - console.log(packName + " now has " + newCount + " downloads"); + console.log("Invalid request, redirecting to 404"); + return Response.redirect("https://thealiendoctor.com/404", 301); } - let oldTotal = await KV.get("total"); - await KV.put("total", oldTotal * 1 + 1); - - // Redirect the user to the recorded URL. - console.log("Redirecting the user to https://github.com/" + packName + "/releases/download/" + fileName) - return await Response.redirect( - "https://github.com/" + packName + "/releases/download/" + fileName, - 301, - { - headers: { - "Cache-Control": "no-store", - }, - } - ); }, async scheduled(event, env, ctx) { ctx.waitUntil(cron(env, false)); - }, + } }; diff --git a/wrangler.toml b/wrangler.toml index e0bb66f..04cdfd4 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -3,7 +3,8 @@ main = "src/worker.js" compatibility_date = "2023-09-24" kv_namespaces = [ - { binding = "KV", id = "c25ceddd69d046ffb315f74ed1f3de33" } + { binding = "WDR", id = "c25ceddd69d046ffb315f74ed1f3de33" }, + { binding = "WVR", id = "8946e1721893497689df9b9e99a5ded2" } ] [triggers]