Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
Questdb
提交
0e7ba429
Q
Questdb
项目概览
jobily
/
Questdb
11 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Q
Questdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
0e7ba429
编写于
2月 10, 2021
作者:
M
Méril
提交者:
GitHub
2月 10, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(console): poll refreshRoute when AUTH_PAYLOAD is present in localStorage (#801)
上级
a292c070
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
90 addition
and
7 deletion
+90
-7
ui/package-lock.json
ui/package-lock.json
+1
-1
ui/src/store/Console/actions.ts
ui/src/store/Console/actions.ts
+5
-1
ui/src/store/Console/epics.ts
ui/src/store/Console/epics.ts
+72
-2
ui/src/store/Console/types.ts
ui/src/store/Console/types.ts
+6
-0
ui/src/telemetry/index.ts
ui/src/telemetry/index.ts
+1
-1
ui/src/utils/fromFetch.ts
ui/src/utils/fromFetch.ts
+5
-2
未找到文件。
ui/package-lock.json
浏览文件 @
0e7ba429
...
...
@@ -2954,7 +2954,7 @@
"buffer-from": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
"integrity": "sha
1-MnE7wCj3XAL9txDXx7zsHyxgcO8
=",
"integrity": "sha
512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A=
=",
"dev": true
},
"buffer-indexof": {
...
...
ui/src/store/Console/actions.ts
浏览文件 @
0e7ba429
...
...
@@ -4,6 +4,10 @@ const bootstrap = (): ConsoleAction => ({
type
:
ConsoleAT
.
BOOTSTRAP
,
})
const
refreshAuthToken
=
():
ConsoleAction
=>
({
type
:
ConsoleAT
.
REFRESH_AUTH_TOKEN
,
})
const
setConfiguration
=
(
payload
:
ConfigurationShape
):
ConsoleAction
=>
({
payload
,
type
:
ConsoleAT
.
SET_CONFIGURATION
,
...
...
@@ -13,4 +17,4 @@ const toggleSideMenu = (): ConsoleAction => ({
type
:
ConsoleAT
.
TOGGLE_SIDE_MENU
,
})
export
default
{
bootstrap
,
setConfiguration
,
toggleSideMenu
}
export
default
{
bootstrap
,
refreshAuthToken
,
setConfiguration
,
toggleSideMenu
}
ui/src/store/Console/epics.ts
浏览文件 @
0e7ba429
import
{
Epic
,
ofType
}
from
"
redux-observable
"
import
{
filter
,
map
,
switchMap
}
from
"
rxjs/operators
"
import
{
filter
,
map
,
switchMap
,
tap
}
from
"
rxjs/operators
"
import
{
NEVER
,
of
,
timer
}
from
"
rxjs
"
import
{
actions
}
from
"
store
"
import
{
...
...
@@ -7,11 +8,19 @@ import {
ConfigurationShape
,
ConsoleAction
,
ConsoleAT
,
RefreshAuthTokenAction
,
StoreAction
,
StoreShape
,
}
from
"
types
"
import
{
fromFetch
}
from
"
utils
"
type
AuthPayload
=
Readonly
<
Partial
<
{
expiry
:
number
refreshRoute
:
string
}
>
>
export
const
getConfiguration
:
Epic
<
StoreAction
,
ConsoleAction
,
StoreShape
>
=
(
action$
,
)
=>
...
...
@@ -29,4 +38,65 @@ export const getConfiguration: Epic<StoreAction, ConsoleAction, StoreShape> = (
),
)
export
default
[
getConfiguration
]
export
const
triggerRefreshTokenOnBootstrap
:
Epic
<
StoreAction
,
ConsoleAction
,
StoreShape
>
=
(
action$
)
=>
action$
.
pipe
(
ofType
<
StoreAction
,
BootstrapAction
>
(
ConsoleAT
.
BOOTSTRAP
),
switchMap
(()
=>
{
const
authPayload
=
localStorage
.
getItem
(
"
AUTH_PAYLOAD
"
)
if
(
authPayload
!=
null
)
{
return
of
(
actions
.
console
.
refreshAuthToken
())
}
return
NEVER
}),
)
export
const
refreshToken
:
Epic
<
StoreAction
,
ConsoleAction
,
StoreShape
>
=
(
action$
,
)
=>
action$
.
pipe
(
ofType
<
StoreAction
,
RefreshAuthTokenAction
>
(
ConsoleAT
.
REFRESH_AUTH_TOKEN
),
switchMap
(()
=>
{
const
authPayload
=
localStorage
.
getItem
(
"
AUTH_PAYLOAD
"
)
if
(
authPayload
!=
null
)
{
try
{
const
{
expiry
,
refreshRoute
}
=
JSON
.
parse
(
authPayload
,
)
as
AuthPayload
if
(
expiry
!=
null
&&
refreshRoute
!=
null
)
{
const
waitUntil
=
expiry
*
1
e3
-
30
e3
-
Date
.
now
()
if
(
waitUntil
<
0
)
{
return
NEVER
}
return
timer
(
waitUntil
).
pipe
(
switchMap
(()
=>
fromFetch
<
AuthPayload
>
(
refreshRoute
)),
tap
((
response
)
=>
{
if
(
!
response
.
error
)
{
localStorage
.
setItem
(
"
AUTH_PAYLOAD
"
,
JSON
.
stringify
(
response
.
data
),
)
}
}),
switchMap
(()
=>
of
(
actions
.
console
.
refreshAuthToken
())),
)
}
}
catch
(
error
)
{
return
NEVER
}
}
return
NEVER
}),
)
export
default
[
getConfiguration
,
triggerRefreshTokenOnBootstrap
,
refreshToken
]
ui/src/store/Console/types.ts
浏览文件 @
0e7ba429
...
...
@@ -16,6 +16,7 @@ export type ConsoleStateShape = Readonly<{
export
enum
ConsoleAT
{
BOOTSTRAP
=
"
CONSOLE/BOOTSTRAP
"
,
REFRESH_AUTH_TOKEN
=
"
CONSOLE/REFRESH_AUTH_TOKEN
"
,
SET_CONFIGURATION
=
"
CONSOLE/SET_CONFIGURATION
"
,
TOGGLE_SIDE_MENU
=
"
CONSOLE/TOGGLE_SIDE_MENU
"
,
}
...
...
@@ -24,6 +25,10 @@ export type BootstrapAction = Readonly<{
type
:
ConsoleAT
.
BOOTSTRAP
}
>
export
type
RefreshAuthTokenAction
=
Readonly
<
{
type
:
ConsoleAT
.
REFRESH_AUTH_TOKEN
}
>
type
SetConfigurationAction
=
Readonly
<
{
payload
:
ConfigurationShape
type
:
ConsoleAT
.
SET_CONFIGURATION
...
...
@@ -35,5 +40,6 @@ type ToggleSideMenuAction = Readonly<{
export
type
ConsoleAction
=
|
BootstrapAction
|
RefreshAuthTokenAction
|
SetConfigurationAction
|
ToggleSideMenuAction
ui/src/telemetry/index.ts
浏览文件 @
0e7ba429
...
...
@@ -11,7 +11,7 @@ const quest = new QuestDB.Client()
const
start
=
async
()
=>
{
const
yearOffset
=
24
*
60
*
60
*
1000
*
31
*
12
const
result
=
await
quest
.
query
<
ConfigShape
>
(
Table
.
CONFIG
)
const
result
=
await
quest
.
query
<
ConfigShape
>
(
`
${
Table
.
CONFIG
}
limit -1`
)
let
lastUpdated
:
string
|
undefined
// If the user enabled telemetry then we start the webworker
...
...
ui/src/utils/fromFetch.ts
浏览文件 @
0e7ba429
...
...
@@ -15,8 +15,10 @@ type SuccessShape<T> = Readonly<{
export
const
fromFetch
=
<
T
extends
Record
<
string
,
any
>>
(
uri
:
string
,
init
:
RequestInit
=
{},
):
Observable
<
SuccessShape
<
T
>
|
ErrorShape
>
=>
rxFromFetch
(
`http://
${
window
.
location
.
host
}
/
${
uri
}
`
,
init
).
pipe
(
):
Observable
<
SuccessShape
<
T
>
|
ErrorShape
>
=>
{
const
separator
=
uri
[
0
]
===
"
/
"
?
""
:
"
/
"
return
rxFromFetch
(
`
${
window
.
location
.
origin
}${
separator
}${
uri
}
`
,
init
).
pipe
(
switchMap
((
response
)
=>
{
if
(
response
.
ok
)
{
return
response
.
json
()
...
...
@@ -41,3 +43,4 @@ export const fromFetch = <T extends Record<string, any>>(
return
response
as
ErrorShape
}),
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录