feat: 实现后台在线更新功能
- 前端添加更新和重启按钮,支持一键更新 Release 构建 - 修复条件判断优先级问题,确保错误/成功状态正确显示 - 后端使用原子文件替换模式,确保更新过程安全可靠 - 在可执行文件同目录创建临时文件,保证 rename 原子性 - 删除未使用的 copyFile 函数,保持代码整洁
This commit is contained in:
@@ -40,9 +40,42 @@ export async function checkUpdates(force = false): Promise<VersionInfo> {
|
||||
return data;
|
||||
}
|
||||
|
||||
export interface UpdateResult {
|
||||
message: string;
|
||||
need_restart: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform system update
|
||||
* Downloads and applies the latest version
|
||||
*/
|
||||
export async function performUpdate(): Promise<UpdateResult> {
|
||||
const { data } = await apiClient.post<UpdateResult>('/admin/system/update');
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rollback to previous version
|
||||
*/
|
||||
export async function rollback(): Promise<UpdateResult> {
|
||||
const { data } = await apiClient.post<UpdateResult>('/admin/system/rollback');
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restart the service
|
||||
*/
|
||||
export async function restartService(): Promise<{ message: string }> {
|
||||
const { data } = await apiClient.post<{ message: string }>('/admin/system/restart');
|
||||
return data;
|
||||
}
|
||||
|
||||
export const systemAPI = {
|
||||
getVersion,
|
||||
checkUpdates,
|
||||
performUpdate,
|
||||
rollback,
|
||||
restartService,
|
||||
};
|
||||
|
||||
export default systemAPI;
|
||||
|
||||
Reference in New Issue
Block a user