API版本化:迁移账号设置与资料入口

This commit is contained in:
Christ committed 2026-08-14 16:53:20 +08:00
1 parent 415a3adc5f
commit eb8a54698c
8 files changed
+202 -14

No files matched your search

+34 -2
View File
@@ -29,7 +29,7 @@ import {
deleteReplyRule,
updateAccountCookie,
updateAccountLoginInfo,
updateAccountSettings,
updateAccountSettings, updateAccountRemark, updateAccountAutoConfirm, updateAccountPauseDuration, getLongLoginSettings, setLongLoginSettings, refreshAccountProfile,
updateItem,
updateNotificationChannel,
updateSystemSettings,
@@ -345,7 +345,7 @@ test('account editor settings use one aggregate request', async () => {
username: 'user', show_browser: true, channel_ids: [1, 2],
});
expect(fetchMock).toHaveBeenCalledTimes(1);
expect(fetchMock).toHaveBeenCalledWith('/cookies/acc1/settings', expect.objectContaining({ method: 'PUT' }));
expect(fetchMock).toHaveBeenCalledWith('/api/v1/accounts/acc1/settings', expect.objectContaining({ method: 'PUT' }));
expect(JSON.parse(fetchMock.mock.calls[0][1].body)).toEqual({
remark: 'main', auto_confirm: false, pause_duration: 5,
username: 'user', show_browser: true, channel_ids: [1, 2],
@@ -783,3 +783,35 @@ const runVersionedAccountAPITest = async () => {
};
test('account summary and status APIs use versioned compatibility routes', runVersionedAccountAPITest);
// 账号设置、长登录和资料 API 使用版本化兼容入口。
const runVersionedAccountSettingsAPITest = async () => {
// fetchMock 是账号设置与资料请求的测试替身。
const fetchMock = vi.fn()
.mockResolvedValueOnce(jsonResponse({ success: true, paused_until: 0, paused: false }))
.mockResolvedValueOnce(jsonResponse({ can_open_long_login: true, enabled: false }))
.mockResolvedValueOnce(jsonResponse({ can_open_long_login: true, enabled: true }))
.mockResolvedValueOnce(jsonResponse({ success: true, id: 'acc1', nickname: '主账号', avatar_url: '', profile_error: '' }))
.mockResolvedValueOnce(jsonResponse({ success: true }))
.mockResolvedValueOnce(jsonResponse({ success: true }))
.mockResolvedValueOnce(jsonResponse({ success: true, paused_until: 0, paused: false }));
vi.stubGlobal('fetch', fetchMock);
await updateAccountSettings('acc1', { remark: '主账号' });
await getLongLoginSettings('acc1');
await setLongLoginSettings('acc1', true);
await refreshAccountProfile('acc1');
await updateAccountRemark('acc1', '新的备注');
await updateAccountAutoConfirm('acc1', true);
await updateAccountPauseDuration('acc1', 15);
expect(fetchMock).toHaveBeenNthCalledWith(1, '/api/v1/accounts/acc1/settings', expect.objectContaining({ method: 'PUT' }));
expect(fetchMock).toHaveBeenNthCalledWith(2, '/api/v1/accounts/acc1/long-login', expect.objectContaining({ method: 'GET' }));
expect(fetchMock).toHaveBeenNthCalledWith(3, '/api/v1/accounts/acc1/long-login', expect.objectContaining({ method: 'PUT' }));
expect(fetchMock).toHaveBeenNthCalledWith(4, '/api/v1/accounts/acc1/refresh-profile', expect.objectContaining({ method: 'POST' }));
expect(fetchMock).toHaveBeenNthCalledWith(5, '/api/v1/accounts/acc1/remark', expect.objectContaining({ method: 'PUT' }));
expect(fetchMock).toHaveBeenNthCalledWith(6, '/api/v1/accounts/acc1/auto-confirm', expect.objectContaining({ method: 'PUT' }));
expect(fetchMock).toHaveBeenNthCalledWith(7, '/api/v1/accounts/acc1/pause-duration', expect.objectContaining({ method: 'PUT' }));
};
test('account settings and profile APIs use versioned compatibility routes', runVersionedAccountSettingsAPITest);
+7 -7
View File
@@ -195,15 +195,15 @@ export const deleteAccount = async (id: string): Promise<OperationResponse> => {
};
export const updateAccountRemark = async (id: string, remark: string): Promise<OperationResponse> => {
return put(`/cookies/${id}/remark`, { remark });
return put(`/api/v1/accounts/${id}/remark`, { remark });
};
export const updateAccountAutoConfirm = async (id: string, autoConfirm: boolean): Promise<OperationResponse> => {
return put(`/cookies/${id}/auto-confirm`, { auto_confirm: autoConfirm });
return put(`/api/v1/accounts/${id}/auto-confirm`, { auto_confirm: autoConfirm });
};
export const updateAccountPauseDuration = async (id: string, pauseDuration: number): Promise<CookieSettingsResponse> => {
return put(`/cookies/${id}/pause-duration`, { pause_duration: pauseDuration });
return put(`/api/v1/accounts/${id}/pause-duration`, { pause_duration: pauseDuration });
};
export const updateAccountCookie = async (id: string, value: string, loginMethod?: string): Promise<OperationResponse> => {
@@ -223,7 +223,7 @@ export interface AccountSettingsUpdate {
}
export const updateAccountSettings = async (id: string, data: AccountSettingsUpdate): Promise<CookieSettingsResponse> => {
return put(`/cookies/${id}/settings`, data);
return put(`/api/v1/accounts/${id}/settings`, data);
};
export interface LongLoginSettings {
@@ -232,11 +232,11 @@ export interface LongLoginSettings {
}
export const getLongLoginSettings = async (id: string): Promise<LongLoginSettings> => {
return get(`/cookies/${id}/long-login`);
return get(`/api/v1/accounts/${id}/long-login`);
};
export const setLongLoginSettings = async (id: string, enabled: boolean): Promise<LongLoginSettings> => {
return put(`/cookies/${id}/long-login`, { enabled });
return put(`/api/v1/accounts/${id}/long-login`, { enabled });
};
export interface PasswordLoginStartResponse {
@@ -277,7 +277,7 @@ export const cancelPasswordLogin = async (sessionId: string): Promise<ApiRespons
};
export const refreshAccountProfile = async (id: string): Promise<CookieProfileResponse> => {
return post(`/cookies/${id}/refresh-profile`, {});
return post(`/api/v1/accounts/${id}/refresh-profile`, {});
};
export const updateAccountLoginInfo = async (id: string, data: {