mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
listing of files on connect
This commit is contained in:
@ -34,6 +34,14 @@ const (
|
||||
CHAT_EMOTE = "chat/emote"
|
||||
)
|
||||
|
||||
const (
|
||||
FILETRANSFER_ENABLE = "filetransfer/enable"
|
||||
FILETRANSFER_DISABLE = "filetransfer/disable"
|
||||
FILETRANSFER_UNPRIVENABLE = "filetransfer/unprivenable"
|
||||
FILETRANSFER_UNPRIVDISABLE = "filetransfer/unprivdisable"
|
||||
FILETRANSFER_LIST = "filetransfer/list"
|
||||
)
|
||||
|
||||
const (
|
||||
SCREEN_CONFIGURATIONS = "screen/configurations"
|
||||
SCREEN_RESOLUTION = "screen/resolution"
|
||||
|
@ -106,6 +106,17 @@ type EmoteSend struct {
|
||||
Emote string `json:"emote"`
|
||||
}
|
||||
|
||||
type FileTransferTarget struct {
|
||||
Event string `json:"event"`
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
type FileList struct {
|
||||
Event string `json:"event"`
|
||||
Cwd string `json:"cwd"`
|
||||
Files []types.FileListItem `json:"files"`
|
||||
}
|
||||
|
||||
type Admin struct {
|
||||
Event string `json:"event"`
|
||||
ID string `json:"id"`
|
||||
|
@ -37,3 +37,8 @@ type WebSocketHandler interface {
|
||||
CanTransferFiles(password string) (bool, error)
|
||||
MakeFilePath(filename string) string
|
||||
}
|
||||
|
||||
type FileListItem struct {
|
||||
Filename string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
30
server/internal/utils/files.go
Normal file
30
server/internal/utils/files.go
Normal file
@ -0,0 +1,30 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"m1k1o/neko/internal/types"
|
||||
)
|
||||
|
||||
func ListFiles(path string) (*[]types.FileListItem, error) {
|
||||
items, err := os.ReadDir(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out := make([]types.FileListItem, len(items))
|
||||
for i, item := range items {
|
||||
var itemType string = ""
|
||||
if item.IsDir() {
|
||||
itemType = "dir"
|
||||
} else {
|
||||
itemType = "file"
|
||||
}
|
||||
out[i] = types.FileListItem{
|
||||
Filename: item.Name(),
|
||||
Type: itemType,
|
||||
}
|
||||
}
|
||||
|
||||
return &out, nil
|
||||
}
|
@ -133,6 +133,21 @@ func (ws *WebSocketHandler) Start() {
|
||||
}
|
||||
}
|
||||
|
||||
// send file list if necessary
|
||||
if session.Admin() && ws.conf.FileTransfer || ws.conf.FileTransfer && ws.conf.UnprivFileTransfer {
|
||||
files, err := utils.ListFiles(ws.conf.FileTransferPath)
|
||||
if err == nil {
|
||||
if err := session.Send(
|
||||
message.FileList{
|
||||
Event: event.FILETRANSFER_LIST,
|
||||
Cwd: ws.conf.FileTransferPath,
|
||||
Files: *files,
|
||||
}); err != nil {
|
||||
ws.logger.Warn().Err(err).Msg("file list event has failed")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// remove outdated stats
|
||||
if session.Admin() {
|
||||
ws.lastAdminLeftAt = nil
|
||||
|
Reference in New Issue
Block a user