Created
May 6, 2018 08:13
-
-
Save MightyPork/5594cfb20157d02e2e7c4180b0cd23e1 to your computer and use it in GitHub Desktop.
extract ordered attachments from the mastodon export / take-out archive
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 fs = require('fs') | |
const array = JSON.parse(fs.readFileSync('outbox.json')).orderedItems | |
const dir = 'pics' | |
if (!fs.existsSync(dir)){ | |
fs.mkdirSync(dir) | |
} | |
array.forEach((msg, i) => { | |
if (msg.type == 'Create' && msg.object.attachment.length > 0) { | |
msg.object.attachment.forEach((att, i) => { | |
fs.copyFile('./'+att.url, dir+'/'+msg.published+'_'+i+att.url.substr(att.url.lastIndexOf('.')), ()=>{}) | |
}) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment