新增:用户名修改接口
This commit is contained in:
parent
0c2127c087
commit
afdc5edcca
@ -107,3 +107,28 @@ export async function post<T = unknown>(
|
|||||||
}
|
}
|
||||||
return res.json() as Promise<T>
|
return res.json() as Promise<T>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 带 x-token 等自定义头的 PUT 请求
|
||||||
|
*/
|
||||||
|
export async function put<T = unknown>(
|
||||||
|
path: string,
|
||||||
|
body?: unknown,
|
||||||
|
config?: RequestConfig,
|
||||||
|
): Promise<T> {
|
||||||
|
const url = new URL(path, BASE_URL || window.location.origin)
|
||||||
|
const headers: Record<string, string> = {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept-Language': i18n.global.locale.value as string,
|
||||||
|
...config?.headers,
|
||||||
|
}
|
||||||
|
const res = await fetch(url.toString(), {
|
||||||
|
method: 'PUT',
|
||||||
|
headers,
|
||||||
|
body: body !== undefined ? JSON.stringify(body) : undefined,
|
||||||
|
})
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error(`HTTP ${res.status}: ${res.statusText}`)
|
||||||
|
}
|
||||||
|
return res.json() as Promise<T>
|
||||||
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import { get } from './request'
|
import { get, put } from './request'
|
||||||
|
import type { ApiResponse } from './types'
|
||||||
|
|
||||||
const USDC_DECIMALS = 1_000_000
|
const USDC_DECIMALS = 1_000_000
|
||||||
|
|
||||||
@ -123,3 +124,22 @@ export async function getUsdcBalance(
|
|||||||
})
|
})
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PUT /user/setSelfUsername
|
||||||
|
* 修改自身用户名
|
||||||
|
* Body: { username: string }
|
||||||
|
* 需鉴权(ApiKeyAuth)
|
||||||
|
*/
|
||||||
|
export interface ChangeSelfUsernameReq {
|
||||||
|
username: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function setSelfUsername(
|
||||||
|
authHeaders: Record<string, string>,
|
||||||
|
req: ChangeSelfUsernameReq,
|
||||||
|
): Promise<ApiResponse> {
|
||||||
|
return put<ApiResponse>('/user/setSelfUsername', req, {
|
||||||
|
headers: authHeaders,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user