Files
kontor/kontor-gin/internal/cmd/update-title.go
T
Thomas Peetz 4c603a8eff
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s
implement command update-title
2026-10-12 17:37:06 +02:00

48 lines
1.3 KiB
Go

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"
"github.com/spf13/cobra"
"resty.dev/v3"
)
var updateTitleCmd = &cobra.Command{
Use: "update-title",
Short: "Update titles",
Long: "Update titles",
Run: func(cmd *cobra.Command, args []string) {
slog.Info("Update titles using server", "server", config.ServerName)
client := resty.New()
localServer := config.Config.Server[config.ServerName]
slog.Info("get token", "url", localServer.Url)
token := api.GetToken(client, localServer)
api.GetJSON(client, token, localServer, "media/lofis", &api.Medialofis)
for _, lofi := range api.Medialofis {
if lofi.Review {
title, err := helpers.GetVideoTitle(lofi.WebLink)
var updated models.MediaLoFiDTO
if err != nil {
slog.Info("get title for Url", "url", lofi.WebLink, "error", err.Error())
} else {
slog.Info("get title for Url", "url", lofi.WebLink, "title", title)
lofi.Title = title
lofi.Review = false
api.PostJSON(client, localServer, token, config.Config.ApiVersion, fmt.Sprintf("media/lofis/%s", lofi.ID), lofi, &updated)
slog.Info("MediaLoi updated", "MediaLoFi", updated)
}
}
}
},
}
func init() {
rootCmd.AddCommand(updateTitleCmd)
}