Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@ module.exports = {
'import/no-extraneous-dependencies': 0,
'noUnusedLocals': 0,
'prefer-destructuring': ['error', { object: true, array: false }],
'no-continue': 1,
},
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
]
},
"dependencies": {
"@arco-design/web-vue": "^2.41.0",
"@arco-design/web-vue": "^2.56.2",
"@babel/core": "^7.20.5",
"@codemirror/autocomplete": "^6.4.2",
"@codemirror/lang-java": "^6.0.1",
Expand All @@ -45,6 +45,7 @@
"@codemirror/state": "^6.2.0",
"@codemirror/theme-one-dark": "^6.1.0",
"@codemirror/view": "^6.9.3",
"@codemirror/lang-json": "^6.0.1",
"@lezer/common": "^1.0.2",
"@lezer/highlight": "^1.1.2",
"@lezer/lr": "^1.2.3",
Expand Down Expand Up @@ -84,7 +85,8 @@
"vue-codemirror": "^6.1.1",
"vue-echarts": "^6.5.0",
"vue-i18n": "^9.2.2",
"vue-router": "^4.0.14"
"vue-router": "^4.0.14",
"js-file-download": "^0.4.12"
},
"devDependencies": {
"@babel/types": "^7.21.4",
Expand Down
74 changes: 42 additions & 32 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion src/api/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import axios, { AxiosRequestConfig, AxiosRequestHeaders } from 'axios'
import dayjs from 'dayjs'
import qs from 'qs'
import { PromForm } from '@/store/modules/code-run/types'
import { HttpResponse } from './interceptor'

const sqlUrl = `/v1/sql`
const scriptUrl = `/v1/scripts`
Expand Down Expand Up @@ -97,7 +98,7 @@ const getTableByName = (tableName: string) => {
)
}

const runSQL = (code: string) => {
const runSQL = (code: string): Promise<HttpResponse> => {
return axios.post(sqlUrl, makeSqlData(code), addDatabaseParams())
}

Expand Down Expand Up @@ -136,6 +137,11 @@ const writeInfluxDB = (data: string, precision: string) => {
} as AxiosRequestConfig
return axios.post(`${influxURL}/write`, data, config)
}
const runSQLWithCSV = (code: string): Promise<HttpResponse> => {
const params = addDatabaseParams()
params.params.format = 'csv'
return axios.post(sqlUrl, makeSqlData(code), params)
}

export default {
getTables,
Expand All @@ -149,4 +155,5 @@ export default {
writeInfluxDB,
checkScriptsTable,
fetchTablesCount,
runSQLWithCSV,
}
31 changes: 24 additions & 7 deletions src/api/interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ export interface Auth {
}

// todo: can we use env and proxy at the same time?
export const TableNameReg = /(?<=from|FROM)\s+([^\s;]+)/
export function parseTable(sql: string) {
const result = sql.match(TableNameReg)
if (result && result.length) {
const arr = result[1].trim().split('.')
return arr[arr.length - 1]
}
return ''
}

axios.interceptors.request.use(
(config: AxiosRequestConfig) => {
Expand Down Expand Up @@ -51,6 +60,7 @@ axios.interceptors.request.use(
return Promise.reject(error)
}
)
const ignoreList = ['pipelines']

axios.interceptors.response.use(
(response: AxiosResponse) => {
Expand All @@ -70,16 +80,22 @@ axios.interceptors.response.use(
return Promise.reject(errorResponse)
}
if (isV1) {
if (response.config.params && response.config.params.format === 'csv') {
return response.data
}
response.data = JSONbigint({ storeAsString: true }).parse(response.data)
const { data } = response
if (data.code && data.code !== 0) {
// v1 and error
Message.error({
content: data.error || 'Error',
duration: 5 * 1000,
closable: true,
resetOnHover: true,
})
const tableName = parseTable(decodeURIComponent(response.config.data))
if (ignoreList.indexOf(tableName) === -1) {
Message.error({
content: data.error || 'Error',
duration: 5 * 1000,
closable: true,
resetOnHover: true,
})
}
const error = {
error: data.error || 'Error',
startTime: new Date(response.config.traceTimeStart).toLocaleTimeString(),
Expand All @@ -104,7 +120,8 @@ axios.interceptors.response.use(
}
const data = JSON.parse(error.response.data)
const isInflux = !!error.config.url?.startsWith(`/v1/influxdb`)
if (!isInflux) {
const tableName = parseTable(decodeURIComponent(error.response.config.data))
if (!isInflux && ignoreList.indexOf(tableName) === -1) {
Message.error({
content: data.error || 'Request Error',
duration: 5 * 1000,
Expand Down
Loading
Loading