diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-02-04 11:08:37 +0100 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-02-04 11:08:37 +0100 |
| commit | ba201a220aa723f98c6a81d74dc4229bf89b282a (patch) | |
| tree | 1be23c35e810823855f535993634b3dc6218bcc8 | |
| parent | 8cd28eb8cede1c6888cbbcd319a9617304bfc4c1 (diff) | |
Add downloads as well
| -rw-r--r-- | internal/mobius/friendship_quest_file_extensions.go | 34 | ||||
| -rw-r--r-- | internal/mobius/transaction_handlers.go | 4 |
2 files changed, 34 insertions, 4 deletions
diff --git a/internal/mobius/friendship_quest_file_extensions.go b/internal/mobius/friendship_quest_file_extensions.go index 1ef8ad6..f04868c 100644 --- a/internal/mobius/friendship_quest_file_extensions.go +++ b/internal/mobius/friendship_quest_file_extensions.go @@ -165,9 +165,39 @@ func HandleDeleteFileWithUserFolders(cc *hotline.ClientConn, t *hotline.Transact resolvedPath, err := ResolveUserPath(cc, requestedPath[len(cc.FileRoot())+1:]) if err != nil { - return cc.NewErrReply(t, "Cannot upload to non-existent user folder.") + return cc.NewErrReply(t, "Cannot delete non-existent file.") } updateTransactionPath(t, resolvedPath) - return HandleUploadFolder(cc, t) + return HandleDeleteFile(cc, t) +} + +func HandleDownloadFileWithUserFolders(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 download non-existent user file.") + } + + updateTransactionPath(t, resolvedPath) + return HandleDownloadFile(cc, t) +} + +func HandleDownloadFolderWithUserFolders(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 download non-existent user folder.") + } + + updateTransactionPath(t, resolvedPath) + return HandleDownloadFolder(cc, t) } diff --git a/internal/mobius/transaction_handlers.go b/internal/mobius/transaction_handlers.go index 32535b2..6451212 100644 --- a/internal/mobius/transaction_handlers.go +++ b/internal/mobius/transaction_handlers.go @@ -31,8 +31,8 @@ func RegisterHandlers(srv *hotline.Server) { srv.HandleFunc(hotline.TranDeleteFile, HandleDeleteFileWithUserFolders) srv.HandleFunc(hotline.TranDeleteUser, HandleDeleteUser) srv.HandleFunc(hotline.TranDisconnectUser, HandleDisconnectUser) - srv.HandleFunc(hotline.TranDownloadFile, HandleDownloadFile) - srv.HandleFunc(hotline.TranDownloadFldr, HandleDownloadFolder) + srv.HandleFunc(hotline.TranDownloadFile, HandleDownloadFileWithUserFolders) + srv.HandleFunc(hotline.TranDownloadFldr, HandleDownloadFolderWithUserFolders) srv.HandleFunc(hotline.TranGetClientInfoText, HandleGetClientInfoText) srv.HandleFunc(hotline.TranGetFileInfo, HandleGetFileInfo) srv.HandleFunc(hotline.TranGetFileNameList, HandleGetFileNameListWithUserFolders) |