You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
planka_custom/server/api/helpers/boards/load-trello-file.js

37 lines
817 B
JavaScript

const fs = require('fs');
module.exports = {
inputs: {
file: {
type: 'json',
required: true,
},
},
async fn(inputs) {
const isValidTrelloFile = (content) =>
content &&
Array.isArray(content.lists) &&
Array.isArray(content.cards) &&
Array.isArray(content.checklists) &&
Array.isArray(content.actions);
return new Promise((resolve, reject) => {
fs.readFile(inputs.file.fd, (err, data) => {
try {
const exp = data && JSON.parse(data);
if (err) {
reject(err);
} else if (isValidTrelloFile(exp)) {
resolve(exp);
} else {
reject(new Error('Invalid Trello File'));
}
} catch (e) {
reject(new Error(e));
}
});
});
},
};