diff --git a/api/package.json b/api/package.json index 542d8ede2..cb82d5831 100644 --- a/api/package.json +++ b/api/package.json @@ -1,6 +1,6 @@ { "name": "@devtable/api", - "version": "14.12.0", + "version": "14.13.0", "description": "", "main": "index.js", "scripts": { diff --git a/api/src/locales/en.json b/api/src/locales/en.json index 6834a7e22..eb99a61a6 100644 --- a/api/src/locales/en.json +++ b/api/src/locales/en.json @@ -14,6 +14,8 @@ "ACCOUNT_NOT_FOUND": "Account not found", "ACCOUNT_NO_DELETE_SUPERADMIN": "Can not delete superadmin account", "DATASOURCE_HTTP_REQUIRED_FIELDS": "Pre processing and post processing are both required for HTTP datasource", + "DATASOURCE_HTTP_MISSING_HOST": "Host info is required but missing in this HTTP datasource", + "DATASOURCE_MMS_MISSING_HOST": "Host info is required but missing in this Merico Metric System datasource", "DATASOURCE_DB_REQUIRED_FIELDS": "Mysql|Postgresql config must contain [port, username, password, database]", "DATASOURCE_RENAME_SAME_KEY": "New key is the same as the old one", "DATASOURCE_NO_DELETE_PRESET": "Can not delete preset datasources", diff --git a/api/src/locales/zh.json b/api/src/locales/zh.json index c666671c5..a2a7a265e 100644 --- a/api/src/locales/zh.json +++ b/api/src/locales/zh.json @@ -14,6 +14,8 @@ "ACCOUNT_NOT_FOUND": "账户不存在", "ACCOUNT_NO_DELETE_SUPERADMIN": "无法删除超级管理员", "DATASOURCE_HTTP_REQUIRED_FIELDS": "HTTP数据源需要预处理和后处理", + "DATASOURCE_HTTP_MISSING_HOST": "请求的HTTP数据源未配置Host信息", + "DATASOURCE_MMS_MISSING_HOST": "请求的指标系统数据源未配置Host信息", "DATASOURCE_DB_REQUIRED_FIELDS": "Mysql|Postgresql配置必须包含[port,username,password,database]", "DATASOURCE_RENAME_SAME_KEY": "新key与旧key相同", "DATASOURCE_NO_DELETE_PRESET": "无法删除预设数据源", diff --git a/api/src/services/query.service.ts b/api/src/services/query.service.ts index 4849c745a..003b5c5c0 100644 --- a/api/src/services/query.service.ts +++ b/api/src/services/query.service.ts @@ -177,7 +177,7 @@ export class QueryService { locale: string, auth?: Account | ApiKey, ): Promise { - const result = await this.mericoMetricQuery(key, query); + const result = await this.mericoMetricQuery(key, query, locale); return result; } async queryStructure( @@ -281,11 +281,11 @@ export class QueryService { break; case 'http': - result = await this.httpQuery(parsedKey, q); + result = await this.httpQuery(parsedKey, q, locale); break; case 'merico_metric_system': - result = await this.mericoMetricQuery(parsedKey, q); + result = await this.mericoMetricQuery(parsedKey, q, locale); break; default: @@ -424,23 +424,23 @@ export class QueryService { return source.query(sql); } - private async httpQuery(key: string, query: string): Promise { + private async httpQuery(key: string, query: string, locale: string): Promise { const options = validateClass(HttpParams, JSON.parse(query)); const sourceConfig = await DataSourceService.getByTypeKey('http', key); - let { host } = sourceConfig.config; + const { host } = sourceConfig.config; if (!host) { - host = options.host; + throw new ApiError(BAD_REQUEST, { message: translate('DATASOURCE_HTTP_MISSING_HOST', locale) }); } return APIClient.request(host)(options); } - private async mericoMetricQuery(key: string, query: string): Promise { + private async mericoMetricQuery(key: string, query: string, locale: string): Promise { // const options = validateClass(HttpParams, JSON.parse(query)); const options = JSON.parse(query); const sourceConfig = await DataSourceService.getByTypeKey('merico_metric_system', key); - let { host } = sourceConfig.config; + const { host } = sourceConfig.config; if (!host) { - host = options.host; + throw new ApiError(BAD_REQUEST, { message: translate('DATASOURCE_MMS_MISSING_HOST', locale) }); } return APIClient.request(host)(options, (err) => _.get(err, 'response.data.detail.message', err.message)); } diff --git a/api/src/utils/api_client.ts b/api/src/utils/api_client.ts index 2c5276037..53ca85d32 100644 --- a/api/src/utils/api_client.ts +++ b/api/src/utils/api_client.ts @@ -1,11 +1,12 @@ import axios, { AxiosError, AxiosRequestConfig } from 'axios'; import { HttpParams } from '../api_models/query'; import log, { LOG_LABELS, LOG_LEVELS } from './logger'; +import _ from 'lodash'; export const APIClient = { request(host: string) { return (options: HttpParams, errorMessageGetter?: (err: AxiosError) => string) => { - const { method, url, headers, params, data, ...restOptions } = options; + const { method, url, headers, params, data, ...restOptions } = _.omit(options, 'host'); const conf: AxiosRequestConfig = { baseURL: host, diff --git a/api/src/utils/i18n.ts b/api/src/utils/i18n.ts index ef97a55b4..339403fd4 100644 --- a/api/src/utils/i18n.ts +++ b/api/src/utils/i18n.ts @@ -26,6 +26,8 @@ type ACCOUNT_KEYS = type DATASOURCE_KEYS = | 'DATASOURCE_HTTP_REQUIRED_FIELDS' + | 'DATASOURCE_HTTP_MISSING_HOST' + | 'DATASOURCE_MMS_MISSING_HOST' | 'DATASOURCE_DB_REQUIRED_FIELDS' | 'DATASOURCE_RENAME_SAME_KEY' | 'DATASOURCE_NO_DELETE_PRESET' diff --git a/dashboard/package.json b/dashboard/package.json index a8b5e29d4..09a988fd7 100644 --- a/dashboard/package.json +++ b/dashboard/package.json @@ -1,6 +1,6 @@ { "name": "@devtable/dashboard", - "version": "14.12.0", + "version": "14.13.0", "license": "Apache-2.0", "publishConfig": { "access": "public", diff --git a/package.json b/package.json index 850bc481d..67e7aa914 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@devtable/root", - "version": "14.12.0", + "version": "14.13.0", "private": true, "workspaces": [ "api", diff --git a/settings-form/package.json b/settings-form/package.json index 0a8f6087d..8acc5fe6d 100644 --- a/settings-form/package.json +++ b/settings-form/package.json @@ -1,6 +1,6 @@ { "name": "@devtable/settings-form", - "version": "14.12.0", + "version": "14.13.0", "license": "Apache-2.0", "publishConfig": { "access": "public", diff --git a/settings-form/src/datasource/add-data-source/forms/http.tsx b/settings-form/src/datasource/add-data-source/forms/http.tsx index 32ee5b840..d8bbb8b83 100644 --- a/settings-form/src/datasource/add-data-source/forms/http.tsx +++ b/settings-form/src/datasource/add-data-source/forms/http.tsx @@ -71,7 +71,8 @@ export function AddDataSourceForm_HTTP({ submit, styles = defaultStyles }: IAddD diff --git a/settings-form/src/datasource/edit-data-source/forms/http.tsx b/settings-form/src/datasource/edit-data-source/forms/http.tsx index e5f2caa24..33491c4ab 100644 --- a/settings-form/src/datasource/edit-data-source/forms/http.tsx +++ b/settings-form/src/datasource/edit-data-source/forms/http.tsx @@ -51,7 +51,8 @@ export function EditDataSourceForm_HTTP({ name, config, submit, styles = default diff --git a/settings-form/src/i18n/en.ts b/settings-form/src/i18n/en.ts index 451d94546..a81e774c2 100644 --- a/settings-form/src/i18n/en.ts +++ b/settings-form/src/i18n/en.ts @@ -23,7 +23,7 @@ export const en = { cant_delete_preset: 'This is a preset datasource, it can not be deleted', }, http: { - base_url: 'Base URL', + host: 'Host', processing: { pre: { label: 'Pre processing of queries', diff --git a/settings-form/src/i18n/zh.ts b/settings-form/src/i18n/zh.ts index 750c34660..b91cace02 100644 --- a/settings-form/src/i18n/zh.ts +++ b/settings-form/src/i18n/zh.ts @@ -23,7 +23,7 @@ export const zh = { cant_delete_preset: '这是预设数据源,不可删除', }, http: { - base_url: '访问地址', + host: 'Host', processing: { pre: { label: '查询请求预处理', diff --git a/website/package.json b/website/package.json index 607142e37..e6f7e5af2 100644 --- a/website/package.json +++ b/website/package.json @@ -2,7 +2,7 @@ "name": "@devtable/website", "private": true, "license": "Apache-2.0", - "version": "14.12.0", + "version": "14.13.0", "scripts": { "dev": "vite", "preview": "vite preview"