add MediaLofi in kontor-gin #97

Merged
tpeetz merged 4 commits from feature/server-configuration into develop/0.4.0 2026-10-09 16:26:11 +00:00
7 changed files with 52 additions and 89 deletions
Showing only changes of commit 85295deb22 - Show all commits
+25 -1
View File
@@ -111,14 +111,35 @@ var (
var Registry map[string]any
func GetToken(client *resty.Client, server config.Server) (token string) {
var login LoginResponse
_, err := client.R().
SetBody(Login{
Email: "thomas.peetz@thpeetz.de",
Password: "admin",
}).
SetHeader("Accept", "application/json").
SetResult(&login).
Post("http://127.0.0.1:8550/api/login")
if err != nil {
slog.Info("Health", "error", err.Error())
}
slog.Info("health", "token", login.Token)
return login.Token
}
func GetData(server config.Server, apiVersion string) (data *ExportData, err error) {
var login LoginResponse
client := resty.New()
PostJSON(client, server, fmt.Sprintf("/%s/%s", "api", "login"), &login)
PostJSON(client, server, "api/login", &login)
for path, value := range Registry {
GetJSON(client, login.Token, server, path, value)
if path == "tysc/sports" {
slog.Info("Sports", "value", value, "Registry.Sports", Sports)
}
}
export := ExportData{
Sport: Sports,
@@ -190,6 +211,9 @@ func GetJSON(client *resty.Client, token string, server config.Server, path stri
if err != nil {
slog.Info(url, "error", err.Error())
}
if config.Verbose > 1 {
slog.Info("GetJSON", "value", v)
}
}
func PostJSON(client *resty.Client, server config.Server, path string, v any) {
+8 -1
View File
@@ -2,6 +2,8 @@ package cmd
import (
"fmt"
"kontor-api-gin/internal/api"
"kontor-api-gin/internal/config"
"kontor-api-gin/internal/helpers"
"kontor-api-gin/internal/models"
"log/slog"
@@ -11,6 +13,10 @@ import (
"resty.dev/v3"
)
var (
servername string
)
var addLinksCmd = &cobra.Command{
Use: "add-links [file]",
Short: "Add Links",
@@ -26,7 +32,8 @@ var addLinksCmd = &cobra.Command{
os.Exit(1)
}
client := resty.New()
token := helpers.GetToken(client)
localServer := config.Config.Server[servername]
token := api.GetToken(client, localServer)
for _, line := range lines {
lofiAdd := models.MediaLofiAdd{Url: line}
response, err := client.R().
+5 -6
View File
@@ -3,8 +3,6 @@ package cmd
import (
"kontor-api-gin/internal/api"
"kontor-api-gin/internal/config"
"kontor-api-gin/internal/helpers"
"kontor-api-gin/internal/models"
"log/slog"
"github.com/spf13/cobra"
@@ -30,13 +28,14 @@ var checkCmd = &cobra.Command{
slog.Info("Verbosity level", "level", config.Verbose)
client := resty.New()
defer client.Close()
token := helpers.GetToken(client)
var comics []models.ComicDTO
localServer := config.Config.Server["local"]
mainServer := config.Config.Server["main"]
api.GetJSON(client, token, localServer, "comics/comics", &comics)
localData, _ := api.GetData(localServer, config.Config.ApiVersion)
mainData, _ := api.GetData(mainServer, config.Config.ApiVersion)
slog.Info("comics", "count", len(comics))
slog.Info("comics local", "count", len(localData.Comic))
slog.Info("comics main", "count", len(mainData.Comic))
slog.Info("kontor.check_kontor.check_duplicate_links")
// check_duplicate_links(first_server, dirs)
+5 -17
View File
@@ -4,7 +4,6 @@ import (
"fmt"
"kontor-api-gin/internal/api"
"kontor-api-gin/internal/config"
"kontor-api-gin/internal/helpers"
"log/slog"
"github.com/spf13/cobra"
@@ -12,11 +11,7 @@ import (
"resty.dev/v3"
)
var (
servername string
filename string
apiVersion string
)
var filename string
var exportCmd = &cobra.Command{
Use: "export",
@@ -26,18 +21,13 @@ var exportCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
slog.Info("export kontor")
slog.Info("Verbosity level", "level", config.Verbose)
slog.Info(fmt.Sprintf("Using server: %s", servername))
slog.Info(fmt.Sprintf("Using server: %s", config.ServerName))
client := resty.New()
defer client.Close()
localServer := config.Config.Server[servername]
localServer := config.Config.Server[config.ServerName]
token := helpers.GetToken(client)
for path, value := range api.Registry {
api.GetJSON(client, token, localServer, path, value)
}
export, _ := api.GetData(localServer, apiVersion)
export, _ := api.GetData(localServer, config.Config.ApiVersion)
err := api.WriteJson(export, filename)
if err != nil {
slog.Info("WriteJon failed", "Error:", err)
@@ -49,10 +39,8 @@ var exportCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(exportCmd)
exportCmd.PersistentFlags().StringVarP(&servername, "servername", "s", "local", "Define server to get Kontor items")
viper.BindPFlag("server", exportCmd.PersistentFlags().Lookup("server"))
exportCmd.PersistentFlags().StringVarP(&filename, "file", "f", "/home/tpeetz/.sync/media/data-gin.json", "Filename to store data")
viper.BindPFlag("file", exportCmd.PersistentFlags().Lookup("file"))
exportCmd.PersistentFlags().StringVarP(&apiVersion, "api", "a", "api/v1", "API Version")
exportCmd.PersistentFlags().StringVarP(&config.Config.ApiVersion, "api", "a", "api/v1", "API Version")
viper.BindPFlag("api", exportCmd.PersistentFlags().Lookup("api"))
}
+2
View File
@@ -35,5 +35,7 @@ func init() {
rootCmd.PersistentFlags().StringVarP(&config.CfgFile, "config", "c", "/home/tpeetz/.config/kli.yaml", "config file")
rootCmd.PersistentFlags().CountVarP(&config.Verbose, "verbose", "v", "increase verbosity (-v, -vv, -vvv)")
viper.BindPFlag("config", rootCmd.PersistentFlags().Lookup("config"))
exportCmd.Flags().StringVarP(&config.ServerName, "servername", "s", "local", "Define server to get Kontor items")
viper.BindPFlag("server", exportCmd.PersistentFlags().Lookup("server"))
cobra.OnInitialize(config.InitCliConfig)
}
+7 -5
View File
@@ -9,10 +9,11 @@ import (
)
var (
CfgFile string
Verbose int
Overwrite bool
Config CliConfig
CfgFile string
Verbose int
Overwrite bool
ServerName string
Config CliConfig
)
type Server struct {
@@ -22,7 +23,8 @@ type Server struct {
}
type CliConfig struct {
Server map[string]Server `mapstructure:"server"`
ApiVersion string
Server map[string]Server `mapstructure:"server"`
}
func InitCliConfig() {
-59
View File
@@ -1,59 +0,0 @@
package helpers
import (
"log/slog"
"resty.dev/v3"
)
type Login struct {
Email string
Password string
}
type LoginResponse struct {
Token string
}
func GetToken(client *resty.Client) (token string) {
var login LoginResponse
_, err := client.R().
SetBody(Login{
Email: "thomas.peetz@thpeetz.de",
Password: "admin",
}).
SetHeader("Accept", "application/json").
SetResult(&login).
Post("http://127.0.0.1:8550/api/login")
if err != nil {
slog.Info("Health", "error", err.Error())
}
slog.Info("health", "token", login.Token)
return login.Token
}
func GetJSON(client *resty.Client, token string, url string, v any) {
_, err := client.R().
SetAuthToken(token).
SetHeader("Accept", "application/json").
SetResult(v).
Get(url)
if err != nil {
slog.Info(url, "error", err.Error())
}
}
func PostJSON(client *resty.Client, url string, v any) {
_, err := client.R().
SetBody(Login{
Email: "thomas.peetz@thpeetz.de",
Password: "admin",
}).
SetHeader("Accept", "application/json").
SetResult(v).
Post(url)
if err != nil {
slog.Info("Health", "error", err.Error())
}
slog.Info(url, "token", v)
}