parent
5164061f22
commit
0b8fec201f
1 changed files with 50 additions and 64 deletions
50
index.js
50
index.js
|
@ -59,28 +59,24 @@ app.get("/cached/*", (req, res) => {
|
|||
function waitForImage() {
|
||||
if (imgWait < imgWaitMax) {
|
||||
imgWait += 0.1
|
||||
imgData = cachedImages.imgs[imgURL]
|
||||
|
||||
if (imgData) {
|
||||
var imgPath = path.join(imgCache, imgData.file)
|
||||
|
||||
if (fs.existsSync(imgPath)) {
|
||||
var img = fs.readFileSync(imgPath)
|
||||
if (fs.existsSync(imgPath) && (img.toString().includes("<html") || fs.statSync(imgPath).size < 1000)) {
|
||||
fs.rmSync(imgPath)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
imgData = cachedImages.imgs[imgURL]
|
||||
console.log(imgData)
|
||||
if (imgData) {
|
||||
fs.createReadStream(path.join(imgCache, imgData.file)).pipe(res)
|
||||
} else {
|
||||
waitForImage()
|
||||
}, 100);
|
||||
}
|
||||
|
||||
}, 100);
|
||||
} else {
|
||||
fs.createReadStream(path.join(__dirname, "/imgs/notFound.png")).pipe(res)
|
||||
}
|
||||
}
|
||||
if (imgData) {
|
||||
fs.createReadStream(path.join(imgCache, imgData.file)).pipe(res)
|
||||
} else {
|
||||
waitForImage()
|
||||
}
|
||||
})
|
||||
|
||||
app.listen(PORT, () => {
|
||||
|
@ -180,37 +176,21 @@ function socketeer() {
|
|||
station.next()
|
||||
}
|
||||
} else {
|
||||
// console.log(spotify)
|
||||
console.log(spotify)
|
||||
}
|
||||
|
||||
for (let index = 0; index < lanyardData.activities.length; index++) {
|
||||
const activity = lanyardData.activities[index];
|
||||
|
||||
downloadFromActivity(activity)
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
socketeer()
|
||||
|
||||
async function downloadFromActivity(activity) {
|
||||
var imgType = undefined
|
||||
var imgRes = "512x512/"
|
||||
for (var i = 0; i < 2; i++) {
|
||||
if (get_img_url(activity, imgType)) {
|
||||
var url = get_img_url(activity, imgType)
|
||||
var fn = Object.keys(cachedImages.imgs).length + "." + imgExtension
|
||||
|
||||
if (cachedImages.imgs[url] && !fs.existsSync(path.join(imgCache, cachedImages.imgs[url].file))) {
|
||||
fn = Object.keys(cachedImages.imgs).indexOf(url) + "." + imgExtension
|
||||
}
|
||||
|
||||
var fp = path.join(imgCache, fn)
|
||||
|
||||
if (!cachedImages.imgs[url] || !fs.existsSync(path.join(imgCache, cachedImages.imgs[url].file))) {
|
||||
console.log(fn)
|
||||
if (!cachedImages.imgs[url]) {
|
||||
const response = await (await fetch(thumborURL + imgRes + thumborArgs + url)).arrayBuffer()
|
||||
|
||||
fs.writeFileSync(fp, Buffer.from(response))
|
||||
|
@ -225,3 +205,9 @@ async function downloadFromActivity(activity) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
socketeer()
|
Loading…
Reference in a new issue