Skip to content

Commit

Permalink
fix: allow Zenodo readme to be set from the Zenodo entry (#109)
Browse files Browse the repository at this point in the history
Also enable publish to test this part
  • Loading branch information
targos authored Apr 19, 2018
1 parent 19fc2f6 commit a428ba9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ end of the entry's description.
##### zenodoReadme

Type: string
Contents of the `_README.md` that is published in the Zenodo entry.
This option is mandatory if `zenodo` is `true`.
Default contents of the `_README.md` that is published in the Zenodo entry.

##### zenodoAttachments

Expand Down
9 changes: 2 additions & 7 deletions src/roc-zenodo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class RocZenodo {
const {
name,
visualizationUrl,
readme,
attachments,
sandbox = true,
token
Expand All @@ -30,16 +29,12 @@ class RocZenodo {
) {
throw new TypeError('visualizationUrl must be a string');
}
if (typeof readme !== 'string' || readme === '') {
throw new TypeError('readme must be a non-empty string');
}
if (attachments !== undefined && typeof attachments !== 'function') {
throw new TypeError('attachments must be a function');
}

this.name = name;
this.visualizationUrl = visualizationUrl;
this.readme = readme;
this.attachments = attachments;
this.isSandbox = sandbox;
this.zenodo = new Zenodo({ host, token });
Expand All @@ -59,11 +54,11 @@ class RocZenodo {
</p>`;
}

getIndexMd() {
getIndexMd(readme) {
return {
filename: '_README.md',
contentType: 'text/markdown',
data: this.readme
data: readme
};
}

Expand Down
16 changes: 11 additions & 5 deletions src/server/middleware/zenodo.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ let rocZenodo = new RocZenodo({
token: config.zenodoToken,
name: config.zenodoName,
visualizationUrl: config.zenodoVisualizationUrl,
readme: config.zenodoReadme,
attachments: config.zenodoAttachments
});

Expand All @@ -29,7 +28,7 @@ exports.createEntry = composeWithError(async (ctx) => {
userEmail,
'write'
);
const { $content: { meta, entries, doi } } = zenodoEntry;
const { $content: { meta, entries, doi, readme: entryReadme } } = zenodoEntry;
if (!entries || entries.length === 0) {
decorateError(ctx, 400, 'cannot publish on Zenodo without entries');
return;
Expand All @@ -38,6 +37,12 @@ exports.createEntry = composeWithError(async (ctx) => {
decorateError(ctx, 403, 'this entry has already been published');
return;
}
const readme = config.zenodoReadme || entryReadme;
if (!readme) {
decorateError(ctx, 400, 'readme is mandatory');
return;
}

let depositionMeta;
try {
depositionMeta = await rocZenodo.getZenodoDeposition(meta);
Expand Down Expand Up @@ -82,6 +87,7 @@ exports.createEntry = composeWithError(async (ctx) => {
deposition,
zenodoEntry,
entryValues,
readme,
couch,
userEmail
).catch((e) => {
Expand All @@ -99,6 +105,7 @@ async function uploadAttachments(
deposition,
zenodoEntry,
entries,
readme,
couch,
userEmail
) {
Expand Down Expand Up @@ -169,7 +176,7 @@ async function uploadAttachments(
contentType: 'application/octet-stream',
data: JSON.stringify(toc, null, 2)
});
await rocZenodo.uploadFile(deposition, rocZenodo.getIndexMd(deposition));
await rocZenodo.uploadFile(deposition, rocZenodo.getIndexMd(readme));
} catch (e) {
await rocZenodo.deleteEntry(deposition);
zenodoEntry.$content.doi = '';
Expand All @@ -181,8 +188,7 @@ async function uploadAttachments(
throw e;
}

// todo enable publish after testing
// await rocZenodo.publish(deposition);
await rocZenodo.publish(deposition);

zenodoEntry.$content.status.unshift({
epoch: Date.now(),
Expand Down

0 comments on commit a428ba9

Please sign in to comment.