Last active
October 12, 2018 23:42
-
-
Save godber/9a234569727b10d5b33d8e12ead8d95a to your computer and use it in GitHub Desktop.
Teraslice dump_asset
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
'use strict'; | |
const argv = require('yargs').argv; | |
const fse = require('fs-extra'); | |
var elasticsearch = require('elasticsearch'); | |
function saveAsset(assetName, assetVersion, binaryData) { | |
const newPath = `${assetName}/${assetVersion}`; | |
const tempFileName = `${newPath}/asset.zip`; | |
return fse.mkdirp(newPath) | |
.then(() => fse.writeFile(tempFileName, binaryData)) | |
.catch((err) => { | |
console.log(err); | |
}); | |
} | |
async function main(esCluster, indexName, assetName) { | |
var client = new elasticsearch.Client({ | |
host: esCluster, | |
// log: 'trace', | |
}); | |
const response = await client.search({ | |
index: indexName, | |
body: { | |
query: { | |
term: {name: assetName}, | |
}, | |
}, | |
}); | |
for (const asset of response.hits.hits) { | |
console.log(`asset:, ${asset._source.name}, ${asset._source.version}`); | |
const binaryData = Buffer.from(asset._source.blob, 'base64'); | |
try { | |
await saveAsset(asset._source.name, asset._source.version, binaryData); | |
} catch (e) { | |
console.log(`ouch ${e}`); | |
} | |
} | |
} | |
main(argv.cluster, argv.index, argv.asset); |
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
{ | |
"name": "dump-assets", | |
"version": "1.0.0", | |
"main": "index.js", | |
"license": "MIT", | |
"dependencies": { | |
"elasticsearch": "^15.1.1", | |
"fs-extra": "^7.0.0", | |
"yargs": "^12.0.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Call with: