Use Cache Server
This commit is contained in:
parent
134d4e4380
commit
3fe2266e3e
3 changed files with 44 additions and 55 deletions
|
@ -1,8 +1,4 @@
|
||||||
{
|
{
|
||||||
"activityImages": {
|
|
||||||
"ULTRAKILL": "https://fs.violets-purgatory.dev/SiteActivityImages/ULTRAKILL.jpg",
|
|
||||||
"Phasmophobia": "https://fs.violets-purgatory.dev/SiteActivityImages/Phasmophobia.png"
|
|
||||||
},
|
|
||||||
"discStatuses": {
|
"discStatuses": {
|
||||||
"online": {
|
"online": {
|
||||||
"text": "Online",
|
"text": "Online",
|
||||||
|
|
|
@ -90,14 +90,7 @@ module.exports = {
|
||||||
|
|
||||||
|
|
||||||
function get_img(activity, size = "large_image") {
|
function get_img(activity, size = "large_image") {
|
||||||
if (cachedImages[get_img_url(activity, size)]) {
|
return "https://cache.violets-purgatory.dev/cached/" + 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function songStats() {
|
function songStats() {
|
||||||
|
|
|
@ -289,28 +289,28 @@ var lastPong = 0
|
||||||
var activityImages = constants.activityImages
|
var activityImages = constants.activityImages
|
||||||
var cachedImages = {}
|
var cachedImages = {}
|
||||||
|
|
||||||
function get_img_url(activity, size = "large_image") {
|
// function get_img_url(activity, size = "large_image") {
|
||||||
if ("assets" in activity) {
|
// if ("assets" in activity) {
|
||||||
var image = activity.assets[size]
|
// var image = activity.assets[size]
|
||||||
|
|
||||||
if (image) {
|
// if (image) {
|
||||||
if (image.includes("https/")) {
|
// if (image.includes("https/")) {
|
||||||
return decodeURIComponent('https://' + image.substr(image.indexOf('https/') + 6, image.length))
|
// return decodeURIComponent('https://' + image.substr(image.indexOf('https/') + 6, image.length))
|
||||||
} else if (image.includes("spotify")) {
|
// } else if (image.includes("spotify")) {
|
||||||
return decodeURIComponent('https://i.scdn.co/image/' + image.substr(image.indexOf('spotify:') + 8, image.length))
|
// return decodeURIComponent('https://i.scdn.co/image/' + image.substr(image.indexOf('spotify:') + 8, image.length))
|
||||||
} else {
|
// } else {
|
||||||
return decodeURIComponent('https://cdn.discordapp.com/app-assets/' + activity.application_id + "/" + image + ".png")
|
// return decodeURIComponent('https://cdn.discordapp.com/app-assets/' + activity.application_id + "/" + image + ".png")
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (!image && size == "large_image") {
|
// if (!image && size == "large_image") {
|
||||||
if (activity.name in activityImages) {
|
// if (activity.name in activityImages) {
|
||||||
return decodeURIComponent(activityImages[activity.name])
|
// return decodeURIComponent(activityImages[activity.name])
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return null
|
// return null
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
function socketeer() {
|
function socketeer() {
|
||||||
|
@ -353,36 +353,36 @@ function socketeer() {
|
||||||
lanyardData = data.d
|
lanyardData = data.d
|
||||||
lastLanyardUpdate = Date.now()
|
lastLanyardUpdate = Date.now()
|
||||||
|
|
||||||
for (let index = 0; index < lanyardData.activities.length; index++) {
|
// for (let index = 0; index < lanyardData.activities.length; index++) {
|
||||||
const activity = lanyardData.activities[index];
|
// const activity = lanyardData.activities[index];
|
||||||
|
|
||||||
if (get_img_url(activity)) {
|
// if (get_img_url(activity)) {
|
||||||
var url = get_img_url(activity)
|
// var url = get_img_url(activity)
|
||||||
var fn = Math.ceil(Math.random() * 100_000_000_000).toString() + "." + imgExtension
|
// var fn = Math.ceil(Math.random() * 100_000_000_000).toString() + "." + imgExtension
|
||||||
var fp = path.join(__dirname, 'cached', fn)
|
// var fp = path.join(__dirname, 'cached', fn)
|
||||||
|
|
||||||
if (!cachedImages[url]) {
|
// if (!cachedImages[url]) {
|
||||||
const response = await (await fetch(thumborURL + "200x200/" + thumborArgs + url)).arrayBuffer()
|
// const response = await (await fetch(thumborURL + "200x200/" + thumborArgs + url)).arrayBuffer()
|
||||||
fs.writeFileSync(fp, Buffer.from(response))
|
// fs.writeFileSync(fp, Buffer.from(response))
|
||||||
|
|
||||||
cachedImages[url] = fn
|
// cachedImages[url] = fn
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (get_img_url(activity, "small_image")) {
|
// if (get_img_url(activity, "small_image")) {
|
||||||
var url = 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 fn = Math.ceil(Math.random() * 100_000_000_000).toString() + "." + imgExtension
|
||||||
var fp = path.join(__dirname, 'cached', fn)
|
// var fp = path.join(__dirname, 'cached', fn)
|
||||||
|
|
||||||
if (!cachedImages[url]) {
|
// if (!cachedImages[url]) {
|
||||||
const response = await (await fetch(thumborURL + "64x64/" + thumborArgs + url)).arrayBuffer()
|
// 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) {
|
} else if (data.op == 4) {
|
||||||
globalSpins = data.spins
|
globalSpins = data.spins
|
||||||
|
|
Loading…
Reference in a new issue