From d4d1a9a990e02a8ecb46766bb6a57ce41c90a4e8 Mon Sep 17 00:00:00 2001
From: Xiao Gui <xgui3783@gmail.com>
Date: Mon, 9 Sep 2019 17:45:16 +0200
Subject: [PATCH] feat: downloadzip ships with license and readme

---
 deploy/datasets/index.js |  8 +++++---
 deploy/datasets/query.js | 17 ++++++++++-------
 2 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/deploy/datasets/index.js b/deploy/datasets/index.js
index c5bb0a0d1..d600e2706 100644
--- a/deploy/datasets/index.js
+++ b/deploy/datasets/index.js
@@ -11,9 +11,11 @@ const bodyParser = require('body-parser')
 datasetsRouter.use(bodyParser.urlencoded({ extended: false }))
 datasetsRouter.use(bodyParser.json())
 
-init().catch(e => {
-  console.warn(`dataset init failed`, e)
-})
+init()
+  .then(() => console.log(`dataset init success`))
+  .catch(e => {
+    console.warn(`dataset init failed`, e)
+  })
 
 const cacheMaxAge24Hr = (_req, res, next) => {
   const oneDay = 24 * 60 * 60
diff --git a/deploy/datasets/query.js b/deploy/datasets/query.js
index d243a34c8..2eb9231d6 100644
--- a/deploy/datasets/query.js
+++ b/deploy/datasets/query.js
@@ -240,16 +240,15 @@ const getDatasetFromId = async ({ user, kgId, returnAsStream = false }) => {
 
 const renderPublication = ({ name, cite, doi }) => `${name}
   ${cite}
-  https://doi.org/${doi}
+  DOI: ${doi}
 `
 
-const prepareDatasetMetadata = ({ name, kgReference, contributors, publications }) => {
+const prepareDatasetMetadata = ({ name, description, kgReference, contributors, publications }) => {
 
   return `${name}
 
-Contributors: ${contributors.join(', ')}
+${description}
 
-Publications:
 ${publications.map(renderPublication).join('\n')}
 `
 }
@@ -263,6 +262,10 @@ fs.readFile(path.join(__dirname, 'kgtos.md') , 'utf-8', (err, data) => {
 
 const getTos = () => kgtos
 
+const getLicense = ({ licenseInfo }) => licenseInfo.map(({ name, url }) => `${name}
+<${url}>
+`).join('\n')
+
 const getDatasetFileAsZip = async ({ user, kgId } = {}) => {
   if (!kgId) {
     throw new Error('kgId must be defined')
@@ -276,15 +279,15 @@ const getDatasetFileAsZip = async ({ user, kgId } = {}) => {
    * append citation information
    */
   zip.append(prepareDatasetMetadata(dataset), {
-    name: `${datasetName}.txt`
+    name: `README.txt`
   })
 
   /**
    * append kg citation policy
    */
 
-  zip.append(getTos(), {
-    name: `Terms Of Use.md`
+  zip.append(getLicense(dataset), {
+    name: `LICENSE.md`
   })
 
   /**
-- 
GitLab