48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"kontor-api-gin/internal/helpers"
|
|
"kontor-api-gin/internal/models"
|
|
"log/slog"
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
"resty.dev/v3"
|
|
)
|
|
|
|
var addLinksCmd = &cobra.Command{
|
|
Use: "add-links [file]",
|
|
Short: "Add Links",
|
|
Long: "Add Links",
|
|
Args: cobra.ExactArgs(1),
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
fileName := args[0]
|
|
slog.Info(fmt.Sprintf("add Links from %s", fileName))
|
|
lines, err := helpers.LinesInFile(fileName)
|
|
if err != nil {
|
|
slog.Warn("add links failed", "error", err)
|
|
os.Exit(1)
|
|
}
|
|
var login LoginResponse
|
|
for _, line := range lines {
|
|
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("Add Lofi", "error", err.Error())
|
|
}
|
|
slog.Info("Add Lofi", "status", response.StatusCode(), "body", response.Body)
|
|
}
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(addLinksCmd)
|
|
}
|