Skip to content

Instantly share code, notes, and snippets.

@MightyPork
Created May 6, 2018 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MightyPork/5594cfb20157d02e2e7c4180b0cd23e1 to your computer and use it in GitHub Desktop.
Save MightyPork/5594cfb20157d02e2e7c4180b0cd23e1 to your computer and use it in GitHub Desktop.
extract ordered attachments from the mastodon export / take-out archive
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