mirror of
https://github.com/sipeed/NanoKVM.git
synced 2026-09-11 00:22:56 -05:00
fix: fix api/storage/image/mounted error when using HID-Only mode (#833)
This commit is contained in:
@@ -33,7 +33,7 @@ var modeMap = map[string]string{
|
|||||||
func (s *Service) GetHidMode(c *gin.Context) {
|
func (s *Service) GetHidMode(c *gin.Context) {
|
||||||
var rsp proto.Response
|
var rsp proto.Response
|
||||||
|
|
||||||
mode, err := getHidMode()
|
mode, err := GetMode()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rsp.ErrRsp(c, -1, "get HID mode failed")
|
rsp.ErrRsp(c, -1, "get HID mode failed")
|
||||||
return
|
return
|
||||||
@@ -58,7 +58,7 @@ func (s *Service) SetHidMode(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if mode, _ := getHidMode(); req.Mode == mode {
|
if mode, _ := GetMode(); req.Mode == mode {
|
||||||
rsp.OkRsp(c)
|
rsp.OkRsp(c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -194,7 +194,7 @@ func copyModeFile(srcScript string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getHidMode() (string, error) {
|
func GetMode() (string, error) {
|
||||||
data, err := os.ReadFile(ModeFlag)
|
data, err := os.ReadFile(ModeFlag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("failed to read %s: %s", ModeFlag, err)
|
log.Errorf("failed to read %s: %s", ModeFlag, err)
|
||||||
|
|||||||
@@ -150,6 +150,19 @@ func (s *Service) MountImage(c *gin.Context) {
|
|||||||
func (s *Service) GetMountedImage(c *gin.Context) {
|
func (s *Service) GetMountedImage(c *gin.Context) {
|
||||||
var rsp proto.Response
|
var rsp proto.Response
|
||||||
|
|
||||||
|
mode, err := hid.GetMode()
|
||||||
|
if err != nil {
|
||||||
|
rsp.ErrRsp(c, -2, "get HID mode failed")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if mode == hid.ModeHidOnly {
|
||||||
|
rsp.OkRspWithData(c, &proto.GetMountedImageRsp{
|
||||||
|
File: "",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
content, err := os.ReadFile(mountDevice)
|
content, err := os.ReadFile(mountDevice)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rsp.ErrRsp(c, -2, "read failed")
|
rsp.ErrRsp(c, -2, "read failed")
|
||||||
|
|||||||
Reference in New Issue
Block a user