matrix-dimension/scripts/stickerpack-to-migration.js
Travis Ralston e8274c9d87 Sticker pack administration
The first step towards #156
2018-05-12 21:55:02 -06:00

40 lines
1.1 KiB
JavaScript

const request = require('request');
const packId = Number(process.argv[2]);
if (!packId) {
console.error("No sticker pack ID provided");
process.exit(1);
}
const url = process.argv[3];
if (!url) {
console.error("No sticker pack URL provided");
process.exit(1);
}
request(url, (err, response) => {
if (err) {
console.error(err);
process.exit(2);
}
if (!response.body) {
console.error("No response body");
process.exit(3);
}
if (typeof(response.body) === "string") {
response.body = JSON.parse(response.body);
}
const migrationLines = [];
for (const pack of response.body) {
migrationLines.push(
'{ packId: ' + packId + ', name: "Sticker", description: "' + pack.filename + '", ' +
'imageMxc: "' + pack.mxc + '", thumbnailMxc: "' + pack.thumbnail + '", mimetype: "' + pack.mimetype + '", ' +
'thumbnailWidth: ' + pack.thumbnail_width + ', thumbnailHeight: ' + pack.thumbnail_height + ' },'
);
}
console.log(migrationLines.join("\n"));
});