add MediaLofi in kontor-gin (#97)
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s
Co-authored-by: Thomas Peetz <thomas.peetz@cimt-ag.de> Reviewed-on: #97
This commit was merged in pull request #97.
This commit is contained in:
@@ -3,6 +3,7 @@ package cmd
|
||||
import (
|
||||
"fmt"
|
||||
"kontor-api-gin/internal/api"
|
||||
"kontor-api-gin/internal/config"
|
||||
"log/slog"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@@ -10,11 +11,7 @@ import (
|
||||
"resty.dev/v3"
|
||||
)
|
||||
|
||||
var (
|
||||
server string
|
||||
filename string
|
||||
apiVersion string
|
||||
)
|
||||
var filename string
|
||||
|
||||
var exportCmd = &cobra.Command{
|
||||
Use: "export",
|
||||
@@ -23,17 +20,14 @@ var exportCmd = &cobra.Command{
|
||||
// Args: cobra.ExactArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
slog.Info("export kontor")
|
||||
slog.Info("Verbosity level", "level", verbose)
|
||||
slog.Info(fmt.Sprintf("Using server: %s", server))
|
||||
var login LoginResponse
|
||||
slog.Info("Verbosity level", "level", config.Verbose)
|
||||
slog.Info(fmt.Sprintf("Using server: %s", config.ServerName))
|
||||
|
||||
client := resty.New()
|
||||
PostJSON(client, fmt.Sprintf("%s/%s/%s", server, "api", "login"), &login)
|
||||
defer client.Close()
|
||||
localServer := config.Config.Server[config.ServerName]
|
||||
|
||||
for path, value := range api.Registry {
|
||||
GetJSON(client, login.Token, fmt.Sprintf("%s/%s/%s", server, apiVersion, path), value)
|
||||
}
|
||||
export, _ := api.GetData(server, apiVersion)
|
||||
export, _ := api.GetData(localServer, config.Config.ApiVersion)
|
||||
err := api.WriteJson(export, filename)
|
||||
if err != nil {
|
||||
slog.Info("WriteJon failed", "Error:", err)
|
||||
@@ -42,39 +36,11 @@ var exportCmd = &cobra.Command{
|
||||
},
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(exportCmd)
|
||||
|
||||
exportCmd.PersistentFlags().StringVarP(&server, "server", "s", "http://127.0.0.1:8550", "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"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user