Last active
October 8, 2023 10:43
-
-
Save puleddu/2f1afc08b5d5e0ec2a0d5687cb2f195c to your computer and use it in GitHub Desktop.
Migrate Ember app snaps to Eagle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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