@curvenote/cli
Version:
CLI Client library for Curvenote
25 lines (24 loc) • 1.07 kB
JavaScript
import { oxaLinkToId } from '@curvenote/blocks';
import { Block } from '../../../models.js';
import { getBlockAndLatestVersion } from './getBlockAndLatestVersion.js';
export const remoteExportWrapper = (exportRemoteArticle) => async (session, path, filename, opts) => {
const id = oxaLinkToId(path);
if (!id) {
throw new Error(`Unknown article: ${path}`);
}
else if ('version' in id.block) {
// Ensure that we actually get a correct ID, and then use the version supplied
const block = await new Block(session, id.block).get();
await exportRemoteArticle(session, { ...block.id, version: id.block.version }, { filename, ...opts });
}
else {
// Here we will load up the latest version
const { version } = await getBlockAndLatestVersion(session, id.block);
if (!version) {
session.log.error('Could not download article; do you need to save the draft?');
}
else {
await exportRemoteArticle(session, version.id, { filename, ...opts });
}
}
};