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:
@@ -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",
|
||||
@@ -25,18 +31,24 @@ var addLinksCmd = &cobra.Command{
|
||||
slog.Warn("add links failed", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
var login LoginResponse
|
||||
client := resty.New()
|
||||
localServer := config.Config.Server[servername]
|
||||
token := api.GetToken(client, localServer)
|
||||
for _, line := range lines {
|
||||
lofiAdd := models.MediaLofiAdd{Url: line}
|
||||
client := resty.New()
|
||||
PostJSON(client, fmt.Sprintf("%s/%s/%s", server, "api", "login"), &login)
|
||||
addResult := &models.MediaLoFi{}
|
||||
response, err := client.R().
|
||||
SetBody(lofiAdd).
|
||||
SetAuthToken(token).
|
||||
SetHeader("Accept", "application/json").
|
||||
Post("http://localhost:8550/api/v1/media/lofi")
|
||||
SetResult(addResult).
|
||||
Post("http://localhost:8550/api/v1/media/lofis")
|
||||
if err != nil {
|
||||
slog.Info("Add Lofi", "error", err.Error())
|
||||
}
|
||||
if addResult != nil {
|
||||
slog.Info("Lofi added", "lofi", addResult)
|
||||
}
|
||||
slog.Info("Add Lofi", "status", response.StatusCode(), "body", response.Body)
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user