The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/app/importer/server/methods/prepareImport.js

35 lines
1.0 KiB

import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import { Importers } from '..';
import { hasPermission } from '../../../authorization';
Meteor.methods({
prepareImport(key, dataURI, contentType, fileName) {
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'prepareImport' });
}
if (!hasPermission(Meteor.userId(), 'run-import')) {
throw new Meteor.Error('error-action-not-allowed', 'Importing is not allowed', { method: 'setupImporter' });
}
check(key, String);
check(dataURI, String);
check(fileName, String);
const importer = Importers.get(key);
if (!importer) {
throw new Meteor.Error('error-importer-not-defined', `The importer (${ key }) has no import class defined.`, { method: 'prepareImport' });
}
const results = importer.instance.prepare(dataURI, contentType, fileName);
if (results instanceof Promise) {
return results.catch((e) => { throw new Meteor.Error(e); });
}
return results;
},
});