Lỗi có thể di chuyển tù sharedlink sang public nhưng không có hotspot quay lại

This commit is contained in:
2026-06-11 16:27:37 +07:00
parent be149f26ca
commit 0434837026
7 changed files with 1055 additions and 47 deletions
+16 -31
View File
@@ -993,14 +993,6 @@ async function loadScenes(urlToken = null) {
return;
}
// 2. Logic lọc Ảnh mẹ: Sửa lỗi typo coordKey (dùng latNum 2 lần)
const coordKey = `${latNum.toFixed(6)},${lngNum.toFixed(6)}`;
if (seenCoordinates.has(coordKey)) {
console.log(`[Frontend] Bỏ qua Scene "${scene.name || scene.title}" (ID: ${scene._id}) do trùng tọa độ (hotspot con).`);
return;
}
seenCoordinates.add(coordKey);
// 3. Truy cập Asset an toàn
const assetId = scene.assetId?._id || scene.assetId;
if (!assetId) return; // Bỏ qua nếu không có ảnh liên kết
@@ -1306,11 +1298,10 @@ async function openScene(sceneId, privacy, shareToken, force = false, initialPit
headers['Authorization'] = `Bearer ${token}`;
}
console.log(`[Viewer] Đang mở scene: ${sceneId}`);
let url = `${API_BASE_URL}/scenes/${sceneId}`;
if (privacy === 'shared' && shareToken) {
url += `?token=${shareToken}`;
}
console.log(`[Frontend-Viewer] Đang nạp Scene: ${sceneId}. Token: ${shareToken || 'None'}`);
const authParam = shareToken ? `?token=${shareToken}` : '';
let url = `${API_BASE_URL}/scenes/${sceneId}${authParam}`;
let hotspotsUrl = `${API_BASE_URL}/hotspots/${sceneId}${authParam}`;
// Lưu trạng thái Scene hiện tại để khôi phục sau khi reload trang
localStorage.setItem('activeSceneId', sceneId);
@@ -1320,23 +1311,20 @@ async function openScene(sceneId, privacy, shareToken, force = false, initialPit
// Nạp đồng thời Scene và danh sách Hotspots từ Collection riêng
const [sceneRes, hotspotsRes] = await Promise.all([
fetch(url, { method: 'GET', headers }),
fetch(`${API_BASE_URL}/hotspots/${sceneId}`, { method: 'GET', headers })
fetch(hotspotsUrl, { method: 'GET', headers })
]);
if (!sceneRes.ok) {
const errorData = await sceneRes.json();
console.error(`[Viewer API Error] Scene status: ${sceneRes.status}. Message: ${errorData.message}`);
throw new Error(errorData.message || 'Không thể tải thông tin cảnh');
}
console.log(`[Viewer API Success] Đã nạp xong Scene và Hotspots cho ${sceneId}`);
const scene = await sceneRes.json();
const hotspots = await hotspotsRes.json();
// Ngăn chặn mở Scene nếu ảnh chưa xử lý xong hoặc lỗi
if (scene.status === 'processing') {
showNotification("Cảnh này đang được nén chất lượng 8K. Vui lòng quay lại sau vài giây.", 'warning');
return;
}
if (scene.status === 'failed') {
showNotification("Lỗi xử lý ảnh 8K. Vui lòng upload lại ảnh cho cảnh này.", 'error');
return;
}
// [TOUR ID] Luôn cập nhật activeTourId theo Scene hiện tại để đảm bảo các cảnh con/hotspot mới
// được gán đúng vào Tour gốc của cảnh đang xem, tránh sử dụng ID cũ/lỗi từ phiên trước.
const openedSceneTourId = scene.tourId?._id || scene.tourId || scene._id;
localStorage.setItem('activeTourId', openedSceneTourId);
@@ -1351,10 +1339,6 @@ async function openScene(sceneId, privacy, shareToken, force = false, initialPit
const isOwner = currentUserId && sceneOwnerId && currentUserId.toString() === sceneOwnerId.toString();
const isAdmin = userRole === 'admin' || userRole === 'Chủ sở hữu';
if (scene.privacy === 'private' && !isOwner && !isAdmin) {
throw new Error("Cảnh này đã được chủ sở hữu chuyển sang chế độ riêng tư.");
}
console.log("DEBUG: Hotspots raw data from API:", hotspots);
// Tự động focus bản đồ vào vị trí của Scene
@@ -1406,10 +1390,11 @@ async function openScene(sceneId, privacy, shareToken, force = false, initialPit
// Kiểm tra nếu đang truy cập qua link trực tiếp (URL có sceneId) mà gặp lỗi (do xóa token hoặc token không hợp lệ)
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.has('sceneId') || window.location.pathname.includes('/api/share/')) {
showNotification("Bạn không có quyền truy cập hoặc liên kết chia sẻ đã hết hạn. Quay về bản đồ công cộng.", 'error');
// Xóa toàn bộ tham số URL và tải lại trang để làm mới trạng thái (về trang chủ dành cho khách)
// Sử dụng Error Modal để thông báo không bị biến mất đột ngột
showErrorModal("Bạn không có quyền truy cập hoặc liên kết chia sẻ đã hết hạn. Quay về bản đồ công cộng.", "Lỗi truy cập", "🚫");
// Chỉ xóa tham số URL để làm sạch thanh địa chỉ, không cần reload trang gây văng marker
window.history.replaceState({}, document.title, "/");
location.reload();
return;
}