This commit is contained in:
@@ -4,6 +4,11 @@
|
||||
*/
|
||||
|
||||
import { BaseService } from '../BaseService'
|
||||
import {
|
||||
assertAssetActionAllowed,
|
||||
markAssetActionCalled,
|
||||
type AssetRateLimitedAction
|
||||
} from '@/utils/business/apiRateLimit'
|
||||
import type {
|
||||
BaseResponse,
|
||||
AssetResolveResponse,
|
||||
@@ -27,6 +32,17 @@ import type {
|
||||
UpdateAssetPackageExpiresAtRequest
|
||||
} from '@/types/api'
|
||||
|
||||
const runRateLimitedAssetAction = async <T>(
|
||||
action: AssetRateLimitedAction,
|
||||
identifier: string,
|
||||
request: () => Promise<T>
|
||||
): Promise<T> => {
|
||||
assertAssetActionAllowed(action, identifier)
|
||||
markAssetActionCalled(action, identifier)
|
||||
const response = await request()
|
||||
return response
|
||||
}
|
||||
|
||||
export class AssetService extends BaseService {
|
||||
/**
|
||||
* 通过任意标识符查询设备或卡的完整详情
|
||||
@@ -58,14 +74,16 @@ export class AssetService extends BaseService {
|
||||
/**
|
||||
* 主动调网关拉取最新数据后返回
|
||||
* POST /api/admin/assets/:identifier/refresh
|
||||
* 注意:设备有 30 秒冷却期,冷却中调用返回 429
|
||||
* 前端按资产标识限制 5 分钟内只能调用一次
|
||||
* @param identifier 资产标识符(ICCID 或 VirtualNo)
|
||||
*/
|
||||
static refreshAsset(identifier: string): Promise<BaseResponse<AssetRefreshResponse>> {
|
||||
return this.post<BaseResponse<AssetRefreshResponse>>(
|
||||
`/api/admin/assets/${identifier}/refresh`,
|
||||
{},
|
||||
{ timeout: 60000 }
|
||||
return runRateLimitedAssetAction('refresh', identifier, () =>
|
||||
this.post<BaseResponse<AssetRefreshResponse>>(
|
||||
`/api/admin/assets/${identifier}/refresh`,
|
||||
{},
|
||||
{ timeout: 60000 }
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -156,11 +174,13 @@ export class AssetService extends BaseService {
|
||||
/**
|
||||
* 复机资产(卡或设备)
|
||||
* POST /api/admin/assets/:identifier/start
|
||||
* 复机成功后设置 1 小时复机保护期(保护期内禁止停机)
|
||||
* 前端按资产标识限制 5 分钟内只能调用一次
|
||||
* @param identifier 资产标识符(ICCID 或 VirtualNo)
|
||||
*/
|
||||
static startAsset(identifier: string): Promise<BaseResponse<void>> {
|
||||
return this.post<BaseResponse<void>>(`/api/admin/assets/${identifier}/start`, {})
|
||||
return runRateLimitedAssetAction('start', identifier, () =>
|
||||
this.post<BaseResponse<void>>(`/api/admin/assets/${identifier}/start`, {})
|
||||
)
|
||||
}
|
||||
|
||||
// ========== 资产停用 ==========
|
||||
|
||||
Reference in New Issue
Block a user