This commit is contained in:
1 parent
d92c7a1964
commit
31f94997d5
13 files changed
+255
-9
No files matched your search
@@ -894,6 +894,8 @@ class Handler(BaseHTTPRequestHandler):
|
||||
self._games(qs)
|
||||
elif path == "/api/export":
|
||||
self._export(qs)
|
||||
elif path == "/api/hltb/status":
|
||||
self._hltb_status(qs)
|
||||
elif path == "/api/moods":
|
||||
self._moods()
|
||||
elif path == "/api/descriptions":
|
||||
@@ -1039,6 +1041,58 @@ class Handler(BaseHTTPRequestHandler):
|
||||
finally:
|
||||
con.close()
|
||||
|
||||
def _hltb_status(self, qs):
|
||||
def q(name, default=None):
|
||||
return qs.get(name, [default])[0]
|
||||
|
||||
where = ["LOWER(g.type) = 'game'", "g.hltb_checked_at IS NOT NULL"]
|
||||
params = []
|
||||
status = q("status")
|
||||
if status == "match":
|
||||
where.append("g.hltb_match = 1")
|
||||
elif status == "miss":
|
||||
where.append("COALESCE(g.hltb_match, 0) = 0")
|
||||
if q("q"):
|
||||
where.append("g.name LIKE ? COLLATE NOCASE")
|
||||
params.append(f"%{q('q')}%")
|
||||
try:
|
||||
limit = max(1, min(500, int(q("limit", "100") or 100)))
|
||||
offset = max(0, int(q("offset", "0") or 0))
|
||||
except (TypeError, ValueError):
|
||||
self._error(400, "invalid pagination")
|
||||
return
|
||||
|
||||
base = f"FROM games g WHERE {' AND '.join(where)}"
|
||||
con = connect()
|
||||
try:
|
||||
total = con.execute(f"SELECT COUNT(*) c {base}", params).fetchone()["c"]
|
||||
checked = con.execute(
|
||||
"""SELECT COUNT(*) FROM games WHERE LOWER(type)='game'
|
||||
AND hltb_checked_at IS NOT NULL""").fetchone()[0]
|
||||
matched = con.execute(
|
||||
"""SELECT COUNT(*) FROM games WHERE LOWER(type)='game'
|
||||
AND hltb_match = 1""").fetchone()[0]
|
||||
rows = con.execute(
|
||||
f"""SELECT g.appid, g.name, g.hltb_match, g.hltb_main, g.hltb_extra,
|
||||
g.hltb_complete, g.hltb_id, g.hltb_checked_at, g.hltb_updated_at
|
||||
{base} ORDER BY g.hltb_checked_at DESC, g.name
|
||||
LIMIT ? OFFSET ?""", [*params, limit, offset]).fetchall()
|
||||
items = [{
|
||||
"appid": row["appid"],
|
||||
"name": row["name"],
|
||||
"status": "match" if row["hltb_match"] else "miss",
|
||||
"main": row["hltb_main"],
|
||||
"extra": row["hltb_extra"],
|
||||
"complete": row["hltb_complete"],
|
||||
"hltb_id": row["hltb_id"],
|
||||
"checked_at": row["hltb_checked_at"],
|
||||
"updated_at": row["hltb_updated_at"],
|
||||
} for row in rows]
|
||||
self._json({"total": total, "checked": checked, "matched": matched,
|
||||
"limit": limit, "offset": offset, "items": items})
|
||||
finally:
|
||||
con.close()
|
||||
|
||||
def _export(self, qs):
|
||||
fmt = (qs.get("format", ["csv"])[0] or "csv").lower()
|
||||
if fmt not in ("csv", "json"):
|
||||
|
||||
@@ -42,6 +42,9 @@ const state = {
|
||||
itemsById: new Map(),
|
||||
moods: [],
|
||||
editingMood: null,
|
||||
hltbOffset: 0,
|
||||
hltbLimit: 100,
|
||||
hltbLoading: false,
|
||||
};
|
||||
|
||||
const $ = (sel) => document.querySelector(sel);
|
||||
@@ -1031,6 +1034,65 @@ $("#csGo").addEventListener("click", () => {
|
||||
runRecommend();
|
||||
});
|
||||
|
||||
function hltbDate(value) {
|
||||
return value ? esc(String(value).slice(0, 10)) : "—";
|
||||
}
|
||||
|
||||
function hltbRowHtml(item) {
|
||||
const hours = (value) => value ? (Math.round(value * 10) / 10).toString() : "—";
|
||||
return `
|
||||
<tr data-appid="${item.appid}" tabindex="0" role="button" aria-label="Открыть ${esc(item.name)}">
|
||||
<td class="hltb-name">${esc(item.name)}</td>
|
||||
<td><span class="status-chip ${item.status === "match" ? "st-playing" : "st-ignore"}">${item.status === "match" ? "совпало" : "не найдено"}</span></td>
|
||||
<td>${hours(item.main)}</td>
|
||||
<td>${hours(item.extra)}</td>
|
||||
<td>${hours(item.complete)}</td>
|
||||
<td>${item.hltb_id ?? "—"}</td>
|
||||
<td>${hltbDate(item.checked_at)}</td>
|
||||
<td>${hltbDate(item.updated_at)}</td>
|
||||
</tr>`;
|
||||
}
|
||||
|
||||
async function loadHltb(reset = true) {
|
||||
if (state.hltbLoading) return;
|
||||
state.hltbLoading = true;
|
||||
const body = $("#hltbBody");
|
||||
if (reset) {
|
||||
state.hltbOffset = 0;
|
||||
body.innerHTML = '<tr><td colspan="8" class="muted">загрузка…</td></tr>';
|
||||
}
|
||||
try {
|
||||
const params = new URLSearchParams({
|
||||
limit: String(state.hltbLimit),
|
||||
offset: String(state.hltbOffset),
|
||||
});
|
||||
const query = $("#hltbSearch").value.trim();
|
||||
const status = $("#hltbFilter").value;
|
||||
if (query) params.set("q", query);
|
||||
if (status) params.set("status", status);
|
||||
const data = await api(`/api/hltb/status?${params}`);
|
||||
if (reset) body.innerHTML = "";
|
||||
if (!data.items.length && reset) {
|
||||
body.innerHTML = '<tr><td colspan="8" class="muted">нет проверенных игр</td></tr>';
|
||||
}
|
||||
body.insertAdjacentHTML("beforeend", data.items.map(hltbRowHtml).join(""));
|
||||
bindRows(body);
|
||||
state.hltbOffset += data.items.length;
|
||||
$("#hltbSummary").textContent = `Проверено: ${data.checked} · совпало: ${data.matched}`;
|
||||
$("#hltbMore").classList.toggle("hidden", state.hltbOffset >= data.total);
|
||||
} catch (err) {
|
||||
toast(err.message);
|
||||
} finally {
|
||||
state.hltbLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
const hltbSearch = debounce(() => loadHltb(true), 280);
|
||||
$("#hltbSearch").addEventListener("input", hltbSearch);
|
||||
$("#hltbFilter").addEventListener("change", () => loadHltb(true));
|
||||
$("#hltbReload").addEventListener("click", () => loadHltb(true));
|
||||
$("#hltbMore").addEventListener("click", () => loadHltb(false));
|
||||
|
||||
async function runRecommend(scroll = true) {
|
||||
const text = $("#moodText").value.trim();
|
||||
if (!state.preset && !text) {
|
||||
@@ -1316,6 +1378,8 @@ function switchView(view) {
|
||||
});
|
||||
$("#libraryView").classList.toggle("hidden", view !== "library");
|
||||
$("#recommendView").classList.toggle("hidden", view !== "recommend");
|
||||
$("#hltbView").classList.toggle("hidden", view !== "hltb");
|
||||
if (view === "hltb") loadHltb(true);
|
||||
try {
|
||||
const url = new URL(location.href);
|
||||
if (view === "recommend") url.searchParams.set("view", "recommend");
|
||||
@@ -1630,6 +1694,7 @@ async function pollJob(silent = false) {
|
||||
toast(done);
|
||||
await loadMeta();
|
||||
await loadGames(true);
|
||||
if (state.view === "hltb") await loadHltb(true);
|
||||
} else {
|
||||
toast("Не удалось выполнить — смотри лог в сайдбаре");
|
||||
}
|
||||
@@ -1761,6 +1826,8 @@ if ("serviceWorker" in navigator) {
|
||||
}
|
||||
if (mood) $("#moodText").value = mood;
|
||||
if (preset || mood) await runRecommend(false);
|
||||
} else if (params.get("view") === "hltb") {
|
||||
switchView("hltb");
|
||||
}
|
||||
if (params.get("game")) openGame(params.get("game"));
|
||||
})();
|
||||
@@ -30,6 +30,8 @@ try {
|
||||
aria-selected="true" aria-controls="libraryView" tabindex="0">Библиотека</button>
|
||||
<button class="tab" id="tabRecommend" role="tab" data-view="recommend"
|
||||
aria-selected="false" aria-controls="recommendView" tabindex="-1">Рекомендации</button>
|
||||
<button class="tab" id="tabHltb" role="tab" data-view="hltb"
|
||||
aria-selected="false" aria-controls="hltbView" tabindex="-1">HLTB</button>
|
||||
</nav>
|
||||
<div class="stats" id="stats"></div>
|
||||
<button id="themeToggle" class="icon-btn theme-toggle" type="button"
|
||||
@@ -343,6 +345,41 @@ try {
|
||||
</div>
|
||||
<div id="recoGrid" class="grid"></div>
|
||||
</section>
|
||||
|
||||
<section id="hltbView" class="hidden" role="tabpanel" aria-labelledby="tabHltb">
|
||||
<div class="hltb-page">
|
||||
<div class="hltb-head">
|
||||
<h1>HLTB: проверенные игры</h1>
|
||||
<div class="muted" id="hltbSummary"></div>
|
||||
</div>
|
||||
<div class="toolbar hltb-toolbar">
|
||||
<input id="hltbSearch" type="search" placeholder="Поиск по названию…"
|
||||
autocomplete="off" aria-label="Поиск в HLTB">
|
||||
<select id="hltbFilter" aria-label="Статус HLTB">
|
||||
<option value="">все</option>
|
||||
<option value="match">совпало</option>
|
||||
<option value="miss">не найдено</option>
|
||||
</select>
|
||||
<button id="hltbReload" class="ghost" type="button">обновить</button>
|
||||
</div>
|
||||
<div class="hltb-table-wrap">
|
||||
<table class="game-table hltb-table" aria-label="Проверенные HLTB игры">
|
||||
<thead><tr>
|
||||
<th>Игра</th>
|
||||
<th>Статус</th>
|
||||
<th>Main</th>
|
||||
<th>+Extra</th>
|
||||
<th>100%</th>
|
||||
<th>HLTB ID</th>
|
||||
<th>Проверено</th>
|
||||
<th>Обновлено</th>
|
||||
</tr></thead>
|
||||
<tbody id="hltbBody"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
<button id="hltbMore" class="more hidden" type="button">показать ещё</button>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<dialog id="modal" class="modal" aria-labelledby="modalTitle">
|
||||
|
||||
@@ -708,6 +708,21 @@ html[data-theme="light"] .game-table tbody tr:hover { background: rgba(23, 32, 5
|
||||
border-radius: var(--radius);
|
||||
}
|
||||
|
||||
/* HLTB service page */
|
||||
#hltbView { max-width: 1200px; margin: 0 auto; }
|
||||
.hltb-page { display: flex; flex-direction: column; gap: 18px; }
|
||||
.hltb-head h1 { font-size: 26px; }
|
||||
.hltb-head .muted { margin-top: 6px; }
|
||||
.hltb-table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
|
||||
.hltb-table { table-layout: auto; min-width: 760px; }
|
||||
.hltb-table td, .hltb-table th { padding: 8px 12px; }
|
||||
.hltb-table td:nth-child(3),
|
||||
.hltb-table td:nth-child(4),
|
||||
.hltb-table td:nth-child(5) { font-variant-numeric: tabular-nums; white-space: nowrap; }
|
||||
.hltb-table .status-chip { display: inline-block; }
|
||||
.hltb-table .hltb-name { font-weight: 600; }
|
||||
.hltb-toolbar .ghost { flex: 0 0 auto; }
|
||||
|
||||
/* recommendations */
|
||||
#recommendView { max-width: 1200px; margin: 0 auto; }
|
||||
|
||||
|
||||
Reference in new issue
Block a user