manual refresh function

This commit is contained in:
William Harrell 2022-11-03 21:54:05 -04:00
parent 70e84c5840
commit cfc7b15211
9 changed files with 74 additions and 4 deletions

View File

@ -134,7 +134,7 @@
} }
refresh() { refresh() {
console.log('refresh') this.$accessor.files.refresh()
} }
download(item: any) { download(item: any) {

View File

@ -187,6 +187,14 @@ export abstract class BaseClient extends EventEmitter<BaseEvents> {
this._ws!.send(JSON.stringify({ event, ...payload })) this._ws!.send(JSON.stringify({ event, ...payload }))
} }
public refreshFiles() {
if (!this.connected) {
this.emit('warn', 'attempting to refresh files while disconnected')
}
this.emit('debug', `sending event '${EVENT.FILETRANSFER.REFRESH}'`)
this._ws!.send(JSON.stringify({ event: EVENT.FILETRANSFER.REFRESH }))
}
public async createPeer(lite: boolean, servers: RTCIceServer[]) { public async createPeer(lite: boolean, servers: RTCIceServer[]) {
this.emit('debug', `creating peer`) this.emit('debug', `creating peer`)
if (!this.socketOpen) { if (!this.socketOpen) {

View File

@ -43,7 +43,8 @@ export const EVENT = {
DISABLE: 'filetransfer/disable', DISABLE: 'filetransfer/disable',
UNPRIVENABLE: 'filetransfer/unprivenable', UNPRIVENABLE: 'filetransfer/unprivenable',
UNPRIVDISABLE: 'filetransfer/unprivdisable', UNPRIVDISABLE: 'filetransfer/unprivdisable',
LIST: 'filetransfer/list' LIST: 'filetransfer/list',
REFRESH: 'filetransfer/refresh'
}, },
SCREEN: { SCREEN: {
CONFIGURATIONS: 'screen/configurations', CONFIGURATIONS: 'screen/configurations',
@ -106,6 +107,7 @@ export type FileTransferEvents =
| typeof EVENT.FILETRANSFER.UNPRIVENABLE | typeof EVENT.FILETRANSFER.UNPRIVENABLE
| typeof EVENT.FILETRANSFER.UNPRIVDISABLE | typeof EVENT.FILETRANSFER.UNPRIVDISABLE
| typeof EVENT.FILETRANSFER.LIST | typeof EVENT.FILETRANSFER.LIST
| typeof EVENT.FILETRANSFER.REFRESH
export type ScreenEvents = typeof EVENT.SCREEN.CONFIGURATIONS | typeof EVENT.SCREEN.RESOLUTION | typeof EVENT.SCREEN.SET export type ScreenEvents = typeof EVENT.SCREEN.CONFIGURATIONS | typeof EVENT.SCREEN.RESOLUTION | typeof EVENT.SCREEN.SET

View File

@ -30,6 +30,13 @@ export const actions = actionTree(
setFileList(store, files: FileListItem[]) { setFileList(store, files: FileListItem[]) {
accessor.files._setFileList(files) accessor.files._setFileList(files)
},
refresh(store) {
if (!accessor.connected) {
return
}
$client.refreshFiles()
} }
} }
) )

View File

@ -40,6 +40,7 @@ const (
FILETRANSFER_UNPRIVENABLE = "filetransfer/unprivenable" FILETRANSFER_UNPRIVENABLE = "filetransfer/unprivenable"
FILETRANSFER_UNPRIVDISABLE = "filetransfer/unprivdisable" FILETRANSFER_UNPRIVDISABLE = "filetransfer/unprivdisable"
FILETRANSFER_LIST = "filetransfer/list" FILETRANSFER_LIST = "filetransfer/list"
FILETRANSFER_REFRESH = "filetransfer/refresh"
) )
const ( const (

View File

@ -0,0 +1,26 @@
package handler
import (
"errors"
"m1k1o/neko/internal/types"
"m1k1o/neko/internal/types/event"
"m1k1o/neko/internal/types/message"
"m1k1o/neko/internal/utils"
)
func (h *MessageHandler) refresh(session types.Session) error {
if !(h.state.FileTransferEnabled() && session.Admin() || h.state.UnprivFileTransferEnabled()) {
return errors.New(session.Member().Name + " tried to refresh file list when they can't")
}
files, err := utils.ListFiles(h.state.FileTransferPath())
if err != nil {
return err
}
return session.Send(
message.FileList{
Event: event.FILETRANSFER_LIST,
Cwd: h.state.FileTransferPath(),
Files: *files,
})
}

View File

@ -126,6 +126,10 @@ func (h *MessageHandler) Message(id string, raw []byte) error {
return h.chatEmote(id, session, payload) return h.chatEmote(id, session, payload)
}), "%s failed", header.Event) }), "%s failed", header.Event)
// File Transfer Events
case event.FILETRANSFER_REFRESH:
return errors.Wrapf(h.refresh(session), "%s failed", header.Event)
// Screen Events // Screen Events
case event.SCREEN_RESOLUTION: case event.SCREEN_RESOLUTION:
return errors.Wrapf(h.screenResolution(id, session), "%s failed", header.Event) return errors.Wrapf(h.screenResolution(id, session), "%s failed", header.Event)

View File

@ -3,12 +3,20 @@ package state
type State struct { type State struct {
banned map[string]string // IP -> session ID (that banned it) banned map[string]string // IP -> session ID (that banned it)
locked map[string]string // resource name -> session ID (that locked it) locked map[string]string // resource name -> session ID (that locked it)
fileTransferEnabled bool // admins can transfer files
fileTransferUnprivEnabled bool // all users can transfer files
fileTransferPath string // path where files are located
} }
func New() *State { func New(fileTransferEnabled bool, fileTransferUnprivEnabled bool, fileTransferPath string) *State {
return &State{ return &State{
banned: make(map[string]string), banned: make(map[string]string),
locked: make(map[string]string), locked: make(map[string]string),
fileTransferEnabled: fileTransferEnabled,
fileTransferUnprivEnabled: fileTransferUnprivEnabled,
fileTransferPath: fileTransferPath,
} }
} }
@ -59,3 +67,17 @@ func (s *State) GetLocked(resource string) (string, bool) {
func (s *State) AllLocked() map[string]string { func (s *State) AllLocked() map[string]string {
return s.locked return s.locked
} }
// File Transfer
func (s *State) FileTransferEnabled() bool {
return s.fileTransferEnabled
}
func (s *State) UnprivFileTransferEnabled() bool {
return s.fileTransferUnprivEnabled
}
func (s *State) FileTransferPath() string {
return s.fileTransferPath
}

View File

@ -26,7 +26,7 @@ const CONTROL_PROTECTION_SESSION = "by_control_protection"
func New(sessions types.SessionManager, desktop types.DesktopManager, capture types.CaptureManager, webrtc types.WebRTCManager, conf *config.WebSocket) *WebSocketHandler { func New(sessions types.SessionManager, desktop types.DesktopManager, capture types.CaptureManager, webrtc types.WebRTCManager, conf *config.WebSocket) *WebSocketHandler {
logger := log.With().Str("module", "websocket").Logger() logger := log.With().Str("module", "websocket").Logger()
state := state.New() state := state.New(conf.FileTransfer, conf.UnprivFileTransfer, conf.FileTransferPath)
// if control protection is enabled // if control protection is enabled
if conf.ControlProtection { if conf.ControlProtection {