This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"kontor-api-gin/internal/helpers"
|
||||
"kontor-api-gin/internal/models"
|
||||
"log/slog"
|
||||
"os"
|
||||
|
||||
"github.com/go-stomp/stomp/v3"
|
||||
"github.com/spf13/cobra"
|
||||
"resty.dev/v3"
|
||||
)
|
||||
|
||||
var addLinksCmd = &cobra.Command{
|
||||
@@ -17,14 +17,6 @@ var addLinksCmd = &cobra.Command{
|
||||
Long: "Add Links",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
conn, err := stomp.Dial("tcp", "localhost:61616",
|
||||
stomp.ConnOpt.Login("artemis", "artemis"), // Provide username and password
|
||||
)
|
||||
if err != nil {
|
||||
slog.Info("failed to connect to Artemis: %s", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer conn.Disconnect()
|
||||
|
||||
fileName := args[0]
|
||||
slog.Info(fmt.Sprintf("add Links from %s", fileName))
|
||||
@@ -33,18 +25,20 @@ var addLinksCmd = &cobra.Command{
|
||||
slog.Warn("add links failed", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
var login LoginResponse
|
||||
for _, line := range lines {
|
||||
b, jsonErr := json.Marshal(line)
|
||||
if jsonErr != nil {
|
||||
slog.Info("Json encoding failed", "error", jsonErr.Error())
|
||||
}
|
||||
err = conn.Send("media.link", "application/json", b)
|
||||
|
||||
lofiAdd := models.MediaLofiAdd{Url: line}
|
||||
client := resty.New()
|
||||
PostJSON(client, fmt.Sprintf("%s/%s/%s", server, "api", "login"), &login)
|
||||
response, err := client.R().
|
||||
SetBody(lofiAdd).
|
||||
SetHeader("Accept", "application/json").
|
||||
Post("http://localhost:8550/api/v1/media/lofi")
|
||||
if err != nil {
|
||||
slog.Info("send failed", "error", err.Error())
|
||||
slog.Info("Add Lofi", "error", err.Error())
|
||||
}
|
||||
slog.Info("Add Lofi", "status", response.StatusCode(), "body", response.Body)
|
||||
}
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user