Skip to content
This repository was archived by the owner on Apr 21, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ARG BUILD_DATE

# Metadata http://label-schema.org/rc1/
LABEL org.label-schema.vendor="o2r project" \
org.label-schema.url="http://o2r.info" \
org.label-schema.url="https://o2r.info" \
org.label-schema.name="o2r loader" \
org.label-schema.description="compendium and workspace loading from uploaded files and cloud resources" \
org.label-schema.version=$VERSION \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Build Status](https://travis-ci.org/o2r-project/o2r-loader.svg?branch=master)](https://travis-ci.org/o2r-project/o2r-loader) [![](https://images.microbadger.com/badges/version/o2rproject/o2r-loader.svg)](https://microbadger.com/images/o2rproject/o2r-loader "Get your own version badge on microbadger.com") [![](https://images.microbadger.com/badges/image/o2rproject/o2r-loader.svg)](https://microbadger.com/images/o2rproject/o2r-loader "Get your own image badge on microbadger.com")

Node.js implementation to load compendia from third party repositories and handle direct user uploads for the [o2r web api](http://o2r.info/o2r-web-api).
Node.js implementation to load compendia from third party repositories and handle direct user uploads for the [o2r API](https://o2r.info/api).

Currently, it implements the endpoint `/api/v1/compendium`.

Expand Down
55 changes: 33 additions & 22 deletions lib/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ function checkAndLoadZip(passon) {
if (passon.result.zipCount >= 1 && passon.result.bagitCount === 0) {
if (passon.result.zipCount === 1) {
debug('[%s] Single zip file found: %s', passon.id);
} else if (passon.zipFile){
} else if (passon.zipFile) {
debug('[%s] Multiple zip files found: %s. Filename %s was provided.', passon.id, passon.zipFile);
} else {
debug('[%s] Multiple zip files found but no filename provided, aborting.', passon.id);
Expand Down Expand Up @@ -595,7 +595,7 @@ function fetchCompendiumID(passon) {
reject(error);
}

if (!compendiumID){
if (!compendiumID) {
debug('[%s] No ID specified for compendium', passon.id);
let message = 'No id found in compendium detection file';
let error = new Error(message);
Expand All @@ -617,6 +617,7 @@ function fetchCompendiumID(passon) {
}
if (compendium === null) {
debug('[%s] Assigned ID %s from configuration file to compendium', passon.id, compendiumID);
passon.uploadId = passon.id;
passon.id = compendiumID;
fulfill(passon);
} else {
Expand Down Expand Up @@ -647,28 +648,38 @@ function fetchCompendiumID(passon) {
function moveCompendiumFiles(passon) {
return new Promise((fulfill, reject) => {

if (passon.isCompendium){
if (passon.isCompendium) {
let updatedPath = path.join(config.fs.compendium, passon.id);
debug('[%s] Copying compendium files from %s to %s due to ID specified in compendium file', passon.id, passon.compendium_path, updatedPath);

let cmd = 'mv ' + passon.compendium_path + ' ' + updatedPath;
exec(cmd, (error, stdout, stderr) => {
if (error || stderr) {
debug('Error copying compendium files: %O', {error, stderr, stdout});
debug(error, stderr, stdout);
let errors = error.message.split(':');
let message = errorMessageHelper(errors[errors.length - 1]);
error.msg = 'moving compendium files to new location failed: ' + message;
error.status = 500;
reject(error);
} else {
debug('[%s] Moving compendium files finished: %s', passon.id, stdout);
passon.compendium_path = updatedPath;
passon.configurationFile = path.join(passon.compendium_path, config.bagit.detectionFileName);
fulfill(passon);
fs.access(updatedPath, (err) => {
if (!err) {
updatedPath_backup = updatedPath.replace(passon.id, passon.id + '_' + passon.uploadId);
debug('[%s] Directory %s already exists, backing up files to %s', passon.id, updatedPath, updatedPath_backup);

// not catching errors on next function to escalate if something goes wrong
fs.renameSync(updatedPath, updatedPath_backup);
}
});

let cmd = 'mv ' + passon.compendium_path + ' ' + updatedPath;
debug('[%s] Executing %s', passon.id, cmd);
exec(cmd, (error, stdout, stderr) => {
if (error || stderr) {
debug('Error copying compendium files: %O', { error, stderr, stdout });
debug(error, stderr, stdout);
let errors = error.message.split(':');
let message = errorMessageHelper(errors[errors.length - 1]);
error.msg = 'moving compendium files to new location failed: ' + message;
error.status = 500;
reject(error);
} else {
debug('[%s] Moving compendium files finished: %s', passon.id, stdout);
passon.compendium_path = updatedPath;
passon.configurationFile = path.join(passon.compendium_path, config.bagit.detectionFileName);
fulfill(passon);
}
});
});
} else {
debug('[%s] Not a compendium, files do not need to be moved', passon.id, );
fulfill(passon);
Expand Down Expand Up @@ -763,7 +774,7 @@ function extractMetadata(passon) {
metaextract_input_dir + ':' + metaextract_input_dir,
metaextract_output_dir + ':' + metaextract_output_dir
];
if(config.fs.volume) {
if (config.fs.volume) {
debug('[%s] volume is configured, overwriting binds configuration (was %o)', passon.id, binds);
// passon.compendium_path always starts with config.fs.base
binds = [
Expand Down Expand Up @@ -1007,8 +1018,8 @@ module.exports = {
detectCompendium: detectCompendium,
getTextFiles: getTextFiles,
checkEncoding: checkEncoding,
fetchCompendiumID : fetchCompendiumID,
moveCompendiumFiles : moveCompendiumFiles,
fetchCompendiumID: fetchCompendiumID,
moveCompendiumFiles: moveCompendiumFiles,
extractMetadata: extractMetadata,
loadMetadata: loadMetadata,
brokerMetadata: brokerMetadata,
Expand Down
Loading