fix(ota): keep update lock through service restart

This commit is contained in:
watermeko
2026-08-05 01:41:07 +00:00
committed by Guoguo
parent 0f8ef20fb5
commit 9e50040713
3 changed files with 9 additions and 7 deletions

View File

@@ -29,9 +29,9 @@ func (s *Service) Update(c *gin.Context) {
rsp.ErrRsp(c, -1, "update already in progress")
return
}
defer releaseUpdateLock()
if err := update(); err != nil {
releaseUpdateLock()
rsp.ErrRsp(c, -1, fmt.Sprintf("update failed: %s", err))
return
}

View File

@@ -26,9 +26,9 @@ func (s *Service) OfflineUpdate(c *gin.Context) {
rsp.ErrRsp(c, -1, "update already in progress")
return
}
defer releaseUpdateLock()
if err := offlineUpdate(c); err != nil {
releaseUpdateLock()
rsp.ErrRsp(c, -1, fmt.Sprintf("update failed: %s", err))
return
}

View File

@@ -67,18 +67,20 @@ export const Offline = ({ status, setStatus, setIsLocked, setErrMsg }: UpdatePro
api
.offlineUpdate(formData, checksum)
.then((rsp: Response) => {
.then(async (rsp: Response) => {
// The proxy may return 502 after the update stops the old server.
if (rsp.status === 502) return;
if (!rsp.ok) throw new Error(`HTTP error ${rsp.status}`);
return rsp.json();
})
.then((rspj: any) => {
const rspj = await rsp.json();
if (rspj.code !== 0) {
const message = rspj.msg?.includes('sha256 checksum mismatch')
? t('settings.update.offline.checksumMismatch')
: rspj.msg || t('settings.update.offline.updateFailed');
throw new Error(message);
}
})
.then(() => {
setTimeout(() => {
setIsLocked(false);
window.location.reload();