zenodraft
Version:
CLI to manage depositions on Zenodo and Zenodo Sandbox
40 lines • 2.03 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.deposition_publish = void 0;
const node_fetch_1 = require("node-fetch");
const details_1 = require("../deposition/show/details");
const get_api_1 = require("../helpers/get-api");
const deposition_publish = (token, sandbox, version_id, verbose = false) => __awaiter(void 0, void 0, void 0, function* () {
const msg = `publishing draft deposition with id ${version_id}...`;
if (verbose) {
console.log(msg);
}
// result of this next function is not used, but there are some checks in it
yield details_1.deposition_show_details(token, sandbox, version_id, verbose);
const api = get_api_1.helpers_get_api(sandbox);
const endpoint = `/deposit/depositions/${version_id}/actions/publish`;
const method = 'POST';
const headers = {
'Authorization': `Bearer ${token}`
};
const init = { method, headers };
let response;
response = yield node_fetch_1.default(`${api}${endpoint}`, init);
if (response.ok !== true) {
throw new Error(`(errid 10) Something went wrong on ${method} to ${api}${endpoint}: ${response.status} - ${response.statusText}`);
}
if (verbose) {
console.log(`${msg}done`);
}
});
exports.deposition_publish = deposition_publish;
//# sourceMappingURL=publish.js.map