diff --git a/backend/dist/src/main.js b/backend/dist/src/main.js index a340feb..fd90124 100644 --- a/backend/dist/src/main.js +++ b/backend/dist/src/main.js @@ -2434,6 +2434,96 @@ let PublicPhotoController = class PublicPhotoController { this.commentGateway.notifyNewPhotoComment(photoId, comment); return comment; } + async sharePhoto(photoId, req, res) { + const photo = await this.prisma.photo.findUnique({ + where: { id: photoId } + }); + if (!photo) { + throw new common_1.NotFoundException('Không tìm thấy ảnh.'); + } + let host = req.headers['x-forwarded-host'] || req.headers.host || ''; + const isProxied = !!(req.headers['x-forwarded-proto'] || req.headers['x-forwarded-for']); + const isLocalhost = host.includes('localhost') || host.includes('127.0.0.1'); + if (isLocalhost && isProxied) { + host = 'yotrip.labz.io.vn'; + } + const isLocal = host.includes('localhost') || host.includes('127.0.0.1') || host.startsWith('192.168.') || host.startsWith('10.'); + const protocol = isLocal ? (req.headers['x-forwarded-proto'] || 'http') : 'https'; + const baseUrl = `${protocol}://${host}`; + let title = 'YoTrip - Xem ảnh công khai'; + let description = 'Xem hình ảnh chia sẻ công khai trên bản đồ hành trình YoTrip.'; + if (photo.metadata && typeof photo.metadata === 'object') { + const meta = photo.metadata; + if (meta.title && meta.title.trim()) { + title = meta.title; + } + if (meta.description && meta.description.trim()) { + description = meta.description; + } + } + const fullImageUrl = photo.imageUrl + ? (photo.imageUrl.startsWith('http') ? photo.imageUrl : `${baseUrl}${photo.imageUrl}`) + : ''; + const shareUrl = `${baseUrl}/api/v1/public-photos/${photoId}/share`; + const redirectUrl = `${baseUrl}/?photoId=${photoId}`; + let imageWidth = 1200; + let imageHeight = 630; + try { + if (photo.imageUrl) { + const localImagePath = path.join(process.cwd(), photo.imageUrl.replace(/^\//, '')); + if (fs.existsSync(localImagePath)) { + const imageMeta = await (0, sharp_1.default)(localImagePath).metadata(); + if (imageMeta.width && imageMeta.height) { + imageWidth = imageMeta.width; + imageHeight = imageMeta.height; + } + } + } + } + catch (err) { + console.warn('[Share] Không thể lấy kích thước ảnh:', err.message); + } + const htmlContent = ` + +
+ +Nếu trang không tự động tải, nhấn vào đây.
+Nếu trang không tự động tải, nhấn vào đây.
+