3s
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"port":8084
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
from system_module import db, gelbooru, logger
|
||||
from flask import Flask, render_template
|
||||
import json
|
||||
|
||||
CONFIG_ROOT = json.load(open("config.json", "r", encoding="utf-8"))
|
||||
CONFIG_PORT = CONFIG_ROOT["port"]
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
return render_template("index.html")
|
||||
|
||||
|
||||
@app.route("/analytics")
|
||||
def analytics():
|
||||
return render_template("analytics.html")
|
||||
|
||||
|
||||
@app.route("/post/<path:post_id>")
|
||||
def post(post_id):
|
||||
return render_template("post.html")
|
||||
|
||||
|
||||
@app.route("/api", methods=["GET", "POST"])
|
||||
def api():
|
||||
return "", 204
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=CONFIG_PORT)
|
||||
@@ -0,0 +1,418 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Analytics - LocalBooru</title>
|
||||
<style>
|
||||
:root {
|
||||
--bg-main: #1e1e1e;
|
||||
--bg-header: #252525;
|
||||
--bg-panel: #222222;
|
||||
--bg-box: #2a2a2a;
|
||||
--bg-input: #333;
|
||||
--text-main: #eee;
|
||||
--text-muted: #aaa;
|
||||
--border-color: #444;
|
||||
--link-color: #4da8da;
|
||||
|
||||
--color-g: #4caf50;
|
||||
--color-s: #ff9800;
|
||||
--color-q: #ffeb3b;
|
||||
--color-e: #f44336;
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
|
||||
body {
|
||||
background-color: var(--bg-main);
|
||||
color: var(--text-main);
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
header {
|
||||
display: flex; align-items: center; background-color: var(--bg-header);
|
||||
padding: 10px 20px; border-bottom: 1px solid var(--border-color); gap: 15px; flex-wrap: wrap;
|
||||
}
|
||||
.logo { font-weight: bold; font-size: 18px; color: white; text-decoration: none; }
|
||||
.analytics-link { color: var(--link-color); text-decoration: none; font-size: 12px; font-weight: bold;}
|
||||
|
||||
/* Search & Autocomplete */
|
||||
.search-wrapper { flex-grow: 1; max-width: 400px; position: relative; }
|
||||
.search-wrapper input {
|
||||
width: 100%; background-color: var(--bg-input); border: 1px solid var(--border-color);
|
||||
color: white; padding: 6px 10px; border-radius: 3px; outline: none;
|
||||
}
|
||||
.search-wrapper input:focus { border-color: var(--text-muted); }
|
||||
.autocomplete-list {
|
||||
position: absolute; top: 100%; left: 0; right: 0; background-color: var(--bg-box);
|
||||
border: 1px solid var(--border-color); border-radius: 3px; margin-top: 4px;
|
||||
list-style: none; z-index: 1000; max-height: 250px; overflow-y: auto;
|
||||
box-shadow: 0 4px 10px rgba(0,0,0,0.5); display: none;
|
||||
}
|
||||
.autocomplete-item { padding: 8px 10px; cursor: pointer; display: flex; justify-content: space-between; border-bottom: 1px solid #333; }
|
||||
.autocomplete-item:last-child { border-bottom: none; }
|
||||
.autocomplete-item:hover { background-color: var(--bg-input); }
|
||||
.autocomplete-count { color: var(--text-muted); font-size: 12px; }
|
||||
|
||||
main { padding: 20px; max-width: 1400px; margin: 0 auto; }
|
||||
h1 { font-size: 20px; margin-bottom: 20px; color: white; }
|
||||
|
||||
.dashboard-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 20px;
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
/* Панели */
|
||||
.panel {
|
||||
background-color: var(--bg-panel); border: 1px solid var(--border-color);
|
||||
border-radius: 4px; padding: 15px; display: flex; flex-direction: column; gap: 15px;
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
font-size: 16px; font-weight: bold; color: var(--link-color);
|
||||
display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--border-color);
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
/* Левая колонка - Статистика */
|
||||
.left-col { display: flex; flex-direction: column; gap: 20px; }
|
||||
|
||||
.rating-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
|
||||
.rating-box {
|
||||
background-color: var(--bg-box); border: 1px solid var(--border-color);
|
||||
border-radius: 4px; padding: 15px; text-align: center;
|
||||
}
|
||||
.rating-box.e { border-top: 2px solid var(--color-e); }
|
||||
.rating-box.s { border-top: 2px solid var(--color-s); }
|
||||
.rating-box.q { border-top: 2px solid var(--color-q); }
|
||||
.rating-box.g { border-top: 2px solid var(--color-g); }
|
||||
|
||||
.rating-title { font-weight: bold; font-size: 15px; margin-bottom: 5px; }
|
||||
.rating-box.e .rating-title { color: var(--color-e); }
|
||||
.rating-box.s .rating-title { color: var(--color-s); }
|
||||
.rating-box.q .rating-title { color: var(--color-q); }
|
||||
.rating-box.g .rating-title { color: var(--color-g); }
|
||||
|
||||
.rating-count { color: var(--text-muted); margin-bottom: 3px; }
|
||||
.rating-size { font-weight: bold; }
|
||||
|
||||
.data-list { list-style: none; display: flex; flex-direction: column; gap: 8px;}
|
||||
.data-row { display: flex; justify-content: space-between; border-bottom: 1px solid #333; padding-bottom: 4px; }
|
||||
.data-row.total { color: var(--color-g); font-weight: bold; border-top: 1px solid var(--border-color); padding-top: 8px; border-bottom: none;}
|
||||
.data-row .val { font-weight: bold; }
|
||||
|
||||
.sub-text { font-size: 11px; color: var(--text-muted); margin-top: 5px; }
|
||||
|
||||
.ext-block { margin-bottom: 10px; }
|
||||
.ext-block a { color: var(--link-color); text-decoration: none; word-break: break-all; }
|
||||
.ext-block a:hover { text-decoration: underline; }
|
||||
|
||||
/* Таблицы тегов (Центр и Правая) */
|
||||
.table-header { display: flex; justify-content: space-between; font-weight: bold; margin-bottom: 10px; color: white;}
|
||||
.tag-row { display: flex; justify-content: space-between; margin-bottom: 8px; }
|
||||
.tag-row a { color: var(--link-color); text-decoration: none; }
|
||||
.tag-row a:hover { text-decoration: underline; }
|
||||
|
||||
/* Пагинация */
|
||||
.pagination { display: flex; justify-content: center; gap: 5px; margin-top: 15px; align-items: center; }
|
||||
.page-btn {
|
||||
background-color: transparent; border: 1px solid var(--border-color); color: white;
|
||||
padding: 4px 10px; border-radius: 3px; cursor: pointer;
|
||||
}
|
||||
.page-btn:hover { background-color: var(--bg-input); }
|
||||
.page-info { font-weight: bold; padding: 0 10px; }
|
||||
|
||||
@media (max-width: 1000px) {
|
||||
.dashboard-grid { grid-template-columns: 1fr 1fr; }
|
||||
.left-col { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; }
|
||||
}
|
||||
@media (max-width: 700px) {
|
||||
.dashboard-grid, .left-col { grid-template-columns: 1fr; }
|
||||
header { justify-content: space-between; }
|
||||
.search-wrapper { order: 3; max-width: 100%; width: 100%; margin-top: 10px;}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header>
|
||||
<a href="index.html" class="logo">LocalBooru</a>
|
||||
<a href="analytics.html" class="analytics-link">📊 Analytics</a>
|
||||
<div class="search-wrapper">
|
||||
<input type="text" id="searchInput" placeholder="Search tags...">
|
||||
<ul id="autocompleteList" class="autocomplete-list"></ul>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<h1>Database Analytics</h1>
|
||||
|
||||
<div class="dashboard-grid" id="analyticsGrid" style="display: none;">
|
||||
|
||||
<!-- Левая колонка -->
|
||||
<div class="left-col">
|
||||
<div class="panel">
|
||||
<div class="panel-header">⭐ Rating Breakdown</div>
|
||||
<div class="rating-grid" id="ratingContainer">
|
||||
<!-- JS inject -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel">
|
||||
<div class="panel-header">📁 Storage Breakdown</div>
|
||||
<div class="data-list" id="storageContainer">
|
||||
<!-- JS inject -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel">
|
||||
<div class="panel-header">🎨 Media Types (in img/)</div>
|
||||
<div class="data-list" id="mediaContainer">
|
||||
<!-- JS inject -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel">
|
||||
<div class="panel-header">📏 Extremes (Click to view)</div>
|
||||
<div id="extremesContainer">
|
||||
<!-- JS inject -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Центральная колонка -->
|
||||
<div class="panel">
|
||||
<div class="panel-header">🏷️ All Tags List</div>
|
||||
<div class="table-header"><span>Tag</span><span>Count</span></div>
|
||||
<div class="data-list" id="tagsListContainer"></div>
|
||||
<div class="pagination">
|
||||
<button class="page-btn" onclick="prevTagPage()">«</button>
|
||||
<button class="page-btn" onclick="prevTagPage()">‹</button>
|
||||
<span class="page-info" id="tagPageInfo">1 / 1</span>
|
||||
<button class="page-btn" onclick="nextTagPage()">›</button>
|
||||
<button class="page-btn" onclick="nextTagPage()">»</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Правая колонка -->
|
||||
<div class="panel">
|
||||
<div class="panel-header">🔗 Top 30 Tag Pairs</div>
|
||||
<div class="table-header"><span>Pair</span><span>Count</span></div>
|
||||
<div class="data-list" id="pairsContainer">
|
||||
<!-- JS inject -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<script>
|
||||
// Инициализация поиска с автодополнением
|
||||
const searchInput = document.getElementById('searchInput');
|
||||
const list = document.getElementById('autocompleteList');
|
||||
let debounceTimer;
|
||||
|
||||
searchInput.addEventListener('input', () => {
|
||||
clearTimeout(debounceTimer);
|
||||
const words = searchInput.value.split(' ');
|
||||
const currentWord = words[words.length - 1];
|
||||
|
||||
if (currentWord.length < 2) { list.style.display = 'none'; return; }
|
||||
|
||||
debounceTimer = setTimeout(async () => {
|
||||
const req = { type: "autocomplete", q: currentWord };
|
||||
|
||||
// РЕАЛЬНОЕ API: const data = await fetch('/api', ...);
|
||||
const data = await mockAutocompleteAPI(req);
|
||||
|
||||
if (data.length === 0) { list.style.display = 'none'; return; }
|
||||
|
||||
list.innerHTML = data.map(item => `
|
||||
<li class="autocomplete-item" data-tag="${item.tag}">
|
||||
<span>${item.tag}</span><span class="autocomplete-count">${item.count}</span>
|
||||
</li>
|
||||
`).join('');
|
||||
list.style.display = 'block';
|
||||
|
||||
list.querySelectorAll('.autocomplete-item').forEach(li => {
|
||||
li.addEventListener('click', () => {
|
||||
words[words.length - 1] = li.getAttribute('data-tag');
|
||||
searchInput.value = words.join(' ') + ' ';
|
||||
list.style.display = 'none';
|
||||
searchInput.focus();
|
||||
});
|
||||
});
|
||||
}, 200);
|
||||
});
|
||||
|
||||
document.addEventListener('click', (e) => {
|
||||
if (e.target !== searchInput && e.target !== list) list.style.display = 'none';
|
||||
});
|
||||
|
||||
searchInput.addEventListener('keypress', (e) => {
|
||||
if(e.key === 'Enter') window.location.href = `index.html?query=${searchInput.value.trim()}`;
|
||||
});
|
||||
|
||||
// Состояние для пагинации тегов (для имитации UI)
|
||||
let allTags = [];
|
||||
let currentTagPage = 1;
|
||||
const tagsPerPage = 22; // Примерно столько строк влезает на скрине
|
||||
|
||||
async function fetchAnalytics() {
|
||||
const requestBody = { type: "analytics" };
|
||||
|
||||
try {
|
||||
// РЕАЛЬНОЕ API: fetch('/api', ...);
|
||||
const data = await generateMockAnalyticsData();
|
||||
renderAnalytics(data);
|
||||
document.getElementById('analyticsGrid').style.display = 'grid';
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
document.body.innerHTML += `<div style="text-align:center; padding:50px;">Ошибка загрузки</div>`;
|
||||
}
|
||||
}
|
||||
|
||||
function renderAnalytics(data) {
|
||||
// 1. Ratings
|
||||
const r = data.ratings;
|
||||
document.getElementById('ratingContainer').innerHTML = `
|
||||
<div class="rating-box e"><div class="rating-title">Explicit</div><div class="rating-count">${r.explicit.count} items</div><div class="rating-size">${r.explicit.size}</div></div>
|
||||
<div class="rating-box s"><div class="rating-title">Sensitive</div><div class="rating-count">${r.sensitive.count} items</div><div class="rating-size">${r.sensitive.size}</div></div>
|
||||
<div class="rating-box q"><div class="rating-title">Questionable</div><div class="rating-count">${r.questionable.count} items</div><div class="rating-size">${r.questionable.size}</div></div>
|
||||
<div class="rating-box g"><div class="rating-title">General</div><div class="rating-count">${r.general.count} items</div><div class="rating-size">${r.general.size}</div></div>
|
||||
`;
|
||||
|
||||
// 2. Storage
|
||||
const s = data.storage;
|
||||
document.getElementById('storageContainer').innerHTML = `
|
||||
<div class="data-row"><span>Logs (logs/):</span><span class="val">${s.logs}</span></div>
|
||||
<div class="data-row"><span>Database (json_db/):</span><span class="val">${s.db}</span></div>
|
||||
<div class="data-row"><span>Thumbnails (thumb/):</span><span class="val">${s.thumb}</span></div>
|
||||
<div class="data-row"><span>Main Media (img/):</span><span class="val">${s.main}</span></div>
|
||||
<div class="data-row total"><span>GRAND TOTAL:</span><span class="val">${s.total}</span></div>
|
||||
`;
|
||||
|
||||
// 3. Media Types
|
||||
const m = data.media;
|
||||
document.getElementById('mediaContainer').innerHTML = `
|
||||
<div class="data-row"><span>Static Images (IMG):</span><span class="val">${m.img_size}</span></div>
|
||||
<div class="data-row"><span>Videos (VID):</span><span class="val">${m.vid_size}</span></div>
|
||||
<div class="data-row"><span>Animations (GIF):</span><span class="val">${m.gif_size}</span></div>
|
||||
<div class="sub-text">Total Valid Items Analyzed: <b>${m.total_items}</b><br>Average Weight per item: <b>${m.avg_weight}</b></div>
|
||||
`;
|
||||
|
||||
// 4. Extremes
|
||||
const e = data.extremes;
|
||||
document.getElementById('extremesContainer').innerHTML = `
|
||||
<div class="ext-block"><b>Largest Resolution:</b> ${e.largest.val}<br>(<a href="post.html?id=${e.largest.id}">${e.largest.file}</a>)</div>
|
||||
<div class="ext-block"><b>Smallest Resolution:</b> ${e.smallest.val}<br>(<a href="post.html?id=${e.smallest.id}">${e.smallest.file}</a>)</div>
|
||||
<div class="ext-block"><b>Heaviest File:</b> ${e.heaviest.val}<br>(<a href="post.html?id=${e.heaviest.id}">${e.heaviest.file}</a>)</div>
|
||||
<div class="ext-block"><b>Lightest File:</b> ${e.lightest.val}<br>(<a href="post.html?id=${e.lightest.id}">${e.lightest.file}</a>)</div>
|
||||
`;
|
||||
|
||||
// 5. Pairs (Right Column)
|
||||
const pairsHtml = data.top_pairs.map(p => `
|
||||
<div class="tag-row"><a href="index.html?query=${p.pair.replace(/ \+ /g, '+')}">${p.pair}</a> <span>${p.count}</span></div>
|
||||
`).join('');
|
||||
document.getElementById('pairsContainer').innerHTML = pairsHtml;
|
||||
|
||||
// 6. Tags (Center Column + Pagination Setup)
|
||||
allTags = data.all_tags;
|
||||
renderTagsPage();
|
||||
}
|
||||
|
||||
// Логика пагинации для тегов
|
||||
function renderTagsPage() {
|
||||
const totalPages = Math.ceil(allTags.length / tagsPerPage);
|
||||
document.getElementById('tagPageInfo').innerText = `${currentTagPage} / ${totalPages}`;
|
||||
|
||||
const start = (currentTagPage - 1) * tagsPerPage;
|
||||
const end = start + tagsPerPage;
|
||||
const pageTags = allTags.slice(start, end);
|
||||
|
||||
document.getElementById('tagsListContainer').innerHTML = pageTags.map(t => `
|
||||
<div class="tag-row"><a href="index.html?query=${t.name}">${t.name}</a> <span>${t.count}</span></div>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
window.prevTagPage = () => { if(currentTagPage > 1) { currentTagPage--; renderTagsPage(); }};
|
||||
window.nextTagPage = () => { if(currentTagPage < Math.ceil(allTags.length / tagsPerPage)) { currentTagPage++; renderTagsPage(); }};
|
||||
|
||||
// --- ВРЕМЕННЫЕ ЗАГЛУШКИ ДЛЯ API ---
|
||||
function mockAutocompleteAPI(req) {
|
||||
return new Promise(res => {
|
||||
const db = [
|
||||
{tag: "long_hair", count: 8184}, {tag: "long_sleeves", count: 2828},
|
||||
{tag: "looking_at_viewer", count: 8062}, {tag: "1girl", count: 11061},
|
||||
{tag: "blue_hair", count: 3279}, {tag: "blue_eyes", count: 3279}
|
||||
];
|
||||
res(db.filter(t => t.tag.includes(req.q.toLowerCase())));
|
||||
});
|
||||
}
|
||||
|
||||
function generateMockAnalyticsData() {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
resolve({
|
||||
ratings: {
|
||||
explicit: { count: 1605, size: "4.52 GB" },
|
||||
sensitive: { count: 6623, size: "19.35 GB" },
|
||||
questionable: { count: 1591, size: "4.72 GB" },
|
||||
general: { count: 4184, size: "10.29 GB" }
|
||||
},
|
||||
storage: {
|
||||
logs: "14.44 MB", db: "24.39 MB", thumb: "331.45 MB",
|
||||
main: "38.88 GB", total: "39.24 GB"
|
||||
},
|
||||
media: {
|
||||
img_size: "38.56 GB", vid_size: "140.80 MB", gif_size: "181.30 MB",
|
||||
total_items: 14003, avg_weight: "2.84 MB"
|
||||
},
|
||||
extremes: {
|
||||
largest: { val: "9921x14031", id: "5a63c", file: "5a63c28906dc7e0e...png" },
|
||||
smallest: { val: "240x280", id: "8fc61", file: "8fc614e712ae2ad...gif" },
|
||||
heaviest: { val: "65.21 MB", id: "4ab6a", file: "4ab6acf0a32c61...png" },
|
||||
lightest: { val: "6.49 KB", id: "28c67", file: "28c679ea3483e1...png" }
|
||||
},
|
||||
// Генерируем массив на 765 страниц для имитации пагинации
|
||||
all_tags: Array.from({length: 765 * 22}, (_, i) => ({
|
||||
name: ["highres", "1girl", "solo", "virtual_youtuber", "long_hair", "looking_at_viewer", "breasts", "absurdres", "blush", "hololive", "smile", "open_mouth", "animal_ears", "multicolored_hair"][i % 14] + (i > 13 ? `_${i}` : ''),
|
||||
count: 12700 - i
|
||||
})),
|
||||
top_pairs: [
|
||||
{ pair: "1girl + highres", count: 10236 },
|
||||
{ pair: "1girl + solo", count: 8902 },
|
||||
{ pair: "highres + solo", count: 8557 },
|
||||
{ pair: "highres + virtual_youtuber", count: 8192 },
|
||||
{ pair: "highres + long_hair", count: 7531 },
|
||||
{ pair: "highres + looking_at_viewer", count: 7479 },
|
||||
{ pair: "1girl + virtual_youtuber", count: 7315 },
|
||||
{ pair: "breasts + highres", count: 7096 },
|
||||
{ pair: "1girl + looking_at_viewer", count: 7015 },
|
||||
{ pair: "absurdres + highres", count: 6742 },
|
||||
{ pair: "1girl + long_hair", count: 6560 },
|
||||
{ pair: "1girl + breasts", count: 6407 },
|
||||
{ pair: "looking_at_viewer + solo", count: 6230 },
|
||||
{ pair: "solo + virtual_youtuber", count: 6011 },
|
||||
{ pair: "1girl + absurdres", count: 5572 },
|
||||
{ pair: "blush + highres", count: 5552 },
|
||||
{ pair: "hololive + virtual_youtuber", count: 5494 },
|
||||
{ pair: "long_hair + solo", count: 5490 },
|
||||
{ pair: "looking_at_viewer + virtual_youtuber", count: 5332 },
|
||||
{ pair: "breasts + solo", count: 5316 },
|
||||
{ pair: "highres + hololive", count: 5073 },
|
||||
{ pair: "breasts + virtual_youtuber", count: 5039 }
|
||||
]
|
||||
});
|
||||
}, 300);
|
||||
});
|
||||
}
|
||||
|
||||
fetchAnalytics();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,233 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>LocalBooru</title>
|
||||
<style>
|
||||
:root {
|
||||
--bg-main: #1e1e1e;
|
||||
--bg-header: #252525;
|
||||
--bg-card: #2a2a2a;
|
||||
--bg-panel: #222;
|
||||
--bg-input: #333;
|
||||
--text-main: #eee;
|
||||
--text-muted: #aaa;
|
||||
--border-color: #444;
|
||||
--color-g: #4caf50; --color-s: #ff9800; --color-q: #ffeb3b; --color-e: #f44336;
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
body { background-color: var(--bg-main); color: var(--text-main); font-family: sans-serif; font-size: 14px; }
|
||||
|
||||
/* Header */
|
||||
header { display: flex; align-items: center; background-color: var(--bg-header); padding: 10px 20px; border-bottom: 1px solid var(--border-color); gap: 15px; flex-wrap: wrap; }
|
||||
.logo { font-weight: bold; font-size: 18px; color: white; text-decoration: none; }
|
||||
.analytics { color: #88bece; text-decoration: none; font-size: 12px; }
|
||||
|
||||
/* Search & Autocomplete */
|
||||
.search-wrapper { flex-grow: 1; max-width: 400px; position: relative; }
|
||||
.search-wrapper input { width: 100%; background-color: var(--bg-input); border: 1px solid var(--border-color); color: white; padding: 6px 10px; border-radius: 3px; outline: none; }
|
||||
.search-wrapper input:focus { border-color: var(--text-muted); }
|
||||
|
||||
.autocomplete-list {
|
||||
position: absolute; top: 100%; left: 0; right: 0; background-color: var(--bg-card);
|
||||
border: 1px solid var(--border-color); border-radius: 3px; margin-top: 4px;
|
||||
list-style: none; z-index: 1000; max-height: 250px; overflow-y: auto;
|
||||
box-shadow: 0 4px 10px rgba(0,0,0,0.5); display: none;
|
||||
}
|
||||
.autocomplete-item {
|
||||
padding: 8px 10px; cursor: pointer; display: flex; justify-content: space-between; border-bottom: 1px solid #333;
|
||||
}
|
||||
.autocomplete-item:last-child { border-bottom: none; }
|
||||
.autocomplete-item:hover { background-color: var(--bg-input); }
|
||||
.autocomplete-count { color: var(--text-muted); font-size: 12px; }
|
||||
|
||||
/* Filters */
|
||||
.rating-filters { display: flex; gap: 5px; }
|
||||
.rating-btn { background: transparent; color: white; border: 1px solid; width: 24px; height: 24px; border-radius: 3px; cursor: pointer; font-size: 12px; font-weight: bold; }
|
||||
.rating-btn.active { opacity: 1; }
|
||||
.rating-btn:not(.active) { opacity: 0.3; }
|
||||
#btn-e { border-color: var(--color-e); color: var(--color-e); }
|
||||
#btn-q { border-color: var(--color-q); color: var(--color-q); }
|
||||
#btn-s { border-color: var(--color-s); color: var(--color-s); }
|
||||
#btn-g { border-color: var(--color-g); color: var(--color-g); }
|
||||
|
||||
/* Main Content */
|
||||
main { padding: 20px; max-width: 1600px; margin: 0 auto; }
|
||||
.results-header { font-size: 18px; font-weight: bold; margin-bottom: 20px; }
|
||||
.pagination-container { display: flex; justify-content: center; gap: 10px; margin: 20px 0; }
|
||||
.pagination-btn { background-color: var(--bg-header); border: 1px solid var(--border-color); color: var(--text-muted); padding: 5px 12px; cursor: pointer; border-radius: 3px; }
|
||||
.pagination-btn:hover:not(:disabled) { background-color: var(--bg-input); color: white; }
|
||||
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
|
||||
.card { background-color: var(--bg-card); display: flex; flex-direction: column; border-radius: 3px; overflow: hidden; }
|
||||
.card-image-container { width: 100%; aspect-ratio: 1/1; background-color: #333; }
|
||||
.card-meta { padding: 6px; text-align: center; font-size: 10px; color: var(--text-muted); }
|
||||
.loader { text-align: center; padding: 50px; color: var(--text-muted); grid-column: 1/-1; }
|
||||
|
||||
@media (max-width: 600px) { .search-wrapper { order: 3; max-width: 100%; width: 100%; margin-top: 10px; } }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header>
|
||||
<a href="index.html" class="logo">LocalBooru</a>
|
||||
<a class="analytics" href="analytics.html">📊 Analytics</a>
|
||||
<div class="search-wrapper">
|
||||
<input type="text" id="searchInput" placeholder="Search tags...">
|
||||
<ul id="autocompleteList" class="autocomplete-list"></ul>
|
||||
</div>
|
||||
<div class="rating-filters">
|
||||
<button id="btn-e" class="rating-btn active" data-rating="e">E</button>
|
||||
<button id="btn-q" class="rating-btn active" data-rating="q">Q</button>
|
||||
<button id="btn-s" class="rating-btn active" data-rating="s">S</button>
|
||||
<button id="btn-g" class="rating-btn active" data-rating="g">G</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<div class="results-header" id="resultsCount">Results (0)</div>
|
||||
<div class="pagination-container" id="paginationTop"></div>
|
||||
<div class="grid" id="imageGrid"></div>
|
||||
<div class="pagination-container" id="paginationBottom"></div>
|
||||
</main>
|
||||
|
||||
<script>
|
||||
const state = { page: 0, query: "", ratings: { e: true, q: true, s: true, g: true }, totalPages: 1, totalResults: 0 };
|
||||
|
||||
// Инициализация
|
||||
function init() {
|
||||
setupAutocomplete('searchInput', 'autocompleteList');
|
||||
|
||||
const searchInput = document.getElementById('searchInput');
|
||||
searchInput.addEventListener('keypress', (e) => {
|
||||
if (e.key === 'Enter') {
|
||||
document.getElementById('autocompleteList').style.display = 'none';
|
||||
state.query = searchInput.value;
|
||||
state.page = 0;
|
||||
fetchData();
|
||||
}
|
||||
});
|
||||
|
||||
document.querySelectorAll('.rating-btn').forEach(btn => {
|
||||
btn.addEventListener('click', (e) => {
|
||||
const r = e.target.getAttribute('data-rating');
|
||||
state.ratings[r] = !state.ratings[r];
|
||||
e.target.classList.toggle('active', state.ratings[r]);
|
||||
state.page = 0; fetchData();
|
||||
});
|
||||
});
|
||||
|
||||
fetchData();
|
||||
}
|
||||
|
||||
// Логика автозаполнения
|
||||
function setupAutocomplete(inputId, listId) {
|
||||
const input = document.getElementById(inputId);
|
||||
const list = document.getElementById(listId);
|
||||
let debounceTimer;
|
||||
|
||||
input.addEventListener('input', () => {
|
||||
clearTimeout(debounceTimer);
|
||||
const words = input.value.split(' ');
|
||||
const currentWord = words[words.length - 1];
|
||||
|
||||
if (currentWord.length < 2) {
|
||||
list.style.display = 'none';
|
||||
return;
|
||||
}
|
||||
|
||||
debounceTimer = setTimeout(async () => {
|
||||
const req = { type: "autocomplete", q: currentWord };
|
||||
console.log("-> Отправка API Автозаполнения:", JSON.stringify(req));
|
||||
|
||||
// Заглушка API. Для реального бэка: fetch('/api', { body: JSON.stringify(req)... })
|
||||
const data = await mockAutocompleteAPI(req);
|
||||
|
||||
if (data.length === 0) {
|
||||
list.style.display = 'none';
|
||||
return;
|
||||
}
|
||||
|
||||
list.innerHTML = data.map(item => `
|
||||
<li class="autocomplete-item" data-tag="${item.tag}">
|
||||
<span>${item.tag}</span><span class="autocomplete-count">${item.count}</span>
|
||||
</li>
|
||||
`).join('');
|
||||
list.style.display = 'block';
|
||||
|
||||
list.querySelectorAll('.autocomplete-item').forEach(li => {
|
||||
li.addEventListener('click', () => {
|
||||
words[words.length - 1] = li.getAttribute('data-tag');
|
||||
input.value = words.join(' ') + ' ';
|
||||
list.style.display = 'none';
|
||||
input.focus();
|
||||
});
|
||||
});
|
||||
}, 200); // 200ms задержка перед запросом
|
||||
});
|
||||
|
||||
// Скрываем список при клике вне него
|
||||
document.addEventListener('click', (e) => {
|
||||
if (e.target !== input && e.target !== list) list.style.display = 'none';
|
||||
});
|
||||
}
|
||||
|
||||
async function fetchData() {
|
||||
const grid = document.getElementById('imageGrid');
|
||||
grid.innerHTML = `<div class="loader">Загрузка...</div>`;
|
||||
const activeRatings = Object.keys(state.ratings).filter(k => state.ratings[k]).join('+');
|
||||
const req = { page: state.page, query: state.query.trim(), rating: activeRatings };
|
||||
|
||||
// Заглушка API Поиска
|
||||
const data = await mockSearchAPI(req);
|
||||
state.totalResults = data.total_results; state.totalPages = data.total_pages;
|
||||
|
||||
document.getElementById('resultsCount').textContent = `Results (${state.totalResults})`;
|
||||
grid.innerHTML = data.items.map(i => `
|
||||
<div class="card">
|
||||
<div class="card-image-container" style="background-color: hsl(${Math.random() * 360}, 20%, 30%);"></div>
|
||||
<div class="card-meta">Date: ${i.date}<br>Score: ${i.score} | Rating: <span style="color:var(--color-${i.rating[0].toLowerCase()})">${i.rating}</span></div>
|
||||
</div>
|
||||
`).join('');
|
||||
renderPagination();
|
||||
}
|
||||
|
||||
function renderPagination() {
|
||||
const html = `
|
||||
<button class="pagination-btn" onclick="changePage(0)" ${state.page === 0 ? 'disabled' : ''}>« First</button>
|
||||
<button class="pagination-btn" onclick="changePage(${state.page - 1})" ${state.page === 0 ? 'disabled' : ''}>‹ Prev</button>
|
||||
<span style="font-size:12px; font-weight:bold;">Page ${state.page + 1} of ${state.totalPages}</span>
|
||||
<button class="pagination-btn" onclick="changePage(${state.page + 1})" ${state.page >= state.totalPages - 1 ? 'disabled' : ''}>Next ›</button>
|
||||
<button class="pagination-btn" onclick="changePage(${state.totalPages - 1})" ${state.page >= state.totalPages - 1 ? 'disabled' : ''}>Last »</button>
|
||||
`;
|
||||
document.getElementById('paginationTop').innerHTML = html;
|
||||
document.getElementById('paginationBottom').innerHTML = html;
|
||||
}
|
||||
|
||||
window.changePage = (p) => { state.page = p; fetchData(); window.scrollTo(0,0); };
|
||||
|
||||
// --- ВРЕМЕННЫЕ API ЗАГЛУШКИ ---
|
||||
function mockAutocompleteAPI(req) {
|
||||
return new Promise(res => {
|
||||
const db = [{tag: "long_hair", count: 8184}, {tag: "long_sleeves", count: 2828}, {tag: "looking_at_viewer", count: 8062}, {tag: "1girl", count: 11061}, {tag: "highres", count: 12700}, {tag: "absurdres", count: 6742}];
|
||||
res(db.filter(t => t.tag.includes(req.q.toLowerCase())));
|
||||
});
|
||||
}
|
||||
|
||||
function mockSearchAPI(req) {
|
||||
return new Promise(res => { setTimeout(() => {
|
||||
const items = [];
|
||||
if(req.rating.length > 0) {
|
||||
const rArr = req.rating.split('+');
|
||||
const rMap = {'g':'general','s':'sensitive','q':'questionable','e':'explicit'};
|
||||
for(let i=0; i<48; i++) items.push({ date: '2026-05-20', score: 10, rating: rMap[rArr[Math.floor(Math.random()*rArr.length)]] });
|
||||
}
|
||||
res({ total_results: 14003, total_pages: 281, items });
|
||||
}, 300);});
|
||||
}
|
||||
|
||||
init();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,267 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Post - LocalBooru</title>
|
||||
<style>
|
||||
:root {
|
||||
--bg-main: #1e1e1e;
|
||||
--bg-header: #252525;
|
||||
--bg-panel: #2a2a2a;
|
||||
--bg-input: #333;
|
||||
--text-main: #eee;
|
||||
--text-muted: #aaa;
|
||||
--border-color: #444;
|
||||
--link-color: #4da8da;
|
||||
|
||||
--color-g: #4caf50;
|
||||
--color-s: #ff9800;
|
||||
--color-q: #ffeb3b;
|
||||
--color-e: #f44336;
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
|
||||
body {
|
||||
background-color: var(--bg-main);
|
||||
color: var(--text-main);
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
header {
|
||||
display: flex; align-items: center; background-color: var(--bg-header);
|
||||
padding: 10px 20px; border-bottom: 1px solid var(--border-color); gap: 15px;
|
||||
}
|
||||
.logo { font-weight: bold; font-size: 18px; color: white; text-decoration: none; }
|
||||
|
||||
/* Search & Autocomplete */
|
||||
.search-wrapper { flex-grow: 1; max-width: 400px; position: relative; }
|
||||
.search-wrapper input {
|
||||
width: 100%; background-color: var(--bg-input); border: 1px solid var(--border-color);
|
||||
color: white; padding: 6px 10px; border-radius: 3px; outline: none;
|
||||
}
|
||||
.search-wrapper input:focus { border-color: var(--text-muted); }
|
||||
.autocomplete-list {
|
||||
position: absolute; top: 100%; left: 0; right: 0; background-color: var(--bg-panel);
|
||||
border: 1px solid var(--border-color); border-radius: 3px; margin-top: 4px;
|
||||
list-style: none; z-index: 1000; max-height: 250px; overflow-y: auto;
|
||||
box-shadow: 0 4px 10px rgba(0,0,0,0.5); display: none;
|
||||
}
|
||||
.autocomplete-item { padding: 8px 10px; cursor: pointer; display: flex; justify-content: space-between; border-bottom: 1px solid #333; }
|
||||
.autocomplete-item:last-child { border-bottom: none; }
|
||||
.autocomplete-item:hover { background-color: var(--bg-input); }
|
||||
.autocomplete-count { color: var(--text-muted); font-size: 12px; }
|
||||
|
||||
main {
|
||||
padding: 20px;
|
||||
max-width: 1600px;
|
||||
margin: 0 auto;
|
||||
display: grid;
|
||||
grid-template-columns: 300px 1fr;
|
||||
gap: 20px;
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
background-color: var(--bg-panel); border: 1px solid var(--border-color);
|
||||
border-radius: 4px; padding: 15px; display: flex; flex-direction: column; gap: 20px;
|
||||
}
|
||||
|
||||
.section-title { font-size: 16px; font-weight: bold; border-bottom: 1px solid var(--border-color); padding-bottom: 8px; margin-bottom: 10px; }
|
||||
.stat-row { margin-bottom: 6px; line-height: 1.4; word-break: break-all;}
|
||||
.stat-label { font-weight: bold; }
|
||||
|
||||
.stat-val-g { color: var(--color-g); }
|
||||
.stat-val-s { color: var(--color-s); }
|
||||
.stat-val-q { color: var(--color-q); }
|
||||
.stat-val-e { color: var(--color-e); }
|
||||
|
||||
.tags-list { display: flex; flex-direction: column; gap: 6px; }
|
||||
.tags-list a { color: var(--link-color); text-decoration: none; word-break: break-word; }
|
||||
.tags-list a:hover { text-decoration: underline; }
|
||||
|
||||
.media-container {
|
||||
background-color: var(--bg-panel); border: 1px solid var(--border-color);
|
||||
border-radius: 4px; padding: 20px; display: flex; justify-content: center;
|
||||
align-items: center; min-height: 400px;
|
||||
}
|
||||
|
||||
.media-container img, .media-container video { max-width: 100%; max-height: 85vh; object-fit: contain; border-radius: 2px; }
|
||||
|
||||
.loader { grid-column: 1 / -1; text-align: center; padding: 50px; color: var(--text-muted); }
|
||||
|
||||
@media (max-width: 900px) {
|
||||
main { grid-template-columns: 1fr; }
|
||||
.media-container { order: -1; }
|
||||
header { flex-wrap: wrap; }
|
||||
.search-wrapper { min-width: 100%; order: 3; margin-top: 10px; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header>
|
||||
<a href="index.html" class="logo">LocalBooru</a>
|
||||
<div class="search-wrapper">
|
||||
<input type="text" id="searchInput" placeholder="Search tags...">
|
||||
<ul id="autocompleteList" class="autocomplete-list"></ul>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main id="mainContent">
|
||||
<div class="loader" id="loader">Загрузка поста...</div>
|
||||
</main>
|
||||
|
||||
<script>
|
||||
// Инициализация поиска с автодополнением
|
||||
const searchInput = document.getElementById('searchInput');
|
||||
const list = document.getElementById('autocompleteList');
|
||||
let debounceTimer;
|
||||
|
||||
searchInput.addEventListener('input', () => {
|
||||
clearTimeout(debounceTimer);
|
||||
const words = searchInput.value.split(' ');
|
||||
const currentWord = words[words.length - 1];
|
||||
|
||||
if (currentWord.length < 2) { list.style.display = 'none'; return; }
|
||||
|
||||
debounceTimer = setTimeout(async () => {
|
||||
const req = { type: "autocomplete", q: currentWord };
|
||||
|
||||
// РЕАЛЬНОЕ API: const data = await fetch('/api', ...);
|
||||
const data = await mockAutocompleteAPI(req);
|
||||
|
||||
if (data.length === 0) { list.style.display = 'none'; return; }
|
||||
|
||||
list.innerHTML = data.map(item => `
|
||||
<li class="autocomplete-item" data-tag="${item.tag}">
|
||||
<span>${item.tag}</span><span class="autocomplete-count">${item.count}</span>
|
||||
</li>
|
||||
`).join('');
|
||||
list.style.display = 'block';
|
||||
|
||||
list.querySelectorAll('.autocomplete-item').forEach(li => {
|
||||
li.addEventListener('click', () => {
|
||||
words[words.length - 1] = li.getAttribute('data-tag');
|
||||
searchInput.value = words.join(' ') + ' ';
|
||||
list.style.display = 'none';
|
||||
searchInput.focus();
|
||||
});
|
||||
});
|
||||
}, 200);
|
||||
});
|
||||
|
||||
// Скрываем список при клике вне него
|
||||
document.addEventListener('click', (e) => {
|
||||
if (e.target !== searchInput && e.target !== list) list.style.display = 'none';
|
||||
});
|
||||
|
||||
// Переход на главную при нажатии Enter
|
||||
searchInput.addEventListener('keypress', (e) => {
|
||||
if(e.key === 'Enter') window.location.href = `index.html?query=${searchInput.value.trim()}`;
|
||||
});
|
||||
|
||||
|
||||
// Загрузка поста
|
||||
async function fetchPost() {
|
||||
let postId = new URLSearchParams(window.location.search).get('id');
|
||||
if (!postId) postId = window.location.pathname.split('/').pop();
|
||||
|
||||
if (!postId || postId.includes('.html')) {
|
||||
document.getElementById('mainContent').innerHTML = `<div class="loader">Ошибка: ID поста не найден</div>`;
|
||||
return;
|
||||
}
|
||||
|
||||
const requestBody = { type: "post", post_id: postId };
|
||||
|
||||
try {
|
||||
// РЕАЛЬНОЕ API: fetch('/api', ...);
|
||||
const data = await generateMockPostData(requestBody);
|
||||
renderPost(data);
|
||||
} catch (error) {
|
||||
document.getElementById('mainContent').innerHTML = `<div class="loader">Ошибка загрузки</div>`;
|
||||
}
|
||||
}
|
||||
|
||||
function renderPost(data) {
|
||||
const main = document.getElementById('mainContent');
|
||||
|
||||
let mediaHtml = '';
|
||||
if (data.media_type === 'video') {
|
||||
mediaHtml = `<video controls autoplay loop src="${data.media_url}"></video>`;
|
||||
} else {
|
||||
mediaHtml = `<img src="${data.media_url}" alt="Post Media">`;
|
||||
}
|
||||
|
||||
const tagsHtml = data.tags.map(tag => `<a href="index.html?query=${tag}">${tag}</a>`).join('');
|
||||
|
||||
main.innerHTML = `
|
||||
<aside class="sidebar">
|
||||
<div class="statistics">
|
||||
<div class="section-title">Statistics</div>
|
||||
<div class="stat-row"><span class="stat-label">File:</span> ${data.file_name}</div>
|
||||
<div class="stat-row"><span class="stat-label">Date:</span> ${data.date}</div>
|
||||
<div class="stat-row"><span class="stat-label">Rating:</span> <span class="stat-val-${data.rating[0].toLowerCase()}">${data.rating}</span></div>
|
||||
<div class="stat-row"><span class="stat-label">Score:</span> ${data.score}</div>
|
||||
<div class="stat-row"><span class="stat-label">Size:</span> ${data.size}</div>
|
||||
<div class="stat-row"><span class="stat-label">Source:</span> <a href="${data.source}" style="color: var(--link-color); text-decoration: none;">Link</a></div>
|
||||
</div>
|
||||
|
||||
<div class="tags">
|
||||
<div class="section-title">Tags</div>
|
||||
<div class="tags-list">
|
||||
${tagsHtml}
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<div class="media-container">
|
||||
${mediaHtml}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
// --- ВРЕМЕННЫЕ ЗАГЛУШКИ ДЛЯ API ---
|
||||
function mockAutocompleteAPI(req) {
|
||||
return new Promise(res => {
|
||||
const db = [
|
||||
{tag: "long_hair", count: 8184}, {tag: "long_sleeves", count: 2828},
|
||||
{tag: "looking_at_viewer", count: 8062}, {tag: "1girl", count: 11061},
|
||||
{tag: "blue_hair", count: 3279}, {tag: "blue_eyes", count: 3279}
|
||||
];
|
||||
res(db.filter(t => t.tag.includes(req.q.toLowerCase())));
|
||||
});
|
||||
}
|
||||
|
||||
function generateMockPostData(req) {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
resolve({
|
||||
post_id: req.post_id,
|
||||
file_name: `${req.post_id}.jpg`,
|
||||
date: "2026-05-24",
|
||||
rating: "general",
|
||||
score: 0,
|
||||
size: "3916x3062",
|
||||
source: "#",
|
||||
media_type: "image",
|
||||
media_url: "data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22800%22%20height%3D%22600%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20fill%3D%22%23444%22%2F%3E%3Ctext%20x%3D%2250%25%22%20y%3D%2250%25%22%20fill%3D%22%23fff%22%20font-size%3D%2224%22%20text-anchor%3D%22middle%22%3E%D0%9F%D0%BB%D0%B5%D0%B9%D1%81%D1%85%D0%BE%D0%BB%D0%B4%D0%B5%D1%80%3C%2Ftext%3E%3C%2Fsvg%3E",
|
||||
tags: [
|
||||
"1boy", "absurdres", "arknights", "blue_hair", "blue_neckerchief",
|
||||
"commentary", "english_commentary", "gloves", "hat", "highres",
|
||||
"holding", "holding_umbrella", "infection_monitor_(arknights)",
|
||||
"looking_at_viewer", "male_focus", "mizuki_(arknights)", "neckerchief",
|
||||
"pink_eyes", "pppmepl", "rain", "smile", "solo", "teruterubouzu",
|
||||
"trap", "umbrella", "upper_body"
|
||||
]
|
||||
});
|
||||
}, 300);
|
||||
});
|
||||
}
|
||||
|
||||
fetchPost();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user