Skip to content

Commit

Permalink
Merge pull request #120 from eschizoid/bugfix/library-job-hook-url
Browse files Browse the repository at this point in the history
Fixed library job webhook url
  • Loading branch information
eschizoid authored Dec 28, 2018
2 parents c7d84bf + e5695b7 commit 5bff6ea
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 40 deletions.
4 changes: 2 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions cmd/library/retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ var RetrieveLibraryCmd = &cobra.Command{
defer getJobOutputOutput.Body.Close()
part, err := ioutil.ReadAll(getJobOutputOutput.Body)
ShowError(err)
var zipFileName = writeFile(part)
glacierService.Unzip(zipFileName)
glacierService.Cleanup([]string{zipFileName})
writeFile(part)
//glacierService.Cleanup([]string{fileName})
jsonString, _ := json.Marshal(getJobOutputOutput)
fmt.Println("\n" + string(jsonString))
close(shutdownCh)
Expand All @@ -38,15 +37,16 @@ var RetrieveLibraryCmd = &cobra.Command{

func writeFile(part []byte) string {
var err error
var zipFile *os.File
var retrievedFile *os.File
if retrievalType == "InventoryRetrieval" {
zipFile, err = ioutil.TempFile(os.TempDir(), "inventory.*.json")
retrievedFile, err = ioutil.TempFile(os.TempDir(), "inventory.*.json")
} else if retrievalType == "ArchiveRetrieval" {
zipFile, err = ioutil.TempFile(os.TempDir(), "movie.*.zip")
retrievedFile, err = ioutil.TempFile(os.TempDir(), "movie.*.zip")
glacierService.Unzip(retrievedFile.Name())
}
ShowError(err)
zipFileName := zipFile.Name()
err = ioutil.WriteFile(zipFileName, part, 0644)
fileName := retrievedFile.Name()
err = ioutil.WriteFile(fileName, part, 0644)
ShowError(err)
return zipFileName
return fileName
}
Binary file modified database/storm/library.db
Binary file not shown.
4 changes: 2 additions & 2 deletions hooks/hooks.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
"pass-environment-to-command": [
{
"source": "url",
"name": "t",
"name": "a",
"envname": "RETRIEVAL_TYPE"
},
{
Expand All @@ -240,7 +240,7 @@
"type": "value",
"value": "{{getenv "SLACK_STATUS_TOKEN"}}",
"parameter": {
"source": "payload",
"source": "url",
"name": "token"
}
}
Expand Down
2 changes: 1 addition & 1 deletion hooks/library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ case $# in
--filter "${FILTER}"
;;
retrieve)
if [[ "${RETRIEVAL_TYPE}" = "FileRetrieval" ]]; then
if [[ "${RETRIEVAL_TYPE}" = "ArchiveRetrieval" ]]; then
/home/webhook/go/bin/flixctl library retrieve \
--job-id "${JOB_ID}" \
--file "/plex/movies/movie-$(date +%Y-%m-%d.%H:%M:%S).zip"
Expand Down
11 changes: 8 additions & 3 deletions slack/library/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package library
import (
"encoding/json"
"fmt"
"os"
"strconv"

"github.com/aws/aws-sdk-go/service/glacier"
Expand All @@ -12,6 +13,7 @@ import (

func SendJobs(jobDescriptions []glacier.JobDescription, slackIncomingHookURL string) {
var attachments = make([]slack.Attachment, len(jobDescriptions))
token := os.Getenv("SLACK_MOVIES_SEARCH_TOKEN")
for _, jobDescription := range jobDescriptions {
attachmentFieldJobType := slack.AttachmentField{
Title: "*Job Type*",
Expand Down Expand Up @@ -50,9 +52,12 @@ func SendJobs(jobDescriptions []glacier.JobDescription, slackIncomingHookURL str
MarkdownIn: []string{"text", "fields"},
Actions: []slack.AttachmentAction{
{
Type: "button",
Text: "Start",
URL: fmt.Sprintf("https://marianoflix.duckdns.org:9091/hooks/retrieve-job?t=%s&i%s", *jobDescription.Action, *jobDescription.JobId),
Type: "button",
Text: "Start",
URL: util.RetrieveJobHookURL +
"?a=" + *jobDescription.Action +
"&i=" + *jobDescription.JobId +
"&token=" + token,
Style: "default",
Confirm: &slack.ConfirmationField{
Title: "Are you sure you want to start the job retrieval?",
Expand Down
6 changes: 1 addition & 5 deletions slack/torrent/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ import (
"github.com/nlopes/slack"
)

const (
outgoingHookURL = "https://marianoflix.duckdns.org:9000/hooks/torrent-download"
)

func SendDownloadLinks(search *torrent.Search, slackIncomingHookURL string, directoryDir string, notification bool) {
var attachments = make([]slack.Attachment, len(search.Out))
token := os.Getenv("SLACK_MOVIES_SEARCH_TOKEN")
Expand Down Expand Up @@ -47,7 +43,7 @@ func SendDownloadLinks(search *torrent.Search, slackIncomingHookURL string, dire
attachment := slack.Attachment{
Color: "#C40203",
Title: torrentResult.Name,
TitleLink: outgoingHookURL +
TitleLink: util.TorrentDownloadHookURL +
"?directory=" + directoryDir +
"&name=" + url.QueryEscape(encodedName) +
"&notify=" + strconv.FormatBool(notification) +
Expand Down
6 changes: 6 additions & 0 deletions slack/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ package slack

import (
"fmt"
"os"
"time"
)

var (
TorrentDownloadHookURL = fmt.Sprintf("%s/%s", os.Getenv("HOOKS_URL"), "torrent-download")
RetrieveJobHookURL = fmt.Sprintf("%s/%s", os.Getenv("HOOKS_URL"), "retrieve-job")
)

func GetTimeStamp() int64 {
location, err := time.LoadLocation("America/Chicago")
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions vendor/github.com/eschizoid/flixctl/aws/ec2/service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions vendor/github.com/eschizoid/flixctl/cmd/library/retrieve.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 20 additions & 4 deletions vendor/github.com/eschizoid/flixctl/slack/library/message.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 11 additions & 5 deletions vendor/github.com/eschizoid/flixctl/slack/torrent/message.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions vendor/github.com/eschizoid/flixctl/slack/util.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5bff6ea

Please sign in to comment.