20260607 - login, add scene, add hotspot

This commit is contained in:
2026-06-07 21:31:31 +07:00
parent 10d2e07297
commit 5ba6e37039
29 changed files with 1064 additions and 73 deletions
+15 -3
View File
@@ -48,18 +48,30 @@ const degToDmsRational = (deg) => {
*/
const injectGPSCoordinates = async (filePath, lat, lng) => {
try {
const jpegBinary = fs.readFileSync(filePath).toString('binary');
const data = fs.readFileSync(filePath);
let exifObj = { "0th": {}, "Exif": {}, "GPS": {} };
// Kiểm tra marker SOI (Start of Image) trực tiếp trên Buffer
if (data[0] !== 0xFF || data[1] !== 0xD8) {
throw new Error("Tệp tin không phải là định dạng JPEG hợp lệ (thiếu SOI marker).");
}
const jpegBinary = data.toString('binary');
let exifObj;
try {
exifObj = piexif.load(jpegBinary);
} catch (e) {
// No existing EXIF, start clean
// Nếu không có EXIF hoặc lỗi khi nạp, khởi tạo đối tượng sạch
exifObj = { "0th": {}, "Exif": {}, "GPS": {} };
}
// Đảm bảo các cấu trúc IFD tồn tại trước khi ghi đè
exifObj["GPS"] = exifObj["GPS"] || {};
const latRef = lat >= 0 ? 'N' : 'S';
const lngRef = lng >= 0 ? 'E' : 'W';
// Thêm Version ID (Bắt buộc để một số trình đọc nhận diện khối GPS)
exifObj["GPS"][piexif.GPSIFD.GPSVersionID] = [2, 2, 0, 0];
exifObj["GPS"][piexif.GPSIFD.GPSLatitudeRef] = latRef;
exifObj["GPS"][piexif.GPSIFD.GPSLatitude] = degToDmsRational(lat);
exifObj["GPS"][piexif.GPSIFD.GPSLongitudeRef] = lngRef;
+8 -1
View File
@@ -8,10 +8,17 @@ const sharp = require('sharp');
const resizeTo8K = async (inputPath, outputPath) => {
try {
await sharp(inputPath)
.rotate() // Tự động xoay ảnh dựa trên EXIF orientation
.resize(8192, 4096, {
fit: 'fill' // Ensures the output is exactly 8192x4096
})
.jpeg({ quality: 90 })
.jpeg({
quality: 85,
progressive: false, // Tắt progressive để header đơn giản hơn cho piexifjs
chromaSubsampling: '4:2:0'
})
// Loại bỏ .withMetadata() để Sharp tạo ra file JPEG sạch nhất.
// Điều này giúp piexifjs không bị lỗi "Given data is not jpeg".
.toFile(outputPath);
} catch (error) {
throw new Error(`Sharp image processing failed: ${error.message}`);