新增:用户名修改接口

This commit is contained in:
ivan 2026-03-20 17:05:30 +08:00
parent 0c2127c087
commit afdc5edcca
2 changed files with 46 additions and 1 deletions

View File

@ -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>
}

View File

@ -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,
})
}