Skip to content

Commit 748cb3f

Browse files
authored
Merge pull request #15 from hothsys/export-fix
Exclude empty pins from export
2 parents 27b16ab + e0b66a6 commit 748cb3f

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

js/data.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,23 @@ async function _decompressGzip(blob) {
150150
function exportData() {
151151
document.getElementById('settings-dropdown').classList.remove('open');
152152
if (!photos.length && !albums.length) { showToast('No data to export','error'); return; }
153+
const realPhotos = photos.filter(p => !p.isEmptyPin);
154+
const emptyCount = photos.length - realPhotos.length;
155+
if (realPhotos.length === 0) { showToast('No photos to export — only empty pins found','error'); return; }
156+
if (emptyCount > 0) showToast(`Exporting ${realPhotos.length} photo${realPhotos.length!==1?'s':''} (${emptyCount} empty pin${emptyCount!==1?'s':''} excluded)`, 'info');
153157
showProg(true);
154158
updProg(5, 'Preparing data...');
155159
// Defer the heavy work so the progress bar renders immediately
156160
setTimeout(() => _doExport(), 50);
157161
}
158162
async function _doExport() {
159-
// Strip large binary fields — full-size images are stored on disk by serve.py,
160-
// thumbnails are regenerated on import. Including them causes "Invalid string length"
161-
// errors on large datasets (>512MB V8 string limit).
162-
const exportPhotos = photos.map(p => {
163+
// Replace base64 dataUrl with the server file path — full-size images live in
164+
// matrix-photos/ on disk. On import, the path is resolved back to a data URL.
165+
// This avoids "Invalid string length" errors on large datasets (>512MB V8 limit).
166+
const exportPhotos = photos.filter(p => !p.isEmptyPin).map(p => {
163167
const { dataUrl, ...rest } = p;
164-
return rest;
168+
const ext = (dataUrl && dataUrl.match(/data:image\/(\w+)/)?.[1] === 'png') ? 'png' : 'jpg';
169+
return { ...rest, dataUrl: `matrix-photos/${p.id}.${ext}` };
165170
});
166171
const payload = { version: 1, exportedAt: Date.now(), photos: exportPhotos, albums, geoCodeCache: {..._geoCodeCache}, geoCountryCache: {..._geoCountryCache} };
167172
const json = JSON.stringify(payload);

0 commit comments

Comments
 (0)