mirror of
https://github.com/postmannen/ctrl.git
synced 2024-12-14 12:37:31 +00:00
REQToFile<x> now honor the directory path specified
This commit is contained in:
parent
fc3d69a94b
commit
433541fcc1
2 changed files with 25 additions and 4 deletions
|
@ -665,6 +665,8 @@ If used as a **replyMethod** set the **replyMethodArgs** `"replyMethodArgs": ["s
|
|||
|
||||
Append the output of the reply message to a log file specified with the `directory` and `fileName` fields.
|
||||
|
||||
If the value of the **directory** field is not prefixed with `./` or `/` the directory structure file will be created within the **steward data folder** specified in the config file.
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
|
@ -682,6 +684,8 @@ Append the output of the reply message to a log file specified with the `directo
|
|||
|
||||
Write the output of the reply message to a file specified with the `directory` and `fileName` fields, where the writing will write over any existing content of that file.
|
||||
|
||||
If the value of the **directory** field is not prefixed with `./` or `/` the directory structure file will be created within the **steward data folder** specified in the config file.
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
|
|
25
requests.go
25
requests.go
|
@ -488,20 +488,37 @@ func newReplyMessage(proc process, message Message, outData []byte) {
|
|||
// to create.
|
||||
func selectFileNaming(message Message, proc process) (string, string) {
|
||||
var fileName string
|
||||
var folderTree string
|
||||
// As default we set the folder tree to what is specified in the
|
||||
// message.Directory field. If we don't want that in the checks
|
||||
// done later we then replace the value with what we want.
|
||||
folderTree := message.Directory
|
||||
|
||||
checkPrefix := func(s string) bool {
|
||||
if strings.HasPrefix(s, "./") || strings.HasPrefix(s, "/") {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
switch {
|
||||
case message.PreviousMessage == nil:
|
||||
// If this was a direct request there are no previous message to take
|
||||
// information from, so we use the one that are in the current mesage.
|
||||
fileName = message.FileName
|
||||
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.Directory, string(message.ToNode))
|
||||
if !checkPrefix(message.Directory) {
|
||||
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.Directory, string(message.ToNode))
|
||||
}
|
||||
case message.PreviousMessage.ToNode != "":
|
||||
fileName = message.PreviousMessage.FileName
|
||||
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.PreviousMessage.ToNode))
|
||||
if !checkPrefix(message.PreviousMessage.Directory) {
|
||||
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.PreviousMessage.ToNode))
|
||||
}
|
||||
case message.PreviousMessage.ToNode == "":
|
||||
fileName = message.PreviousMessage.FileName
|
||||
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.FromNode))
|
||||
if !checkPrefix(message.PreviousMessage.Directory) {
|
||||
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.FromNode))
|
||||
}
|
||||
}
|
||||
|
||||
return fileName, folderTree
|
||||
|
|
Loading…
Reference in a new issue