Load the key from STEAMBASE_STEAM_API_KEY or data/steam_api_key.txt, expose GET /api/steam/achievements/{appid} with a 15-minute in-memory cache, show progress in the game card, and report steam_api in /api/meta. The key is never logged or returned to clients.
This commit is contained in:
1 parent
fc113b8794
commit
5b1b23d392
16 files changed
+423
-8
No files matched your search
@@ -1404,6 +1404,38 @@ async function openGame(appid, remember = true) {
|
||||
}
|
||||
}
|
||||
|
||||
async function loadAchievements(appid) {
|
||||
if (!state.meta || !state.meta.steam_api) return;
|
||||
const box = $("#achievementsBlock");
|
||||
if (!box) return;
|
||||
try {
|
||||
const data = await api(`/api/steam/achievements/${appid}`);
|
||||
if (!data || !data.total) return;
|
||||
const items = data.achievements || [];
|
||||
const shown = items.slice(0, 100);
|
||||
box.classList.remove("hidden");
|
||||
box.innerHTML = `
|
||||
<h3>Достижения <span class="muted">${data.achieved} / ${data.total} · ${data.percent}%</span></h3>
|
||||
<div class="bar"><i style="width:${Math.max(0, Math.min(100, data.percent))}%"></i></div>
|
||||
<div class="achievement-list">
|
||||
${shown.map((item) => `
|
||||
<div class="ach ${item.achieved ? "done" : ""}">
|
||||
${item.icon
|
||||
? `<img src="${esc(item.icon)}" alt="" width="32" height="32" loading="lazy">`
|
||||
: `<span class="ach-icon"></span>`}
|
||||
<div class="ach-text">
|
||||
<b>${esc(item.title)}</b>
|
||||
<span class="muted">${esc(item.description || (item.hidden ? "Скрытое достижение" : ""))}</span>
|
||||
</div>
|
||||
</div>`).join("")}
|
||||
</div>
|
||||
${items.length > shown.length
|
||||
? `<div class="muted">показаны первые ${shown.length} из ${items.length}</div>` : ""}`;
|
||||
} catch (_) {
|
||||
/* no key, private profile or no stats — keep the block hidden */
|
||||
}
|
||||
}
|
||||
|
||||
function renderModal(g) {
|
||||
const statusOptions = Object.entries(STATUS_LABEL)
|
||||
.map(([k, v]) => `<option value="${k}" ${k === g.status ? "selected" : ""}>${v}</option>`).join("");
|
||||
@@ -1464,6 +1496,7 @@ function renderModal(g) {
|
||||
<p class="modal-desc">${esc(shortText)}</p>
|
||||
${about ? `<details class="about-block"><summary>Полное описание</summary><p class="modal-desc about">${esc(about.slice(0, 2400))}${about.length > 2400 ? "…" : ""}</p></details>` : ""}
|
||||
${tags ? `<div class="chip-row">${tags}</div>` : ""}
|
||||
<div id="achievementsBlock" class="achievements-block hidden"></div>
|
||||
${similar}
|
||||
${attrs}
|
||||
<form class="personal" id="personalForm">
|
||||
@@ -1482,6 +1515,7 @@ function renderModal(g) {
|
||||
|
||||
$("#modalCoverBlur").style.backgroundImage = `url("${coverUrl(g.appid)}")`;
|
||||
attachCoverFallback($("#modalCover img"));
|
||||
loadAchievements(g.appid);
|
||||
|
||||
$("#modalClose").addEventListener("click", () => $("#modal").close());
|
||||
const back = $("#modalBack");
|
||||
|
||||
Reference in new issue
Block a user