mirror of
https://github.com/sismics/docs.git
synced 2024-11-22 05:57:57 +01:00
#210: create documents with file importer
This commit is contained in:
parent
7aa4a1bf82
commit
dc8b8ae6c4
@ -229,21 +229,36 @@ const importFile = (file, remove, resolve) => {
|
|||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
request.put({
|
request.put({
|
||||||
url: prefs.importer.baseUrl + '/api/file',
|
url: prefs.importer.baseUrl + '/api/document',
|
||||||
formData: {
|
form: {
|
||||||
file: fs.createReadStream(file)
|
title: file.replace(/^.*[\\\/]/, ''),
|
||||||
|
language: 'eng'
|
||||||
}
|
}
|
||||||
}, function (error, response) {
|
}, function (error, response, body) {
|
||||||
if (error || !response || response.statusCode !== 200) {
|
if (error || !response || response.statusCode !== 200) {
|
||||||
spinner.fail('Upload failed for ' + file + ': ' + error);
|
spinner.fail('Upload failed for ' + file + ': ' + error);
|
||||||
resolve();
|
resolve();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
spinner.succeed('Upload successful for ' + file);
|
|
||||||
if (remove) {
|
request.put({
|
||||||
fs.unlinkSync(file);
|
url: prefs.importer.baseUrl + '/api/file',
|
||||||
}
|
formData: {
|
||||||
resolve();
|
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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user