Created
December 6, 2018 00:31
-
-
Save phette23/fc9811570c097453ebd9477c9b8d18ca to your computer and use it in GitHub Desktop.
bulk download attachments from a list of item UUIDs (openEQUELLA)
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
#!/usr/bin/env node | |
// given a set of item UUIDs, download all their attached files | |
// .equellarc file with credentials for API use | |
let options = require('rc')('equella', {}) | |
let headers = { 'X-Authorization': 'access_token=' + options.token } | |
const fs = require('fs') | |
const request = require('request') | |
// construct API URL | |
let base_url = 'https://vault.cca.edu/api/item/' | |
// paste list of UUIDs/versions here e.g. 'abdecf-1234/1/' | |
// easy way to get UUIDs is to search, set max view per page | |
// then run this in chrome dev tools: | |
// a = []; $('.titlelink').each(function(){ a.push(this.href.replace(/.*\/items\//,'')) }); copy(a) | |
let items = [ | |
"4a07bbae-f584-4fa5-9280-e85cbf7b9dc5/1/", | |
"0ddae300-55bd-400d-b8d3-7f411c990813/1/", | |
"a4fe946d-43d7-4250-b1e8-18bbae3362b8/1/" | |
] | |
items.forEach((item) => { | |
request.get(base_url + item, | |
{ | |
'headers': headers, | |
'json': true | |
}, | |
(err, response, data) => { | |
data.attachments.forEach( (att) => { | |
if (att.type === 'file') { | |
console.log(`Downloading ${att.filename} from item ${data.links.view}`) | |
let file_url = 'https://vault.cca.edu/file/' + item + att.filename | |
request.get(file_url, {'headers': headers}) | |
.on('error', err => console.log(err)) | |
.pipe(fs.createWriteStream(att.filename)) | |
} | |
}) | |
} | |
).on('error', err => console.log(err)) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment