Local image converting

This commit is contained in:
bingus_violet 2024-09-26 23:41:36 -05:00
parent 17c528c23d
commit 7c89ef047d
3 changed files with 532 additions and 998 deletions

View file

@ -1,7 +1,8 @@
const express = require("express"),
fs = require("fs"),
path = require("path"),
WebSocket = require('ws')
WebSocket = require('ws'),
sharp = require("sharp")
const PORT = process.env.PORT || 8080
@ -135,7 +136,7 @@ function socketeer() {
const activity = lanyardData.activities[index];
var imgType = undefined
var imgRes = "512x512/"
var imgRes = 512
for (var i = 0; i < 2; i++) {
if (get_img_url(activity, imgType)) {
var url = get_img_url(activity, imgType)
@ -143,17 +144,24 @@ function socketeer() {
var fp = path.join(imgCache, fn)
if (!cachedImages.imgs[url]) {
const response = await (await fetch(thumborURL + imgRes + thumborArgs + url)).arrayBuffer()
const response = await (await fetch(url)).arrayBuffer()
const converted = await sharp(response)
.resize(imgRes, imgRes)
.png({ progressive: true })
.toBuffer()
fs.writeFileSync(fp, converted)
fs.writeFileSync(fp, Buffer.from(response))
cachedImages.imgs[url] = {
"file": fn,
"lastUpdated": Date.now()
}
fs.writeFileSync(cacheFile, JSON.stringify(cachedImages))
}
imgType = "small_image"
imgRes = "128x128/"
imgRes = 128
}
}
}

1510
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -4,7 +4,7 @@
},
"dependencies": {
"express": "^4.19.2",
"spotifydl-core": "^0.2.0",
"sharp": "^0.33.5",
"ws": "^8.17.0"
}
}