---
import '../styles/global.css';
import crypto from 'node:crypto';
import Header from '../components/Header.astro';
import Footer from '../components/Footer.jsx';
import SplashScreen from '../components/SplashScreen.jsx';
import { txasupabase } from '../lib/txasupabase.js';
interface Props {
title?: string;
description?: string;
image?: string;
type?: string;
slug?: string;
}
import { ClientRouter } from 'astro:transitions';
const settings = await txasupabase.getSettings() || {};
const siteName = settings.site_name || 'DPTXA';
const siteDescription = settings.site_description || 'DPTXA - Động Phim TXA | Nền tảng xem phim trực tuyến miễn phí với kho phim khổng lồ, cập nhật liên tục mỗi ngày. Phim bộ, phim lẻ, hoạt hình Full HD Vietsub.';
const siteKeywords = settings.site_keywords || 'xem phim online, phim vietsub, phim hd, phim moi, phim bo, phim le, hoat hinh, dptxa, dong phim txa';
const siteUrl = await txasupabase.getSiteUrl(Astro.request);
const {
title = 'Động Phim Đỉnh Cao',
description = siteDescription,
image = 'https://dongmephim.online/og-image.jpg',
type = 'website',
slug = ''
} = Astro.props;
// Automatically replace TPHIMX / DPTXA with the dynamic siteName from Admin Dashboard
const dynamicTitle = title.replace(/TPHIMX|DPTXA/gi, siteName);
const dynamicDescription = description.replace(/TPHIMX|DPTXA/gi, siteName);
const dynamicKeywords = siteKeywords.replace(/TPHIMX|DPTXA/gi, siteName);
// --- REFERRER DECOY GATEKEEPER & ZALO ACCESS GATEKEEPER ---
const currentPath = Astro.url.pathname;
// Các trang được miễn trừ bộ lọc ngụy trang (để Admin làm việc và các API hoạt động)
const isExempted = currentPath.startsWith('/admin') ||
currentPath.startsWith('/api/') ||
currentPath === '/dang-nhap' ||
currentPath === '/dang-ky';
const referer = Astro.request.headers.get('referer') || '';
const url = new URL(Astro.request.url);
const refParam = url.searchParams.get('ref') || url.searchParams.get('from') || '';
const bypassParam = url.searchParams.get('bypass') || '';
let isReferred = Astro.cookies.get('nrotxa_referred')?.value === 'true';
if (bypassParam === 'true') {
isReferred = true;
Astro.cookies.set('nrotxa_referred', 'true', { path: '/', maxAge: 365 * 24 * 60 * 60 });
Astro.cookies.set('zalo_access_approved', 'true', { path: '/', maxAge: 365 * 24 * 60 * 60 });
}
// --- ADMIN ABSOLUTE BYPASS ---
let isAdmin = false;
const token = Astro.cookies.get('auth_token')?.value;
if (token) {
try {
const user = JSON.parse(Buffer.from(token, 'base64').toString('utf-8'));
if (user && user.role === 'admin') {
isAdmin = true;
isReferred = true; // Admin luôn được bypass trang ngụy trang
}
} catch(e) {}
}
// Nếu chưa được xác định nguồn giới thiệu và trang hiện tại không được miễn trừ, tiến hành xác thực bảo mật
if (!isReferred && !isExempted) {
// 1. Xác thực HMAC SHA256 Token bảo mật từ film.nrotxa.online
const SECURE_KEY = 'TPhimX_Gatekeeper_Secret_Signature_Key_2026';
const tTimeParam = url.searchParams.get('t_time') || '';
const tTokenParam = url.searchParams.get('t_token') || '';
let isTokenValid = false;
if (tTimeParam && tTokenParam) {
try {
const timestamp = parseInt(tTimeParam, 10);
const now = Math.floor(Date.now() / 1000);
const timeDiff = Math.abs(now - timestamp);
// Token hợp lệ trong vòng 1 tiếng (3600 giây) kể từ lúc sinh ra
if (timeDiff <= 3600) {
const expectedSignature = crypto
.createHmac('sha256', SECURE_KEY)
.update(tTimeParam)
.digest('hex');
if (crypto.timingSafeEqual(Buffer.from(tTokenParam, 'hex'), Buffer.from(expectedSignature, 'hex'))) {
isTokenValid = true;
}
}
} catch (e) {
console.error("Lỗi xác thực token bảo mật:", e);
}
}
// 2. Chấp nhận nếu token bảo mật hợp lệ HOẶC đi từ domain chính thức cũ qua Referer
const isRefererValid = referer.includes('film.nrotxa.online');
if (isTokenValid || isRefererValid) {
isReferred = true;
Astro.cookies.set('nrotxa_referred', 'true', { path: '/', maxAge: 365 * 24 * 60 * 60 });
}
}
// Nếu không đến từ film.nrotxa.online và không phải trang miễn trừ -> kích hoạt trạng thái ngụy trang (Decoy)
const showDecoy = !isReferred && !isExempted;
// Nếu đã được xác định nguồn giới thiệu, nhưng truy cập trang xem phim/trang chủ mà CHƯA ĐƯỢC DUYỆT Zalo -> đá về Landing Page (/)
let forceRedirect = false;
if (!showDecoy && !isExempted && currentPath !== '/') {
const isApproved = Astro.cookies.get('zalo_access_approved')?.value === 'true';
if (!isApproved && !isAdmin) {
forceRedirect = true;
}
}
const finalTitle = dynamicTitle.includes(siteName) ? dynamicTitle : `${dynamicTitle} | ${siteName}`;
const canonical = `${siteUrl}${slug}`;
// Override metadata for Decoy Tech Blog to ensure Google Search only indexes technology content!
let seoTitle = finalTitle;
let seoDesc = dynamicDescription;
let seoKeywords = dynamicKeywords;
let seoImage = image;
if (showDecoy) {
seoTitle = `TxaTech Studio - Giải Pháp Công Nghệ Đột Phá Doanh Nghiệp 2026`;
seoDesc = `TxaTech Studio chuyên cung cấp giải pháp phần mềm, ứng dụng di động hiệu năng cao và các dịch vụ bảo mật mạng doanh nghiệp toàn diện.`;
seoKeywords = `txatech, lập trình di động, phát triển website, bảo mật hệ thống, phần mềm doanh nghiệp, công nghệ số 2026`;
seoImage = `https://images.unsplash.com/photo-1517694712202-14dd9538aa97?q=80&w=600`;
}
---
Chúng tôi thiết kế và phát triển các sản phẩm phần mềm, ứng dụng di động hiệu năng cao và hệ thống dữ liệu chuyên nghiệp. Hiện đã phục vụ hơn 1500 khách hàng trên toàn cầu.