From 91f2e1abcb5120541934d6b7453d51567765b604 Mon Sep 17 00:00:00 2001 From: RPJosh Date: Thu, 22 Sep 2022 19:45:33 +0200 Subject: [PATCH] Create JSON modell --- configs/ncConverter.json | 21 ++++++++++++++ internal/models/ncconvert.go | 49 ++++++++++++++++++++++++++++++++ internal/models/webconfig.go | 6 ++-- internal/ncworker/ncconverter.go | 9 ++++++ internal/ncworker/scheduler.go | 7 +++++ scripts/run.sh | 2 +- 6 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 configs/ncConverter.json create mode 100644 internal/models/ncconvert.go create mode 100644 internal/ncworker/ncconverter.go create mode 100644 internal/ncworker/scheduler.go mode change 100644 => 100755 scripts/run.sh diff --git a/configs/ncConverter.json b/configs/ncConverter.json new file mode 100644 index 0000000..b5eae77 --- /dev/null +++ b/configs/ncConverter.json @@ -0,0 +1,21 @@ +{ + "users": [ + { + "authUser": "Unique Username (from ", + "nextcloudUrl": "https://cloud.myDomain.de", + "username": "MyUsername", + "password": "App Password", + + "jobs": [ + { + "jobName": "", + "sourceDir": "Arbeit/", + "destinationDir": "Ebooks/", + "keepFolders": true, + "recursive": true, + "execution": [ "01:00", "15:00" ] + } + ] + } + ] +} \ No newline at end of file diff --git a/internal/models/ncconvert.go b/internal/models/ncconvert.go new file mode 100644 index 0000000..dc7fad2 --- /dev/null +++ b/internal/models/ncconvert.go @@ -0,0 +1,49 @@ +package models + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "os" +) + +type User struct { + AuthUser string`json:"authUser"` + NextcloudBaseUrl string`json:"nextcloudUrl"` + Username string`json:"username"` + Password string`json:"password"` +} + +type ConvertJob struct { + JobName string`json:"jobName"` + SourceDir string`json:"sourceDir"` + DestinationDir string`json:"destinationDir"` + KeepFolders string`json:"keepFolders"` + Recursive string`json:"recursive"` + Executions []string`json:"execution"` +} + +type NcConverter struct { + Users []User`json:"users"` +} + +// Parses the given file to the in memory struct +func ParseUsers(filePath string) (*NcConverter, error) { + + file, err := os.OpenFile(filePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + if err != nil { + return nil, fmt.Errorf("failed to open the file '%s': %s", filePath, err) + } + defer file.Close() + + byteValue, err := ioutil.ReadAll(file) + if err != nil { + return nil, fmt.Errorf("failed to parse 'ncConverter.json': %s", err) + } + + var conv NcConverter + + json.Unmarshal(byteValue, &conv) + + return &conv, nil +} \ No newline at end of file diff --git a/internal/models/webconfig.go b/internal/models/webconfig.go index 08ed494..5c453cb 100644 --- a/internal/models/webconfig.go +++ b/internal/models/webconfig.go @@ -2,7 +2,6 @@ package models import ( "flag" - "fmt" "os" yaml "gopkg.in/yaml.v3" @@ -27,6 +26,7 @@ type Logging struct { LogFilePath string `yaml:"logFilePath"` } +// Parses the given configuration file (.yaml file) to an WebConfiguration func ParseConfig(webConfig *WebConfig, file string) (*WebConfig, error) { if file == "" { return webConfig, nil @@ -70,7 +70,9 @@ func SetConfig() (*WebConfig, error) { webConfig := getDefaultConfig() webConfig, err := ParseConfig(webConfig, configPath) if err != nil { - return nil, fmt.Errorf("unable to parse the configuration file '%s': %s", configPath, err) + logger.Error("Unable to parse the configuration file '%s': %s", configPath, err) + webConfig = getDefaultConfig() + err = nil } _ = flag.String("config", "./config.yaml", "Path to the configuration file (see configs/config.yaml) for an example") diff --git a/internal/ncworker/ncconverter.go b/internal/ncworker/ncconverter.go new file mode 100644 index 0000000..8c1e9fb --- /dev/null +++ b/internal/ncworker/ncconverter.go @@ -0,0 +1,9 @@ +package ncworker + +type NcConverter struct { + NextcloudBaseUrl string`json:"nextcloudUrl"` + Username string`json:"username"` + App + SourceDir string`json:"users"` + DestinationDir string`json:"users"` +} \ No newline at end of file diff --git a/internal/ncworker/scheduler.go b/internal/ncworker/scheduler.go new file mode 100644 index 0000000..00451f2 --- /dev/null +++ b/internal/ncworker/scheduler.go @@ -0,0 +1,7 @@ +package ncworker + + + +func scheduleExecutions() { + +} \ No newline at end of file diff --git a/scripts/run.sh b/scripts/run.sh old mode 100644 new mode 100755 index b2793db..799c694 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -1,3 +1,3 @@ #!/bin/sh -nodemon --delay 1s -e go,html --ignore web/app/ --exec go run ./cmd/ncDocConverth --signal SIGTERM \ No newline at end of file +./web/app/node_modules/.bin/nodemon --delay 10s -e go,html --ignore web/app/ --signal SIGTERM --exec go run ./cmd/ncDocConverth || exit 1 \ No newline at end of file