feat: 新版webui
This commit is contained in:
1 parent
1d0d25eea2
commit
ee1291e42c
201 files changed
+18454
-3422
No files matched your search
@@ -0,0 +1,45 @@
|
||||
import { AxiosResponse } from 'axios'
|
||||
|
||||
/**
|
||||
* 打开链接
|
||||
* @param url 链接地址
|
||||
* @param newTab 是否在新标签页打开
|
||||
*/
|
||||
export function openUrl(url: string, newTab = true) {
|
||||
if (newTab) {
|
||||
window.open(url)
|
||||
} else {
|
||||
window.location.href = url
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将Axios的响应转换为标准的HTTP报文
|
||||
* @param response Axios响应
|
||||
* @returns 标准的HTTP报文
|
||||
*/
|
||||
export function parseAxiosResponse(
|
||||
response: AxiosResponse,
|
||||
http_version: string = 'HTTP/1.1'
|
||||
) {
|
||||
if (!response?.status) {
|
||||
return 'No response'
|
||||
}
|
||||
const statusLine = `${http_version} ${response.status} ${response.statusText}`
|
||||
const headers = Object.entries(response.headers)
|
||||
.map(([key, value]) => `${key}: ${value}`)
|
||||
.join('\r\n')
|
||||
const body = response.data
|
||||
? `\r\n\r\n${typeof response.data === 'string' ? JSON.stringify(JSON.parse(response.data), null, 2) : JSON.stringify(response.data, null, 2)}`
|
||||
: ''
|
||||
return `${statusLine}\r\n${headers}${body}`
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为URI
|
||||
* @param uri URI
|
||||
* @returns 是否为URI
|
||||
*/
|
||||
export const isURI = (uri: string) => {
|
||||
return /^(http|https|file):\/\/.*/.test(uri)
|
||||
}
|
||||
Reference in new issue
Block a user