From d81c06f926b327457f30adfc6b5d4b207f0d12d4 Mon Sep 17 00:00:00 2001 From: Ananth Venkatesh <46249765+quantum9Innovation@users.noreply.github.com> Date: Thu, 15 Feb 2024 22:02:20 +0000 Subject: [PATCH] Add Zenodo upload script --- scripts/.gitignore | 2 ++ scripts/run.sh | 1 + scripts/zenodo.ts | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 scripts/.gitignore create mode 100644 scripts/run.sh create mode 100644 scripts/zenodo.ts diff --git a/scripts/.gitignore b/scripts/.gitignore new file mode 100644 index 0000000..8fcbb93 --- /dev/null +++ b/scripts/.gitignore @@ -0,0 +1,2 @@ +*.js +secret.txt diff --git a/scripts/run.sh b/scripts/run.sh new file mode 100644 index 0000000..f2bf5c2 --- /dev/null +++ b/scripts/run.sh @@ -0,0 +1 @@ +npx tsc zenodo.ts && node zenodo.js $1 $2 diff --git a/scripts/zenodo.ts b/scripts/zenodo.ts new file mode 100644 index 0000000..277aedd --- /dev/null +++ b/scripts/zenodo.ts @@ -0,0 +1,34 @@ +import { execSync } from 'child_process' + +const TOKEN = process.env.ZENODO +const filename = process.argv[2] +const path = process.argv[3] + +const run = (cmd: string): string | Buffer => { + try { + const output = execSync(cmd, { stdio: 'pipe' }) + return output + } catch (error) { + console.error(`Error executing shell script: ${error}`) + throw error + } +} + +const out = + run(`curl --request POST 'https://zenodo.org/api/deposit/depositions?access_token=${TOKEN}' \ +--header 'Content-Type: application/json' \ +--data-raw '{}' +`) +const json = JSON.parse(out.toString()) +const doi = json.metadata.prereserve_doi.doi +const file = json.links.bucket + +console.log('DOI: ' + doi) +console.log('File: ' + file) + +const res = run( + `curl --upload-file ${path} --request PUT '${file}/${filename}?access_token=${TOKEN}'` +) +const resJSON = JSON.parse(res.toString()) + +console.log(resJSON)