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