:oaweb model

v3
veypi 4 weeks ago
parent 90a1f1d3a3
commit 58f5d57b77

@ -17,7 +17,7 @@ export interface ListQuery {
updated_at?: Date
}
export function List(json: ListOpts, query: ListQuery) {
return webapi.Get<[models.Access]>(`/access`, { json, query })
return webapi.Get<models.Access[]>(`/access`, { json, query })
}
export interface PostOpts {

@ -7,7 +7,7 @@
import webapi from "./webapi"
import * as models from "./models"
export function Get(app_id: string) {
return webapi.Get<models.App>(`/app/${app_id}`, { })
return webapi.Get<models.App>(`/app/${app_id}`, {})
}
export interface PatchOpts {
@ -22,7 +22,7 @@ export function Patch(app_id: string, json: PatchOpts) {
}
export function Delete(app_id: string) {
return webapi.Delete<models.App>(`/app/${app_id}`, { })
return webapi.Delete<models.App>(`/app/${app_id}`, {})
}
export interface PostOpts {
@ -39,7 +39,7 @@ export interface ListOpts {
name?: string
}
export function List(json: ListOpts) {
return webapi.Get<[models.App]>(`/app`, { json })
return webapi.Get<models.App[]>(`/app`, { json })
}
export interface AppUserGetOpts {
@ -57,7 +57,7 @@ export function AppUserPatch(app_user_id: string, app_id: string, json: AppUserP
}
export function AppUserDelete(app_user_id: string, app_id: string) {
return webapi.Delete<models.AppUser>(`/app/${app_id}/app_user/${app_user_id}`, { })
return webapi.Delete<models.AppUser>(`/app/${app_id}/app_user/${app_user_id}`, {})
}
export interface AppUserListOpts {
@ -65,7 +65,7 @@ export interface AppUserListOpts {
status?: string
}
export function AppUserList(app_id: string, json: AppUserListOpts) {
return webapi.Get<[models.AppUser]>(`/app/${app_id}/app_user`, { json })
return webapi.Get<models.AppUser[]>(`/app/${app_id}/app_user`, { json })
}
export interface AppUserPostOpts {
@ -81,7 +81,7 @@ export interface ResourceListQuery {
updated_at?: Date
}
export function ResourceList(app_id: string, query: ResourceListQuery) {
return webapi.Get<[models.Resource]>(`/app/${app_id}/resource`, { query })
return webapi.Get<models.Resource[]>(`/app/${app_id}/resource`, { query })
}
export interface ResourcePostOpts {
@ -100,10 +100,10 @@ export function ResourceDelete(app_id: string, json: ResourceDeleteOpts) {
}
export function ResourceGet(app_id: string) {
return webapi.Get<models.Resource>(`/app/${app_id}/resource`, { })
return webapi.Get<models.Resource>(`/app/${app_id}/resource`, {})
}
export function ResourcePatch(app_id: string) {
return webapi.Patch<models.Resource>(`/app/${app_id}/resource`, { })
return webapi.Patch<models.Resource>(`/app/${app_id}/resource`, {})
}

@ -7,7 +7,7 @@
import webapi from "./webapi"
import * as models from "./models"
export function Get(role_id: string) {
return webapi.Get<models.Role>(`/role/${role_id}`, { })
return webapi.Get<models.Role>(`/role/${role_id}`, {})
}
export interface PatchOpts {
@ -20,7 +20,7 @@ export function Patch(role_id: string, json: PatchOpts) {
}
export function Delete(role_id: string) {
return webapi.Delete<models.Role>(`/role/${role_id}`, { })
return webapi.Delete<models.Role>(`/role/${role_id}`, {})
}
export interface PostOpts {
@ -36,6 +36,6 @@ export interface ListOpts {
name?: string
}
export function List(json: ListOpts) {
return webapi.Get<[models.Role]>(`/role`, { json })
return webapi.Get<models.Role[]>(`/role`, { json })
}

@ -50,6 +50,6 @@ export interface ListOpts {
app_id: string
}
export function List(json: ListOpts) {
return webapi.Get<[models.Token]>(`/token`, { json })
return webapi.Get<models.Token[]>(`/token`, { json })
}

@ -7,7 +7,7 @@
import webapi from "./webapi"
import * as models from "./models"
export function Get(user_id: string) {
return webapi.Get<models.User>(`/user/${user_id}`, { })
return webapi.Get<models.User>(`/user/${user_id}`, {})
}
export interface PatchOpts {
@ -23,7 +23,7 @@ export function Patch(user_id: string, json: PatchOpts) {
}
export function Delete(user_id: string) {
return webapi.Delete<models.User>(`/user/${user_id}`, { })
return webapi.Delete<models.User>(`/user/${user_id}`, {})
}
export interface PostOpts {
@ -47,11 +47,11 @@ export interface ListOpts {
status?: number
}
export function List(json: ListOpts) {
return webapi.Get<[models.User]>(`/user`, { json })
return webapi.Get<models.User[]>(`/user`, { json })
}
export function UserRoleGet(user_role_id: string, user_id: string) {
return webapi.Get<models.UserRole>(`/user/${user_id}/user_role/${user_role_id}`, { })
return webapi.Get<models.UserRole>(`/user/${user_id}/user_role/${user_role_id}`, {})
}
export interface UserRolePatchOpts {
@ -82,6 +82,6 @@ export interface UserRoleListOpts {
status?: string
}
export function UserRoleList(user_id: string, json: UserRoleListOpts) {
return webapi.Get<[models.UserRole]>(`/user/${user_id}/user_role`, { json })
return webapi.Get<models.UserRole[]>(`/user/${user_id}/user_role`, { json })
}

@ -1,6 +1,6 @@
//
// Copyright (C) 2024 veypi <i@veypi.com>
// 2024-10-25 18:42:03
// 2024-10-28 17:43:57
// Distributed under terms of the MIT license.
//
@ -22,14 +22,45 @@ const proxy = axios.create({
},
});
export const token = {
value: '',
update: () => {
return new Promise<string>((resolve) => { resolve(token.value) })
},
set_updator: (fn: () => Promise<string>) => {
let locked = false
token.update = () => {
if (locked) {
return new Promise<void>((resolve) => {
setTimeout(() => {
resolve();
}, 1000)
}).then(() => {
return token.update()
})
}
locked = true
return new Promise<string>((resolve, reject) => {
if (token.value) {
locked = false
resolve(token.value)
return
}
fn().then((e) => {
token.value = e
resolve(e)
}).catch(() => {
reject()
}).finally(() => { locked = false })
})
}
}
}
// 请求拦截
const beforeRequest = (config: any) => {
// 设置 token
const token = util.getToken()
config.retryTimes = 3
// NOTE 添加自定义头部
token && (config.headers.Authorization = `Bearer ${token}`)
token.value && (config.headers.Authorization = `Bearer ${token.value}`)
// config.headers['auth_token'] = ''
return config
}
@ -64,12 +95,23 @@ const responseFailed = (error: AxiosError) => {
needRetry = false
} else if (response?.status == 401) {
needRetry = false
if (data.code === 40103) {
// AuthNotFound = New(40100, "auth not found")
// AuthExpired = New(40102, "auth expired")
if (data.code === 40102 || data.code === 40100) {
token.value = ''
return token.update().then(() => {
return requestRetry(1000, response!)
})
}
}
if (!needRetry) {
return Promise.reject(data || response)
};
return requestRetry(1000, response!)
}
const requestRetry = (delay = 0, response: AxiosResponse) => {
const config = response?.config
// @ts-ignore
const { __retryCount = 0, retryDelay = 1000, retryTimes } = config;
// 在请求对象上设置重试次数
@ -79,18 +121,20 @@ const responseFailed = (error: AxiosError) => {
if (__retryCount >= retryTimes) {
return Promise.reject(response?.data || response?.headers.error)
}
if (delay <= 0) {
return proxy.request(config as any)
}
// 延时处理
const delay = new Promise<void>((resolve) => {
return new Promise<void>((resolve) => {
setTimeout(() => {
resolve();
}, retryDelay);
});
// 重新发起请求
return delay.then(function() {
return proxy.request(config as any);
});
}, delay)
}).then(() => {
return proxy.request(config as any)
})
}
proxy.interceptors.response.use(responseSuccess, responseFailed)
interface data {

Loading…
Cancel
Save