Новые изменения в проект

This commit is contained in:
Web-serfer 2026-04-28 02:09:18 +05:00
parent 38bf5d7dcf
commit c369cd30bd
2 changed files with 13 additions and 2 deletions

View file

@ -312,17 +312,22 @@ const {
// 5. СЧЁТЧИК ПРОСМОТРОВ
const viewsEl = document.querySelector('.meta-views') as HTMLElement & { dataset: { postId: string } };
console.log('[Views] Element found:', viewsEl, 'postId:', viewsEl?.dataset?.postId);
if (viewsEl?.dataset?.postId) {
const postId = viewsEl.dataset.postId;
console.log('[Views] Fetching for post:', postId);
fetch(`/api/increment-views?postId=${postId}`)
.then(res => res.json())
.then(data => {
console.log('[Views] Response:', data);
if (data.views !== undefined) {
viewsEl.textContent = formatViews(data.views);
}
})
.catch(() => {});
.catch(err => {
console.error('[Views] Error:', err);
});
}
function formatViews(n: number): string {

View file

@ -10,7 +10,13 @@ function getClientIp(request: Request): string {
if (forwarded) {
return forwarded.split(',')[0].trim();
}
return request.headers.get('x-real-ip') || 'unknown';
const realIp = request.headers.get('x-real-ip');
if (realIp) {
return realIp;
}
// Для localhost использовать заголовок Host или default
const host = request.headers.get('host') || 'localhost';
return host.includes('localhost') || host.includes('127.0.0.1') ? 'localhost' : 'unknown';
}
function generateVisitorHash(ip: string, userAgent: string): string {