fix: createAssetFromPicked() now passes original File with EXIF
- Set manualPhotoFile = pickedPhotoFile directly (preserves EXIF) - Set manualPhotoBlob = pickedPhotoFile (preserves EXIF) - Keep FileReader for preview display only - Trigger EXIF GPS extraction via extractGpsFromPhoto() - Fill GPS coordinates into manual form (parking + map link) Previously the function used readAsDataURL -> atob -> Blob which stripped all EXIF metadata. Now the original File flows through to submitManualAsset where exifr.parse() re-embeds EXIF on the server.
This commit is contained in:
+23
-11
@@ -1794,21 +1794,18 @@
|
|||||||
showToast('GPS data will be extracted server-side — check EXIF info below for file details');
|
showToast('GPS data will be extracted server-side — check EXIF info below for file details');
|
||||||
}
|
}
|
||||||
|
|
||||||
function createAssetFromPicked() {
|
async function createAssetFromPicked() {
|
||||||
if (!pickedPhotoFile) return;
|
if (!pickedPhotoFile) return;
|
||||||
// Switch to Manual mode and pre-load the photo
|
// Switch to Manual mode and pass the original file (preserves EXIF)
|
||||||
setAddAssetMode('manual');
|
setAddAssetMode('manual');
|
||||||
|
|
||||||
|
// Pass the original File directly — preserves EXIF for server re-embed
|
||||||
|
manualPhotoFile = pickedPhotoFile;
|
||||||
|
manualPhotoBlob = pickedPhotoFile; // Use original file (preserves EXIF)
|
||||||
|
|
||||||
|
// Show the photo in the manual preview using FileReader
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.onload = function(e) {
|
reader.onload = function(e) {
|
||||||
// Convert data URL to blob for manualPhotoBlob
|
|
||||||
const arr = e.target.result.split(',');
|
|
||||||
const mime = arr[0].match(/:(.*?);/)[1];
|
|
||||||
const bstr = atob(arr[1]);
|
|
||||||
let n = bstr.length;
|
|
||||||
const u8arr = new Uint8Array(n);
|
|
||||||
while (n--) { u8arr[n] = bstr.charCodeAt(n); }
|
|
||||||
manualPhotoBlob = new Blob([u8arr], { type: mime });
|
|
||||||
// Show the photo in the manual preview
|
|
||||||
const img = document.getElementById('manPhotoPreview');
|
const img = document.getElementById('manPhotoPreview');
|
||||||
img.src = e.target.result;
|
img.src = e.target.result;
|
||||||
img.style.display = 'block';
|
img.style.display = 'block';
|
||||||
@@ -1818,6 +1815,21 @@
|
|||||||
if (retake) retake.style.display = 'block';
|
if (retake) retake.style.display = 'block';
|
||||||
};
|
};
|
||||||
reader.readAsDataURL(pickedPhotoFile);
|
reader.readAsDataURL(pickedPhotoFile);
|
||||||
|
|
||||||
|
// Try EXIF GPS from the original file
|
||||||
|
manualPhotoGps = await extractGpsFromPhoto(pickedPhotoFile);
|
||||||
|
if (manualPhotoGps) {
|
||||||
|
const coords = manualPhotoGps.lat.toFixed(6) + ', ' + manualPhotoGps.lng.toFixed(6);
|
||||||
|
const parkingEl = document.getElementById('manParkingLocation');
|
||||||
|
if (parkingEl && !parkingEl.value.trim()) {
|
||||||
|
parkingEl.value = coords;
|
||||||
|
}
|
||||||
|
const mapLinkEl = document.getElementById('manMapLink');
|
||||||
|
if (mapLinkEl && !mapLinkEl.value.trim()) {
|
||||||
|
mapLinkEl.value = `https://www.openstreetmap.org/?mlat=${manualPhotoGps.lat}&mlon=${manualPhotoGps.lng}&zoom=17`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
showToast('Photo loaded into Manual mode');
|
showToast('Photo loaded into Manual mode');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user