From cbd7e67161d34fede0b8169206aef2e2e1ff5d14 Mon Sep 17 00:00:00 2001 From: rozetko Date: Fri, 30 Dec 2022 14:57:54 +0300 Subject: [PATCH] it works --- src/routes/tasks.ts | 10 ++++------ src/services/exporter.ts | 19 ++++++++++--------- src/types/index.ts | 7 ++++--- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/routes/tasks.ts b/src/routes/tasks.ts index 37ba9ca..2061a6e 100644 --- a/src/routes/tasks.ts +++ b/src/routes/tasks.ts @@ -35,20 +35,18 @@ async function getTasks(req, res) { let data = fs.readFileSync(path.join(EXPORTED_PATH, item), 'utf8'); let status = JSON.parse(data); - let requestedUrl = `http://${req.headers.host}`; - let downloadLink = ''; - let deleteLink = ''; + let filename = ''; if(status.status === 'finished') { - downloadLink = ``; + filename = file.name; } resp.push({ timestamp: status.time, - user: status.user, + username: status.user, datasourceRef: status.datasourceRef, rowsCount: status.exportedRows, progress: status.progress, status: status.status, - downloadLink, + filename, }); } diff --git a/src/services/exporter.ts b/src/services/exporter.ts index 8c94182..4f5ba90 100644 --- a/src/services/exporter.ts +++ b/src/services/exporter.ts @@ -21,7 +21,7 @@ const TIMESTAMP_COLUMN = 'timestamp'; export class Exporter { private exportedRows = 0; private createdTimestamp: number; - private user: string; + private username: string; private datasourceRef: DataSourceRef; private initCsvStream() { @@ -44,9 +44,9 @@ export class Exporter { let time = moment().valueOf(); let data = { time, - user: this.user, + username: this.username, exportedRows: this.exportedRows, - progress: progress.toLocaleString('en', { style: 'percent' }), + progress: progress, status, datasourceRef: this.datasourceRef, }; @@ -58,11 +58,11 @@ export class Exporter { } } - public async export(data: Target[], datasourceUrl: string, user: string, from: number, to: number) { - this.user = user; + public async export(data: Target[], datasourceUrl: string, username: string, from: number, to: number) { + this.username = username; this.validateTargets(datasourceUrl, data); - + // console.log('ds', data[0].datasource) const targets = data.map(target => { console.log({ @@ -72,17 +72,18 @@ export class Exporter { return { ...target, metric: new QueryConfig( - QueryType.GRAFANA, + QueryType.GRAFANA, { ...target.datasource, url: datasourceUrl - }, + }, target.panel.targets ) } }); - this.datasourceRef = data.length === 1 ? data[0].datasource : { uid: 'all', type: 'all' }; + const datasource = data[0].datasource; + this.datasourceRef = data.length === 1 ? { uid: datasource.uid, type: datasource.type } : { uid: 'all', type: 'all' }; await this.updateStatus(ExportStatus.EXPORTING, 0); diff --git a/src/types/index.ts b/src/types/index.ts index df63d77..ca9a1b5 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -80,7 +80,8 @@ export interface PanelModel { alert?: any; } -export type Task = DataQuery & { +// TODO: rename to query +export type Task = Omit & { selected: boolean; panel: PanelModel; datasource: DataSourceSettings; @@ -88,10 +89,10 @@ export type Task = DataQuery & { export type TaskTableRowConfig = { timestamp: number; - user: string; + username: string; datasourceRef: DataSourceRef; rowsCount: number; progress: number; status: string; - downloadLink: string; + filename?: string; };