MCPcopy Create free account
hub / github.com/MertJSX/folderhost / processWebSocketMessage

Function processWebSocketMessage

middleware/websocket/file_editor.go:19–107  ·  view source on GitHub ↗
(msg []byte, filePath string, c *websocket.Conn, mt int)

Source from the content-addressed store, hash-verified

17)
18
19func processWebSocketMessage(msg []byte, filePath string, c *websocket.Conn, mt int) error {
20 var message types.EditorChange
21 var account types.Account = c.Locals("account").(types.Account)
22
23 if err := json.Unmarshal(msg, &message); err != nil {
24 return err
25 }
26
27 switch message.Type {
28 case "editor-change":
29 if !account.Permissions.Change {
30 permissionError, _ := json.Marshal(fiber.Map{
31 "type": "error",
32 "error": "You don't have permission to change!",
33 })
34
35 c.WriteMessage(mt, permissionError)
36 return nil // Server doesn't care about permission errors
37 }
38
39 utils.ScheduleDebouncedLog(account.Username, filePath)
40
41 utils.SendToAllExclude(filePath, mt, msg, c)
42 return applyEditorChange(filePath, message.Change, &account)
43 case "change-path":
44 if !account.Permissions.ReadDirectories {
45 permissionError, _ := json.Marshal(fiber.Map{
46 "type": "error",
47 "error": "You don't have permission to read-directories!",
48 })
49
50 c.WriteMessage(mt, permissionError)
51 return nil
52 }
53
54 path := config.Config.GetScopedFolder(account.Scope) + "/" + message.Path
55
56 if !utils.IsSafePath(path) {
57 c.Close()
58 return fmt.Errorf("path traversal security issue")
59 }
60
61 fileStat, err := os.Stat(path)
62 if err != nil {
63 c.Close()
64 return fmt.Errorf("unknown error")
65 }
66
67 return utils.ChangePath(c, path, fileStat.IsDir())
68 case "unzip":
69 if !account.Permissions.Extract {
70 permissionError, _ := json.Marshal(fiber.Map{
71 "type": "error",
72 "error": "You don't have permission to unzip!",
73 })
74
75 c.WriteMessage(mt, permissionError)
76 return nil // Server doesn't care about permission errors

Callers 1

HandleWebsocketFunction · 0.85

Calls 9

ScheduleDebouncedLogFunction · 0.92
SendToAllExcludeFunction · 0.92
IsSafePathFunction · 0.92
ChangePathFunction · 0.92
CreateLogFunction · 0.92
applyEditorChangeFunction · 0.85
HandleUnzipFunction · 0.85
HandleZipFunction · 0.85
GetScopedFolderMethod · 0.80

Tested by

no test coverage detected