From: Ruben Beltran del Rio Date: Tue, 4 Feb 2025 10:08:37 +0000 (+0100) Subject: Add downloads as well X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/commitdiff_plain/ba201a220aa723f98c6a81d74dc4229bf89b282a Add downloads as well --- 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)