mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 00:39:13 +00:00
fix(macros): torrentdata parsing (#757)
* fix(macros): Fix torrentdata parsing in macros. * fix action test * more dead code * hunting demons * limit success output
This commit is contained in:
parent
92f2b0ebe3
commit
29bedc532d
6 changed files with 54 additions and 83 deletions
|
@ -2,6 +2,8 @@ package domain
|
|||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/autobrr/autobrr/pkg/errors"
|
||||
)
|
||||
|
@ -51,10 +53,30 @@ type Action struct {
|
|||
}
|
||||
|
||||
// ParseMacros parse all macros on action
|
||||
func (a *Action) ParseMacros(release Release) error {
|
||||
func (a *Action) ParseMacros(release *Release) error {
|
||||
var err error
|
||||
|
||||
m := NewMacro(release)
|
||||
if release.TorrentTmpFile == "" &&
|
||||
(strings.Contains(a.ExecArgs, "TorrentPathName") || strings.Contains(a.ExecArgs, "TorrentDataRawBytes") ||
|
||||
strings.Contains(a.WebhookData, "TorrentPathName") || strings.Contains(a.WebhookData, "TorrentDataRawBytes") ||
|
||||
strings.Contains(a.SavePath, "TorrentPathName")) {
|
||||
if err := release.DownloadTorrentFile(); err != nil {
|
||||
return errors.Wrap(err, "webhook: could not download torrent file for release: %v", release.TorrentName)
|
||||
}
|
||||
}
|
||||
|
||||
// if webhook data contains TorrentDataRawBytes, lets read the file into bytes we can then use in the macro
|
||||
if len(release.TorrentDataRawBytes) == 0 &&
|
||||
(strings.Contains(a.ExecArgs, "TorrentDataRawBytes") || strings.Contains(a.WebhookData, "TorrentDataRawBytes")) {
|
||||
t, err := os.ReadFile(release.TorrentTmpFile)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not read torrent file: %v", release.TorrentTmpFile)
|
||||
}
|
||||
|
||||
release.TorrentDataRawBytes = t
|
||||
}
|
||||
|
||||
m := NewMacro(*release)
|
||||
|
||||
a.ExecArgs, err = m.Parse(a.ExecArgs)
|
||||
a.WatchFolder, err = m.Parse(a.WatchFolder)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue