mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
fix locks.
This commit is contained in:
parent
75ad4cefe6
commit
4adf1d7182
@ -23,6 +23,9 @@ type session struct {
|
||||
client *http.Client
|
||||
|
||||
lastHostID string
|
||||
lockedControls bool
|
||||
lockedLogins bool
|
||||
lockedFileTransfer bool
|
||||
sessions map[string]*oldTypes.Member
|
||||
|
||||
connClient *websocket.Conn
|
||||
@ -60,11 +63,15 @@ func (s *session) apiReq(method, path string, request, response any) error {
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode != http.StatusOK {
|
||||
if res.StatusCode < 200 || res.StatusCode >= 300 {
|
||||
body, _ := io.ReadAll(res.Body)
|
||||
return fmt.Errorf("unexpected status code: %d, body: %s", res.StatusCode, body)
|
||||
}
|
||||
|
||||
if res.Body == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return json.NewDecoder(res.Body).Decode(response)
|
||||
}
|
||||
|
||||
|
@ -242,8 +242,22 @@ func (s *session) wsToBackend(msg []byte, sendMsg func([]byte) error) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO: No WS equivalent, call HTTP API.
|
||||
return fmt.Errorf("event not implemented: %s", header.Event)
|
||||
data := map[string]any{}
|
||||
|
||||
switch request.Resource {
|
||||
case "login":
|
||||
data["locked_logins"] = true
|
||||
case "control":
|
||||
data["locked_controls"] = true
|
||||
case "file_transfer":
|
||||
data["plugins"] = map[string]any{
|
||||
"filetransfer.enabled": false,
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("unknown resource: %s", request.Resource)
|
||||
}
|
||||
|
||||
return s.apiReq(http.MethodPost, "/api/room/settings", data, nil)
|
||||
|
||||
case oldEvent.ADMIN_UNLOCK:
|
||||
request := &oldMessage.AdminLock{}
|
||||
@ -252,8 +266,22 @@ func (s *session) wsToBackend(msg []byte, sendMsg func([]byte) error) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO: No WS equivalent, call HTTP API.
|
||||
return fmt.Errorf("event not implemented: %s", header.Event)
|
||||
data := map[string]any{}
|
||||
|
||||
switch request.Resource {
|
||||
case "login":
|
||||
data["locked_logins"] = false
|
||||
case "control":
|
||||
data["locked_controls"] = false
|
||||
case "file_transfer":
|
||||
data["plugins"] = map[string]any{
|
||||
"filetransfer.enabled": true,
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("unknown resource: %s", request.Resource)
|
||||
}
|
||||
|
||||
return s.apiReq(http.MethodPost, "/api/room/settings", data, nil)
|
||||
|
||||
case oldEvent.ADMIN_CONTROL:
|
||||
return s.apiReq(http.MethodPost, "/api/room/control/take", nil, nil)
|
||||
|
@ -196,12 +196,15 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
||||
locks := map[string]string{}
|
||||
if request.Settings.LockedLogins {
|
||||
locks["login"] = "" // TODO: We don't know who locked the login.
|
||||
s.lockedLogins = true
|
||||
}
|
||||
if request.Settings.LockedControls {
|
||||
locks["control"] = "" // TODO: We don't know who locked the control.
|
||||
s.lockedControls = true
|
||||
}
|
||||
if !filetransferSettings.Enabled {
|
||||
locks["filetransfer"] = "" // TODO: We don't know who locked the file transfer.
|
||||
locks["file_transfer"] = "" // TODO: We don't know who locked the file transfer.
|
||||
s.lockedFileTransfer = true
|
||||
}
|
||||
|
||||
return send(&oldMessage.SystemInit{
|
||||
@ -540,16 +543,90 @@ func (s *session) wsToClient(msg []byte, sendMsg func([]byte) error) error {
|
||||
IsActive: request.IsActive,
|
||||
})
|
||||
|
||||
/*
|
||||
// Admin Events
|
||||
case:
|
||||
send(&oldMessage.AdminLock{
|
||||
case event.SYSTEM_SETTINGS:
|
||||
request := &message.SystemSettingsUpdate{}
|
||||
err := json.Unmarshal(data.Payload, request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if s.lockedControls != request.LockedControls {
|
||||
s.lockedControls = request.LockedControls
|
||||
|
||||
if request.LockedControls {
|
||||
err = send(&oldMessage.AdminLock{
|
||||
Event: oldEvent.ADMIN_LOCK,
|
||||
Resource: "control",
|
||||
})
|
||||
case:
|
||||
send(&oldMessage.AdminLock{
|
||||
} else {
|
||||
err = send(&oldMessage.AdminLock{
|
||||
Event: oldEvent.ADMIN_UNLOCK,
|
||||
Resource: "control",
|
||||
})
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if s.lockedLogins != request.LockedLogins {
|
||||
s.lockedLogins = request.LockedLogins
|
||||
|
||||
if request.LockedLogins {
|
||||
err = send(&oldMessage.AdminLock{
|
||||
Event: oldEvent.ADMIN_LOCK,
|
||||
Resource: "login",
|
||||
})
|
||||
} else {
|
||||
err = send(&oldMessage.AdminLock{
|
||||
Event: oldEvent.ADMIN_UNLOCK,
|
||||
Resource: "login",
|
||||
})
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// FileTransfer
|
||||
//
|
||||
|
||||
filetransferSettings := filetransfer.Settings{
|
||||
Enabled: true, // defaults to true
|
||||
}
|
||||
|
||||
err = request.Settings.Plugins.Unmarshal(filetransfer.PluginName, &filetransferSettings)
|
||||
if err != nil && !errors.Is(err, types.ErrPluginSettingsNotFound) {
|
||||
return fmt.Errorf("unable to unmarshal %s plugin settings from global settings: %w", filetransfer.PluginName, err)
|
||||
}
|
||||
|
||||
if s.lockedFileTransfer != !filetransferSettings.Enabled {
|
||||
s.lockedFileTransfer = !filetransferSettings.Enabled
|
||||
|
||||
if !filetransferSettings.Enabled {
|
||||
err = send(&oldMessage.AdminLock{
|
||||
Event: oldEvent.ADMIN_LOCK,
|
||||
Resource: "file_transfer",
|
||||
})
|
||||
} else {
|
||||
err = send(&oldMessage.AdminLock{
|
||||
Event: oldEvent.ADMIN_UNLOCK,
|
||||
Resource: "file_transfer",
|
||||
})
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
/*
|
||||
case:
|
||||
send(&oldMessage.AdminTarget{
|
||||
Event: oldEvent.ADMIN_BAN,
|
||||
|
Loading…
Reference in New Issue
Block a user