fix: publish

This commit is contained in:
Rogee
2024-09-04 13:29:15 +08:00
parent 3f6656d97e
commit d7c9d40e37
5 changed files with 29 additions and 7 deletions

View File

@@ -2,6 +2,9 @@ package internal
import (
"context"
"fmt"
"exporter/config"
"github.com/gotd/td/tg"
"github.com/pkg/errors"
@@ -18,7 +21,12 @@ func ExportCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "export",
Short: "export channels",
RunE: wrapE(exportCmd),
PreRunE: func(cmd *cobra.Command, args []string) error {
fmt.Println("init client")
defer fmt.Println("init client done")
return InitClient(config.C)
},
RunE: wrapE(exportCmd),
}
cmd.Flags().Int64Var(&channelID, "channel", 0, "channel id")

View File

@@ -2,6 +2,9 @@ package internal
import (
"context"
"fmt"
"exporter/config"
"github.com/spf13/cobra"
)
@@ -10,6 +13,11 @@ func LoginCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "login",
Short: "login account",
PreRunE: func(cmd *cobra.Command, args []string) error {
fmt.Println("init client")
defer fmt.Println("init client done")
return InitClient(config.C)
},
RunE: wrapE(func(ctx context.Context) error {
return client.Login(ctx)
}),

View File

@@ -21,7 +21,9 @@ func PublishCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "publish",
Short: "publish posts",
RunE: wrapE(publishCmd),
RunE: func(cmd *cobra.Command, args []string) error {
return publishCmd(context.Background())
},
}
return cmd

View File

@@ -2,8 +2,10 @@ package internal
import (
"context"
"fmt"
"time"
"exporter/config"
"exporter/database/telegram_resource/public/model"
"exporter/database/telegram_resource/public/table"
"exporter/pkg/errorx"
@@ -17,7 +19,12 @@ func WatchCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "watch",
Short: "watch channels",
RunE: wrapE(watchCmd),
PreRunE: func(cmd *cobra.Command, args []string) error {
fmt.Println("init client")
defer fmt.Println("init client done")
return InitClient(config.C)
},
RunE: wrapE(watchCmd),
}
return cmd

View File

@@ -27,10 +27,7 @@ func main() {
if err := internal.InitDB(config.C.DSN); err != nil {
return errors.Wrap(err, "init db")
}
fmt.Println("init client")
defer fmt.Println("init client done")
return internal.InitClient(config.C)
return nil
},
PersistentPostRunE: func(cmd *cobra.Command, args []string) error {
fmt.Println("client exit")