mirror of
https://github.com/sipeed/NanoKVM.git
synced 2026-09-11 00:22:56 -05:00
fix(ota): keep update lock through service restart
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
Reference in New Issue
Block a user