/*
* Copyright (C) 2018, 2019 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see .
*/
import {Logger} from '@openstapps/logger';
import {Command} from 'commander';
import {version} from '../package.json';
import {copy} from './copy.js';
import {SCThingType, STAPPS_CORE_VERSION} from '@openstapps/core';
import {Client, ConnectorClient, HttpClient} from '@openstapps/api';
new Command()
.command('run ')
.argument('', 'The URL of the StApps deployment', 'http://localhost:3000')
.argument(
'',
'The URL of the backend to copy the data from',
'https://mobile.server.uni-frankfurt.de',
)
.argument('', 'The type (RegExp full match)', '.*')
.argument('', 'Batch Size', 100)
.version(version)
.action(async (backendUrl: string, foreignBackendUrl: string, types: string, batchSize: number) => {
const client = new HttpClient();
const apiIn = new Client(client, foreignBackendUrl, STAPPS_CORE_VERSION);
const apiOut = new ConnectorClient(client, backendUrl);
const indexResponse = await apiIn.handshake(STAPPS_CORE_VERSION);
const origin = new URL(foreignBackendUrl).host.replaceAll(/[^a-zA-Z0-9-]/g, '-');
const licensePlate = indexResponse.backend.namespace;
const source = `${licensePlate}-${origin}`;
for (const type of Object.values(SCThingType)) {
if (!new RegExp(`^${types}$`).test(type)) continue;
await copy(apiIn, apiOut, source, type, batchSize);
}
Logger.ok('Done');
})
.addHelpCommand()
.parse(process.argv);