mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-17 02:54:42 -05:00
add no id warning
This commit is contained in:
parent
4a9f666624
commit
690f6eaf94
1 changed files with 72 additions and 57 deletions
|
@ -127,93 +127,108 @@ app.get("/avatars/:v", async function (req, res) {
|
||||||
} catch {}
|
} catch {}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/api/getEngagementData", async (req, res) => {
|
app.get("/api/getEngagementData", async (req, res) => {
|
||||||
const { fetch } = await import("undici");
|
const { fetch } = await import("undici");
|
||||||
|
|
||||||
const id = req.query.v;
|
|
||||||
|
|
||||||
try {
|
const id = req.query.v;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (id) {
|
||||||
const apiUrl = `https://ryd-proxy.kavin.rocks/votes/${id}&hash=d0550b6e28c8f93533a569c314d5b4e2`;
|
const apiUrl = `https://ryd-proxy.kavin.rocks/votes/${id}&hash=d0550b6e28c8f93533a569c314d5b4e2`;
|
||||||
|
|
||||||
const engagement = await fetch(apiUrl).then((res) => res.json());
|
const response = await fetch(apiUrl);
|
||||||
|
|
||||||
const likes = parseInt(engagement.likes) || 0;
|
if (response.status === 400) {
|
||||||
const dislikes = parseInt(engagement.dislikes) || 0;
|
const error = await response.json();
|
||||||
const total = likes + dislikes;
|
return res.status(400).send(error);
|
||||||
|
}
|
||||||
|
|
||||||
const likePercentage = total > 0 ? ((likes / total) * 100).toFixed(2) : 0;
|
const engagement = await response.json();
|
||||||
const dislikePercentage = total > 0 ? ((dislikes / total) * 100).toFixed(2) : 0;
|
|
||||||
|
|
||||||
const getLikePercentageColor = (percentage) => {
|
const likes = parseInt(engagement.likes) || 0;
|
||||||
|
const dislikes = parseInt(engagement.dislikes) || 0;
|
||||||
|
const total = likes + dislikes;
|
||||||
|
|
||||||
|
const likePercentage = total > 0 ? ((likes / total) * 100).toFixed(2) : 0;
|
||||||
|
const dislikePercentage = total > 0 ? ((dislikes / total) * 100).toFixed(2) : 0;
|
||||||
|
|
||||||
|
const getLikePercentageColor = (percentage) => {
|
||||||
if (percentage >= 80) {
|
if (percentage >= 80) {
|
||||||
return 'green';
|
return "green";
|
||||||
} else if (percentage >= 50) {
|
} else if (percentage >= 50) {
|
||||||
return 'orange';
|
return "orange";
|
||||||
} else {
|
} else {
|
||||||
return 'red';
|
return "red";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getDislikePercentageColor = (percentage) => {
|
const getDislikePercentageColor = (percentage) => {
|
||||||
if (percentage >= 50) {
|
if (percentage >= 50) {
|
||||||
return 'red';
|
return "red";
|
||||||
} else if (percentage >= 20) {
|
} else if (percentage >= 20) {
|
||||||
return 'orange';
|
return "orange";
|
||||||
} else {
|
} else {
|
||||||
return 'green';
|
return "green";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const likeColor = getLikePercentageColor(likePercentage);
|
const likeColor = getLikePercentageColor(likePercentage);
|
||||||
const dislikeColor = getDislikePercentageColor(dislikePercentage);
|
const dislikeColor = getDislikePercentageColor(dislikePercentage);
|
||||||
|
|
||||||
const userScore = (parseFloat(likePercentage) - parseFloat(dislikePercentage) / 2).toFixed(2);
|
const userScore = (
|
||||||
|
parseFloat(likePercentage) -
|
||||||
|
parseFloat(dislikePercentage) / 2
|
||||||
|
).toFixed(2);
|
||||||
|
|
||||||
const getUserScoreLabel = (score) => {
|
const getUserScoreLabel = (score) => {
|
||||||
if (score >= 98) {
|
if (score >= 98) {
|
||||||
return 'Masterpiece Video';
|
return "Masterpiece Video";
|
||||||
} else if (score >= 80) {
|
} else if (score >= 80) {
|
||||||
return 'Overwhelmingly Positive';
|
return "Overwhelmingly Positive";
|
||||||
} else if (score >= 60) {
|
} else if (score >= 60) {
|
||||||
return 'Positive';
|
return "Positive";
|
||||||
} else if (score >= 40) {
|
} else if (score >= 40) {
|
||||||
return 'Mixed';
|
return "Mixed";
|
||||||
} else if (score >= 20) {
|
} else if (score >= 20) {
|
||||||
return 'Negative';
|
return "Negative";
|
||||||
} else {
|
} else {
|
||||||
return 'Overwhelmingly Negative';
|
return "Overwhelmingly Negative";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const userScoreLabel = getUserScoreLabel(userScore);
|
const userScoreLabel = getUserScoreLabel(userScore);
|
||||||
const userScoreColor = userScore >= 80 ? 'green' : userScore >= 50 ? 'orange' : 'red';
|
const userScoreColor =
|
||||||
|
userScore >= 80 ? "green" : userScore >= 50 ? "orange" : "red";
|
||||||
|
|
||||||
|
const respon = {
|
||||||
|
like_count: likes,
|
||||||
|
dislike_count: dislikes,
|
||||||
|
rating: engagement.rating,
|
||||||
|
userScore: {
|
||||||
|
label: userScoreLabel,
|
||||||
|
score: userScore,
|
||||||
|
color: userScoreColor,
|
||||||
|
},
|
||||||
|
engagement: {
|
||||||
|
likeColor: likeColor,
|
||||||
|
dislikeColor: dislikeColor,
|
||||||
|
percentage: {
|
||||||
|
likePercentage: `${likePercentage}%`,
|
||||||
|
dislikePercentage: `${dislikePercentage}%`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ReturnYouTubeDislikesApiRawResponse: engagement,
|
||||||
|
};
|
||||||
|
|
||||||
var respon = {
|
res.send(respon);
|
||||||
like_count:likes,
|
} else {
|
||||||
dislike_count:dislikes,
|
res.status(400).send("pls gib ID :3");
|
||||||
rating:engagement.rating,
|
|
||||||
userScore : {
|
|
||||||
label:userScoreLabel,
|
|
||||||
score:userScore,
|
|
||||||
color:userScoreColor,
|
|
||||||
},
|
|
||||||
engagement: {
|
|
||||||
likeColor:likeColor,
|
|
||||||
dislikeColor: dislikeColor,
|
|
||||||
percentage: {
|
|
||||||
likePercentage:`${likePercentage}%`,
|
|
||||||
dislikePercentage:`${dislikePercentage}%`
|
|
||||||
}
|
|
||||||
},
|
|
||||||
ReturnYouTubeDislikesApiRawResponse:engagement,
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).send("whoops >~<");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
res.send(respon)
|
|
||||||
} catch {}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.use("/sb/i/:v/:imagePath/:img", async function (req, res) {
|
app.use("/sb/i/:v/:imagePath/:img", async function (req, res) {
|
||||||
const { v, imagePath, img } = req.params;
|
const { v, imagePath, img } = req.params;
|
||||||
const { sqp, xywh } = req.query;
|
const { sqp, xywh } = req.query;
|
||||||
|
|
Loading…
Reference in a new issue