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") rsp.ErrRsp(c, -1, "update already in progress")
return return
} }
defer releaseUpdateLock()
if err := update(); err != nil { if err := update(); err != nil {
releaseUpdateLock()
rsp.ErrRsp(c, -1, fmt.Sprintf("update failed: %s", err)) rsp.ErrRsp(c, -1, fmt.Sprintf("update failed: %s", err))
return return
} }

View File

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

View File

@@ -67,18 +67,20 @@ export const Offline = ({ status, setStatus, setIsLocked, setErrMsg }: UpdatePro
api api
.offlineUpdate(formData, checksum) .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}`); if (!rsp.ok) throw new Error(`HTTP error ${rsp.status}`);
return rsp.json();
}) const rspj = await rsp.json();
.then((rspj: any) => {
if (rspj.code !== 0) { if (rspj.code !== 0) {
const message = rspj.msg?.includes('sha256 checksum mismatch') const message = rspj.msg?.includes('sha256 checksum mismatch')
? t('settings.update.offline.checksumMismatch') ? t('settings.update.offline.checksumMismatch')
: rspj.msg || t('settings.update.offline.updateFailed'); : rspj.msg || t('settings.update.offline.updateFailed');
throw new Error(message); throw new Error(message);
} }
})
.then(() => {
setTimeout(() => { setTimeout(() => {
setIsLocked(false); setIsLocked(false);
window.location.reload(); window.location.reload();