Browse Source

Support multiple panels export at once (#32)

pull/1/head
Dmitry Nalobin 4 years ago committed by GitHub
parent
commit
f07480c7a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 44
      src/routes/tasks.ts

44
src/routes/tasks.ts

@ -1,26 +1,42 @@
import { Target } from '../target' import { Target } from '../target'
import * as express from 'express' import * as express from 'express'
import { Datasource } from '@corpglory/tsdb-kit';
type TRequest = {
body: {
from: string,
to: string,
data: Array<{
panelUrl: string,
datasourceRequest: Datasource,
datasourceName: string
}>,
target: object,
user: string,
}
};
async function addTask(req, res) { async function addTask(req: TRequest, res) {
let body = req.body; const body = req.body;
let from = parseInt(body.from); const from = parseInt(body.from);
let to = parseInt(body.to); const to = parseInt(body.to);
let panelUrl = body.panelUrl; const data = body.data;
let targets = [body.target]; const targets = [body.target];
let datasource = body.datasourceRequest; const user = body.user;
let datasourceName = body.datasourceName;
let user = body.user;
if(isNaN(from) || isNaN(to)) { if(isNaN(from) || isNaN(to)) {
res.status(500).send('Range error: please fill both "from" and "to" fields'); res.status(400).send('Range error: please fill both "from" and "to" fields');
} else if(from >= to) { } else if(from >= to) {
res.status(500).send('Range error: "from" should be less than "to"'); res.status(400).send('Range error: "from" should be less than "to"');
} else { } else {
res.status(200).send('Exporting ' + datasourceName + ' data from ' + new Date(from).toLocaleString() + ' to ' + new Date(to).toLocaleString()); const names = data.map(item => item.datasourceName).join(', ');
let target = new Target(panelUrl, user, datasource, targets, from, to, datasourceName); res.status(200).send(`Exporting ${names} data from ${new Date(from).toLocaleString()} to ${new Date(to).toLocaleString()}`);
target.export();
data.forEach(request => {
const target = new Target(request.panelUrl, user, request.datasourceRequest, targets, from, to, request.datasourceName);
target.export();
});
} }
} }

Loading…
Cancel
Save