fix: sửa lỗi iphone ko thể upload
This commit is contained in:
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+4
-4
File diff suppressed because one or more lines are too long
-2
File diff suppressed because one or more lines are too long
+2
File diff suppressed because one or more lines are too long
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+2
-2
@@ -5,8 +5,8 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||
<title>Travel Planner</title>
|
||||
<script type="module" crossorigin src="/assets/index-D9CLCU9L.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-S9boMaIB.css">
|
||||
<script type="module" crossorigin src="/assets/index-D1uuLlpI.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-f6lAQjsT.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
|
||||
@@ -130,7 +130,7 @@ export const PublicPhotoModal: React.FC<PublicPhotoModalProps> = ({
|
||||
}
|
||||
}
|
||||
|
||||
const res = await fetch(`/api/v1/public-photos/${photo.id}/comments`, {
|
||||
let res = await fetch(`/api/v1/public-photos/${photo.id}/comments`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -138,6 +138,37 @@ export const PublicPhotoModal: React.FC<PublicPhotoModalProps> = ({
|
||||
},
|
||||
body: JSON.stringify({ content: newComment })
|
||||
});
|
||||
|
||||
if (res.status === 401) {
|
||||
console.warn('Token invalid or expired. Creating a new guest user and retrying comment...');
|
||||
localStorage.removeItem('guest_token');
|
||||
localStorage.removeItem('guest_user');
|
||||
localStorage.removeItem('token');
|
||||
localStorage.removeItem('user');
|
||||
|
||||
const guestRes = await fetch('/api/v1/auth/create-guest', { method: 'POST' });
|
||||
if (!guestRes.ok) throw new Error('Không thể tạo lại phiên khách.');
|
||||
const guestData = await guestRes.json();
|
||||
token = guestData.access_token;
|
||||
currentUser = guestData.user;
|
||||
localStorage.setItem('guest_token', token!);
|
||||
localStorage.setItem('guest_user', JSON.stringify(currentUser));
|
||||
localStorage.setItem('token', token!);
|
||||
localStorage.setItem('user', JSON.stringify(currentUser));
|
||||
|
||||
if (onLoginSuccess) {
|
||||
onLoginSuccess(currentUser);
|
||||
}
|
||||
|
||||
res = await fetch(`/api/v1/public-photos/${photo.id}/comments`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`
|
||||
},
|
||||
body: JSON.stringify({ content: newComment })
|
||||
});
|
||||
}
|
||||
|
||||
if (res.ok) {
|
||||
setNewComment('');
|
||||
|
||||
@@ -101,18 +101,21 @@ export const LandingPage: React.FC<LandingPageProps> = ({ onContinue, onGoToSign
|
||||
notify({ title: 'Đang xử lý...', message: 'Vui lòng chờ trong giây lát.', type: 'info' });
|
||||
|
||||
try {
|
||||
// Lấy tọa độ hiện tại của người dùng để làm tọa độ dự phòng
|
||||
const location = await new Promise<GeolocationPosition | null>((resolve) => {
|
||||
if (!navigator.geolocation) {
|
||||
resolve(null);
|
||||
} else {
|
||||
navigator.geolocation.getCurrentPosition(
|
||||
(pos) => resolve(pos),
|
||||
() => resolve(null),
|
||||
{ timeout: 5000, enableHighAccuracy: true }
|
||||
);
|
||||
}
|
||||
});
|
||||
// Lấy tọa độ hiện tại của người dùng với cơ chế chống treo (Promise.race)
|
||||
const location = await Promise.race([
|
||||
new Promise<GeolocationPosition | null>((resolve) => {
|
||||
if (!navigator.geolocation) {
|
||||
resolve(null);
|
||||
} else {
|
||||
navigator.geolocation.getCurrentPosition(
|
||||
(pos) => resolve(pos),
|
||||
() => resolve(null),
|
||||
{ timeout: 4000, enableHighAccuracy: true }
|
||||
);
|
||||
}
|
||||
}),
|
||||
new Promise<null>((resolve) => setTimeout(() => resolve(null), 4500))
|
||||
]);
|
||||
|
||||
// 1. Tạo tài khoản khách và lấy token
|
||||
let guestToken = localStorage.getItem('guest_token');
|
||||
@@ -136,12 +139,34 @@ export const LandingPage: React.FC<LandingPageProps> = ({ onContinue, onGoToSign
|
||||
formData.append('longitude', location.coords.longitude.toString());
|
||||
}
|
||||
|
||||
const uploadRes = await fetch('/api/v1/photos/upload-anonymous', {
|
||||
let uploadRes = await fetch('/api/v1/photos/upload-anonymous', {
|
||||
method: 'POST',
|
||||
headers: { 'Authorization': `Bearer ${guestToken!}` },
|
||||
body: formData,
|
||||
});
|
||||
|
||||
if (uploadRes.status === 401) {
|
||||
console.warn('Guest token invalid or expired. Creating a new guest user and retrying...');
|
||||
localStorage.removeItem('guest_token');
|
||||
localStorage.removeItem('guest_user');
|
||||
localStorage.removeItem('token');
|
||||
localStorage.removeItem('user');
|
||||
|
||||
const guestRes = await fetch('/api/v1/auth/create-guest', { method: 'POST' });
|
||||
if (!guestRes.ok) throw new Error('Không thể tạo lại phiên khách.');
|
||||
const guestData = await guestRes.json();
|
||||
guestToken = guestData.access_token;
|
||||
guestUser = guestData.user;
|
||||
localStorage.setItem('guest_token', guestToken!);
|
||||
localStorage.setItem('guest_user', JSON.stringify(guestUser));
|
||||
|
||||
uploadRes = await fetch('/api/v1/photos/upload-anonymous', {
|
||||
method: 'POST',
|
||||
headers: { 'Authorization': `Bearer ${guestToken!}` },
|
||||
body: formData,
|
||||
});
|
||||
}
|
||||
|
||||
if (!uploadRes.ok) {
|
||||
const errorData = await uploadRes.json();
|
||||
throw new Error(errorData.message || 'Tải ảnh thất bại.');
|
||||
|
||||
Reference in New Issue
Block a user