Can now get activity by ID
This commit is contained in:
parent
70181d577e
commit
71862d8254
1 changed files with 41 additions and 11 deletions
52
index.js
52
index.js
|
@ -29,34 +29,63 @@ var app = express()
|
||||||
|
|
||||||
const imgWaitMax = 2
|
const imgWaitMax = 2
|
||||||
|
|
||||||
app.get("/cached/byURL/*", (req, res) => {
|
app.get("/cached/byID/*", (req, res) => {
|
||||||
var imgURL = req.originalUrl
|
var imgURL = req.originalUrl
|
||||||
imgURL = imgURL.substring(imgURL.indexOf("/", 8) + 1)
|
imgURL = imgURL.substring(imgURL.indexOf("/", 8) + 1, imgURL.lastIndexOf("?"))
|
||||||
var imgData = cachedImages.imgs[imgURL]
|
var size = req.query.size
|
||||||
|
|
||||||
console.log(imgURL)
|
var activities = lanyardData.activities
|
||||||
|
|
||||||
|
for (var i = 0; i < activities.length; i++) {
|
||||||
|
var activity = activities[i]
|
||||||
|
if (activity.id == imgURL) {
|
||||||
|
imgURL = get_img_url(activity, size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var imgData = cachedImages.imgs[imgURL]
|
||||||
|
|
||||||
var imgWait = 0
|
var imgWait = 0
|
||||||
function waitForImage() {
|
function waitForImage() {
|
||||||
if (imgWait < imgWaitMax) {
|
if (imgWait < imgWaitMax) {
|
||||||
imgWait += 0.1
|
imgWait += 0.1
|
||||||
setTimeout(() => {
|
|
||||||
imgData = cachedImages.imgs[imgURL]
|
imgData = cachedImages.imgs[imgURL]
|
||||||
if (imgData) {
|
if (imgData) {
|
||||||
fs.createReadStream(path.join(imgCache, imgData.file)).pipe(res)
|
fs.createReadStream(path.join(imgCache, imgData.file)).pipe(res)
|
||||||
} else {
|
} else {
|
||||||
waitForImage()
|
setTimeout(() => {
|
||||||
|
waitForImage()
|
||||||
|
}, 100);
|
||||||
}
|
}
|
||||||
}, 100);
|
|
||||||
} else {
|
} else {
|
||||||
fs.createReadStream(path.join(__dirname, "/imgs/notFound.png")).pipe(res)
|
fs.createReadStream(path.join(__dirname, "/imgs/notFound.png")).pipe(res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (imgData) {
|
waitForImage()
|
||||||
fs.createReadStream(path.join(imgCache, imgData.file)).pipe(res)
|
})
|
||||||
} else {
|
|
||||||
waitForImage()
|
app.get("/cached/byURL/*", (req, res) => {
|
||||||
|
var imgURL = req.originalUrl
|
||||||
|
imgURL = imgURL.substring(imgURL.indexOf("/", 8) + 1)
|
||||||
|
var imgData = cachedImages.imgs[imgURL]
|
||||||
|
|
||||||
|
var imgWait = 0
|
||||||
|
function waitForImage() {
|
||||||
|
if (imgWait < imgWaitMax) {
|
||||||
|
imgWait += 0.1
|
||||||
|
imgData = cachedImages.imgs[imgURL]
|
||||||
|
if (imgData) {
|
||||||
|
fs.createReadStream(path.join(imgCache, imgData.file)).pipe(res)
|
||||||
|
} else {
|
||||||
|
setTimeout(() => {
|
||||||
|
waitForImage()
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fs.createReadStream(path.join(__dirname, "/imgs/notFound.png")).pipe(res)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
waitForImage()
|
||||||
})
|
})
|
||||||
|
|
||||||
app.get("/cached/*", (req, res) => {
|
app.get("/cached/*", (req, res) => {
|
||||||
|
@ -86,6 +115,7 @@ function get_img_url(activity, size = "large_image") {
|
||||||
if (image.includes("mp:external")) {
|
if (image.includes("mp:external")) {
|
||||||
return ('https://media.discordapp.net/external' + image.substr(image.indexOf('mp:external') + 11, image.length))
|
return ('https://media.discordapp.net/external' + image.substr(image.indexOf('mp:external') + 11, image.length))
|
||||||
} else if (image.includes("https/")) {
|
} else if (image.includes("https/")) {
|
||||||
|
console.log("Bruh")
|
||||||
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))
|
||||||
|
|
Loading…
Reference in a new issue