mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 00:39:13 +00:00
feat(actions): implement TorrentDataRawBytes macro (#444)
* feat(action): implement TorrentDataRawBytes * better citizen * feat(filters): external support TorrentDataRawBytes macro * feat(actions): exec add TorrentDataRawBytes macro * feat(actions): exec add TorrentDataRawBytes macro
This commit is contained in:
parent
c1d2697e18
commit
c7b372ee4e
5 changed files with 59 additions and 3 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"bytes"
|
||||
"crypto/tls"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
|
@ -139,6 +140,15 @@ func (s *service) watchFolder(action domain.Action, release domain.Release) erro
|
|||
}
|
||||
}
|
||||
|
||||
if len(release.TorrentDataRawBytes) == 0 {
|
||||
t, err := ioutil.ReadFile(release.TorrentTmpFile)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not read torrent file: %v", release.TorrentTmpFile)
|
||||
}
|
||||
|
||||
release.TorrentDataRawBytes = t
|
||||
}
|
||||
|
||||
m := domain.NewMacro(release)
|
||||
|
||||
// parse and replace values in argument string before continuing
|
||||
|
@ -184,12 +194,23 @@ func (s *service) watchFolder(action domain.Action, release domain.Release) erro
|
|||
}
|
||||
|
||||
func (s *service) webhook(action domain.Action, release domain.Release) error {
|
||||
if release.TorrentTmpFile == "" && strings.Contains(action.WebhookData, "TorrentPathName") {
|
||||
// if webhook data contains TorrentPathName or TorrentDataRawBytes, lets download the torrent file
|
||||
if release.TorrentTmpFile == "" && (strings.Contains(action.WebhookData, "TorrentPathName") || strings.Contains(action.WebhookData, "TorrentDataRawBytes")) {
|
||||
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(action.WebhookData, "TorrentDataRawBytes") {
|
||||
t, err := ioutil.ReadFile(release.TorrentTmpFile)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not read torrent file: %v", release.TorrentTmpFile)
|
||||
}
|
||||
|
||||
release.TorrentDataRawBytes = t
|
||||
}
|
||||
|
||||
m := domain.NewMacro(release)
|
||||
|
||||
// parse and replace values in argument string before continuing
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue