diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-02-04 10:59:32 +0100 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-02-04 10:59:32 +0100 |
| commit | 8cd28eb8cede1c6888cbbcd319a9617304bfc4c1 (patch) | |
| tree | 6cfec52f435714b0854de2a5994761b46a28f824 /internal | |
| parent | d34160c512a52cf1f5caf59fa00372d3a627e24c (diff) | |
Allow to delete home files / replace files
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/mobius/friendship_quest_file_extensions.go | 15 | ||||
| -rw-r--r-- | internal/mobius/transaction_handlers.go | 17 |
2 files changed, 28 insertions, 4 deletions
diff --git a/internal/mobius/friendship_quest_file_extensions.go b/internal/mobius/friendship_quest_file_extensions.go index fb23b79..1ef8ad6 100644 --- a/internal/mobius/friendship_quest_file_extensions.go +++ b/internal/mobius/friendship_quest_file_extensions.go @@ -156,3 +156,18 @@ func HandleUploadFolderWithUserFolders(cc *hotline.ClientConn, t *hotline.Transa updateTransactionPath(t, resolvedPath) return HandleUploadFolder(cc, t) } + +func HandleDeleteFileWithUserFolders(cc *hotline.ClientConn, t *hotline.Transaction) (res []hotline.Transaction) { + requestedPath, err := hotline.ReadPath(cc.FileRoot(), t.GetField(hotline.FieldFilePath).Data, nil) + if err != nil { + return res + } + + resolvedPath, err := ResolveUserPath(cc, requestedPath[len(cc.FileRoot())+1:]) + if err != nil { + return cc.NewErrReply(t, "Cannot upload to non-existent user folder.") + } + + updateTransactionPath(t, resolvedPath) + return HandleUploadFolder(cc, t) +} diff --git a/internal/mobius/transaction_handlers.go b/internal/mobius/transaction_handlers.go index e74056f..32535b2 100644 --- a/internal/mobius/transaction_handlers.go +++ b/internal/mobius/transaction_handlers.go @@ -28,7 +28,7 @@ func RegisterHandlers(srv *hotline.Server) { srv.HandleFunc(hotline.TranChatSend, HandleChatSend) srv.HandleFunc(hotline.TranDelNewsArt, HandleDelNewsArt) srv.HandleFunc(hotline.TranDelNewsItem, HandleDelNewsItem) - srv.HandleFunc(hotline.TranDeleteFile, HandleDeleteFile) + srv.HandleFunc(hotline.TranDeleteFile, HandleDeleteFileWithUserFolders) srv.HandleFunc(hotline.TranDeleteUser, HandleDeleteUser) srv.HandleFunc(hotline.TranDisconnectUser, HandleDisconnectUser) srv.HandleFunc(hotline.TranDownloadFile, HandleDownloadFile) @@ -346,6 +346,13 @@ func HandleDeleteFile(cc *hotline.ClientConn, t *hotline.Transaction) (res []hot fileName := t.GetField(hotline.FieldFileName).Data filePath := t.GetField(hotline.FieldFilePath).Data + var fp hotline.FilePath + if filePath != nil { + if _, err := fp.Write(filePath); err != nil { + return res + } + } + fullFilePath, err := hotline.ReadPath(cc.FileRoot(), filePath, fileName) if err != nil { return res @@ -363,11 +370,11 @@ func HandleDeleteFile(cc *hotline.ClientConn, t *hotline.Transaction) (res []hot switch mode := fi.Mode(); { case mode.IsDir(): - if !cc.Authorize(hotline.AccessDeleteFolder) { + if !cc.Authorize(hotline.AccessDeleteFolder) && !fp.IsUserDir() { return cc.NewErrReply(t, "You are not allowed to delete folders.") } case mode.IsRegular(): - if !cc.Authorize(hotline.AccessDeleteFile) { + if !cc.Authorize(hotline.AccessDeleteFile) && !fp.IsUserDir() { return cc.NewErrReply(t, "You are not allowed to delete files.") } } @@ -1438,7 +1445,9 @@ func HandleUploadFile(cc *hotline.ClientConn, t *hotline.Transaction) (res []hot } if _, err := cc.Server.FS.Stat(fullFilePath); err == nil { - return cc.NewErrReply(t, fmt.Sprintf("Cannot accept upload because there is already a file named \"%v\". Try choosing a different Name.", string(fileName))) + if !fp.IsUserDir() { + return cc.NewErrReply(t, fmt.Sprintf("Cannot accept upload because there is already a file named \"%v\". Try choosing a different Name.", string(fileName))) + } } ft := cc.NewFileTransfer(hotline.FileUpload, cc.FileRoot(), fileName, filePath, transferSize) |