mirror of
https://github.com/JackDallas/Premiumizearr.git
synced 2025-12-12 01:40:17 +01:00
Make unzip directory configurable
This commit is contained in:
@@ -51,6 +51,8 @@ Edit the config file at `/opt/premiumizearrd/config.yml`
|
||||
|
||||
`DownloadsDirectory` Path for Premiumizearr to download media files to, that the Arr's watch for new media
|
||||
|
||||
`UnzipDirectory` Path for Premiumizearr to use to temporarily unzip downloads before moving, leave blank and a path in temp will me made
|
||||
|
||||
`bindIP` IP the web server binds to
|
||||
|
||||
`bindPort` Port the web server binds to
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
PremiumizemeAPIKey: ""
|
||||
SonarrURL: http://localhost:8989
|
||||
SonarrAPIKey: ""
|
||||
RadarrURL: http://localhost:7878
|
||||
RadarrAPIKey: ""
|
||||
BlackholeDirectory: ""
|
||||
DownloadsDirectory: ""
|
||||
bindIP: 0.0.0.0
|
||||
bindPort: "8182"
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
@@ -26,6 +28,8 @@ type Config struct {
|
||||
BlackholeDirectory string `yaml:"BlackholeDirectory"`
|
||||
DownloadsDirectory string `yaml:"DownloadsDirectory"`
|
||||
|
||||
UnzipDirectory string `yaml:"UnzipDirectory"`
|
||||
|
||||
BindIP string `yaml:"bindIP"`
|
||||
BindPort string `yaml:"bindPort"`
|
||||
|
||||
@@ -42,6 +46,11 @@ func loadConfigFromDisk() (Config, error) {
|
||||
|
||||
err = yaml.Unmarshal(file, &config)
|
||||
if err != nil {
|
||||
data, err := yaml.Marshal(config)
|
||||
if err == nil {
|
||||
//Save config to disk to add missing fields
|
||||
ioutil.WriteFile("config.yaml", data, 0644)
|
||||
}
|
||||
return config, ErrInvalidConfigFile
|
||||
}
|
||||
|
||||
@@ -57,6 +66,7 @@ func createDefaultConfig() error {
|
||||
RadarrAPIKey: "",
|
||||
BlackholeDirectory: "",
|
||||
DownloadsDirectory: "",
|
||||
UnzipDirectory: "",
|
||||
BindIP: "0.0.0.0",
|
||||
BindPort: "8182",
|
||||
WebRoot: "",
|
||||
@@ -102,3 +112,25 @@ func LoadOrCreateConfig(altConfigLocation string) (Config, error) {
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
func (c *Config) GetTempBaseDir() string {
|
||||
if c.UnzipDirectory != "" {
|
||||
return path.Dir(c.UnzipDirectory)
|
||||
}
|
||||
return path.Join(os.TempDir(), "premiumizearrd")
|
||||
}
|
||||
|
||||
func (c *Config) GetTempDir() (string, error) {
|
||||
// Create temp dir in os temp location
|
||||
tempDir := c.GetTempBaseDir()
|
||||
|
||||
err := os.MkdirAll(tempDir, os.ModePerm)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
dir, err := ioutil.TempDir(tempDir, "unzip-")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return dir, nil
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ func (dw *DirectoryWatcherService) Watch() {
|
||||
dw.downloadsFolderID = utils.GetDownloadsFolderIDFromPremiumizeme(dw.premiumizemeClient)
|
||||
|
||||
log.Info("Clearing tmp directory...")
|
||||
tempDir := utils.GetTempBaseDir()
|
||||
tempDir := dw.config.GetTempBaseDir()
|
||||
err := os.RemoveAll(tempDir)
|
||||
if err != nil {
|
||||
log.Errorf("Error clearing tmp directory %s", tempDir)
|
||||
|
||||
@@ -184,7 +184,7 @@ func (manager *TransferManagerService) HandleFinishedItem(item premiumizeme.Item
|
||||
}
|
||||
log.Trace("Downloading: ", link)
|
||||
|
||||
tempDir, err := utils.GetTempDir()
|
||||
tempDir, err := manager.config.GetTempDir()
|
||||
if err != nil {
|
||||
log.Errorf("Could not create temp dir: %s", err)
|
||||
manager.removeDownload(item.Name)
|
||||
|
||||
@@ -4,9 +4,7 @@ import (
|
||||
"archive/zip"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
@@ -23,21 +21,6 @@ func StripDownloadTypesExtention(fileName string) string {
|
||||
return fileName
|
||||
}
|
||||
|
||||
func GetTempBaseDir() string {
|
||||
return path.Join(os.TempDir(), "premiumizearrd")
|
||||
}
|
||||
|
||||
func GetTempDir() (string, error) {
|
||||
// Create temp dir in os temp location
|
||||
tempDir := GetTempBaseDir()
|
||||
err := os.Mkdir(tempDir, os.ModePerm)
|
||||
dir, err := ioutil.TempDir(tempDir, "unzip-")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return dir, nil
|
||||
}
|
||||
|
||||
// https://golangcode.com/unzip-files-in-go/
|
||||
func Unzip(src string, dest string) error {
|
||||
r, err := zip.OpenReader(src)
|
||||
|
||||
Reference in New Issue
Block a user