Skip to content

Instantly share code, notes, and snippets.

@puleddu
Last active October 8, 2023 10:43
Show Gist options
  • Save puleddu/2f1afc08b5d5e0ec2a0d5687cb2f195c to your computer and use it in GitHub Desktop.
Save puleddu/2f1afc08b5d5e0ec2a0d5687cb2f195c to your computer and use it in GitHub Desktop.
Migrate Ember app snaps to Eagle
const sqlite3 = require('better-sqlite3');
const {globSync} = require('glob');
const db = new sqlite3('./EmberLibrary/Stores.nosync/EmberLibrary.sqlite', { verbose: console.log });
const results = db.prepare('SELECT * FROM ZEMBSNAP ORDER BY ZDATE ASC');
const snaps = [];
for (const row of results.iterate()) {
const snapFilePath = './EmberLibrary/Snaps/' + row.ZDOCUMENTPATH + '/*.{png,gif,jpg,jpeg,webp,svg,tiff}';
const images = globSync(snapFilePath, {absolute: true, ignore: '**/**/compositedImage.*'});
const snap = {
'path': images[0],
'name': row.ZTITLE,
'website': row.ZURLSTRING ? row.ZURLSTRING : '',
'annotation': row.ZCOMMENTS ? row.ZCOMMENTS : ''
};
snaps.push(snap);
}
console.log('Connecting to Eagle...');
fetch('http://localhost:41595/api/item/addFromPaths', {
method: 'POST',
body: JSON.stringify({'items': snaps}),
redirect: 'follow'
})
.then(response => response.json())
.then(result => console.log(result))
.catch(error => console.log('error', error));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment