#210: create documents with file importer

This commit is contained in:
Benjamin Gamard 2018-03-26 17:00:14 +02:00
parent 7aa4a1bf82
commit dc8b8ae6c4

View File

@ -229,21 +229,36 @@ const importFile = (file, remove, resolve) => {
}).start();
request.put({
url: prefs.importer.baseUrl + '/api/file',
formData: {
file: fs.createReadStream(file)
url: prefs.importer.baseUrl + '/api/document',
form: {
title: file.replace(/^.*[\\\/]/, ''),
language: 'eng'
}
}, function (error, response) {
}, function (error, response, body) {
if (error || !response || response.statusCode !== 200) {
spinner.fail('Upload failed for ' + file + ': ' + error);
resolve();
return;
}
spinner.succeed('Upload successful for ' + file);
if (remove) {
fs.unlinkSync(file);
}
resolve();
request.put({
url: prefs.importer.baseUrl + '/api/file',
formData: {
id: JSON.parse(body).id,
file: fs.createReadStream(file)
}
}, function (error, response) {
if (error || !response || response.statusCode !== 200) {
spinner.fail('Upload failed for ' + file + ': ' + error);
resolve();
return;
}
spinner.succeed('Upload successful for ' + file);
if (remove) {
fs.unlinkSync(file);
}
resolve();
});
});
};