From 3fe2266e3ef7431fa69deabd7fb886fc06981e44 Mon Sep 17 00:00:00 2001 From: bingus_violet Date: Sat, 1 Jun 2024 13:45:12 -0500 Subject: [PATCH] Use Cache Server --- constants.json | 4 -- overcomplicatedStatuses.js | 9 +--- pageUpdater.js | 86 +++++++++++++++++++------------------- 3 files changed, 44 insertions(+), 55 deletions(-) diff --git a/constants.json b/constants.json index d211148..051de54 100644 --- a/constants.json +++ b/constants.json @@ -1,8 +1,4 @@ { - "activityImages": { - "ULTRAKILL": "https://fs.violets-purgatory.dev/SiteActivityImages/ULTRAKILL.jpg", - "Phasmophobia": "https://fs.violets-purgatory.dev/SiteActivityImages/Phasmophobia.png" - }, "discStatuses": { "online": { "text": "Online", diff --git a/overcomplicatedStatuses.js b/overcomplicatedStatuses.js index 08e6e80..5b6c388 100644 --- a/overcomplicatedStatuses.js +++ b/overcomplicatedStatuses.js @@ -90,14 +90,7 @@ module.exports = { function get_img(activity, size = "large_image") { - if (cachedImages[get_img_url(activity, size)]) { - var fn = cachedImages[get_img_url(activity, size)] - var fp = path.join(__dirname, 'cached', fn) - } else { - return '/imgs/notFound.png' - } - - return '/cached/' + fn + return "https://cache.violets-purgatory.dev/cached/" + get_img_url(activity, size) } function songStats() { diff --git a/pageUpdater.js b/pageUpdater.js index 2bf3732..d32c48f 100644 --- a/pageUpdater.js +++ b/pageUpdater.js @@ -289,28 +289,28 @@ var lastPong = 0 var activityImages = constants.activityImages var cachedImages = {} -function get_img_url(activity, size = "large_image") { - if ("assets" in activity) { - var image = activity.assets[size] +// function get_img_url(activity, size = "large_image") { +// if ("assets" in activity) { +// var image = activity.assets[size] - if (image) { - if (image.includes("https/")) { - return decodeURIComponent('https://' + image.substr(image.indexOf('https/') + 6, image.length)) - } else if (image.includes("spotify")) { - return decodeURIComponent('https://i.scdn.co/image/' + image.substr(image.indexOf('spotify:') + 8, image.length)) - } else { - return decodeURIComponent('https://cdn.discordapp.com/app-assets/' + activity.application_id + "/" + image + ".png") - } - } - } +// if (image) { +// if (image.includes("https/")) { +// return decodeURIComponent('https://' + image.substr(image.indexOf('https/') + 6, image.length)) +// } else if (image.includes("spotify")) { +// return decodeURIComponent('https://i.scdn.co/image/' + image.substr(image.indexOf('spotify:') + 8, image.length)) +// } else { +// return decodeURIComponent('https://cdn.discordapp.com/app-assets/' + activity.application_id + "/" + image + ".png") +// } +// } +// } - if (!image && size == "large_image") { - if (activity.name in activityImages) { - return decodeURIComponent(activityImages[activity.name]) - } - } - return null -} +// if (!image && size == "large_image") { +// if (activity.name in activityImages) { +// return decodeURIComponent(activityImages[activity.name]) +// } +// } +// return null +// } function socketeer() { @@ -353,36 +353,36 @@ function socketeer() { lanyardData = data.d lastLanyardUpdate = Date.now() - for (let index = 0; index < lanyardData.activities.length; index++) { - const activity = lanyardData.activities[index]; + // for (let index = 0; index < lanyardData.activities.length; index++) { + // const activity = lanyardData.activities[index]; - if (get_img_url(activity)) { - var url = get_img_url(activity) - var fn = Math.ceil(Math.random() * 100_000_000_000).toString() + "." + imgExtension - var fp = path.join(__dirname, 'cached', fn) + // if (get_img_url(activity)) { + // var url = get_img_url(activity) + // var fn = Math.ceil(Math.random() * 100_000_000_000).toString() + "." + imgExtension + // var fp = path.join(__dirname, 'cached', fn) - if (!cachedImages[url]) { - const response = await (await fetch(thumborURL + "200x200/" + thumborArgs + url)).arrayBuffer() - fs.writeFileSync(fp, Buffer.from(response)) + // if (!cachedImages[url]) { + // const response = await (await fetch(thumborURL + "200x200/" + thumborArgs + url)).arrayBuffer() + // fs.writeFileSync(fp, Buffer.from(response)) - cachedImages[url] = fn - } - } + // cachedImages[url] = fn + // } + // } - if (get_img_url(activity, "small_image")) { - var url = get_img_url(activity, "small_image") - var fn = Math.ceil(Math.random() * 100_000_000_000).toString() + "." + imgExtension - var fp = path.join(__dirname, 'cached', fn) + // if (get_img_url(activity, "small_image")) { + // var url = get_img_url(activity, "small_image") + // var fn = Math.ceil(Math.random() * 100_000_000_000).toString() + "." + imgExtension + // var fp = path.join(__dirname, 'cached', fn) - if (!cachedImages[url]) { - const response = await (await fetch(thumborURL + "64x64/" + thumborArgs + url)).arrayBuffer() + // if (!cachedImages[url]) { + // const response = await (await fetch(thumborURL + "64x64/" + thumborArgs + url)).arrayBuffer() - fs.writeFileSync(fp, Buffer.from(response)) + // fs.writeFileSync(fp, Buffer.from(response)) - cachedImages[url] = fn - } - } - } + // cachedImages[url] = fn + // } + // } + // } } else if (data.op == 4) { globalSpins = data.spins