feat: login

This commit is contained in:
Rogee
2024-09-02 14:50:51 +08:00
parent 97e0731e2e
commit d739ca0184
7 changed files with 80 additions and 51 deletions

View File

@@ -19,31 +19,7 @@ func ExportCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "export",
Short: "export channels",
RunE: wrapE(func(ctx context.Context) error {
if channelID == 0 && channelAlias == "" {
return errors.New("channel id or alias is required")
}
var channel *tg.Channel
var err error
if channelAlias != "" {
channel, err = client.ChannelInfoByAlias(ctx, channelAlias)
if err != nil {
return err
}
} else {
channel, err = client.ChannelInfoByID(ctx, channelID)
if err != nil {
return err
}
}
if downloadMedia {
client.WithMedia()
}
return client.Channel(ctx, channel, offsetID)
}),
RunE: wrapE(exportCmd),
}
cmd.Flags().Int64Var(&channelID, "channel", 0, "channel id")
@@ -53,3 +29,35 @@ func ExportCmd() *cobra.Command {
return cmd
}
func exportCmd(ctx context.Context) error {
if channelID == 0 && channelAlias == "" {
return errors.New("channel id or alias is required")
}
var channel *tg.Channel
var err error
if channelAlias != "" {
channel, err = client.ChannelInfoByAlias(ctx, channelAlias)
if err != nil {
return err
}
} else {
channel, err = client.ChannelInfoByID(ctx, channelID)
if err != nil {
return err
}
}
if downloadMedia {
client.WithMedia()
}
cfg, err := client.SaveChannelConfig(ctx, channel.ID, offsetID)
if err != nil {
return err
}
return nil
return client.Channel(ctx, channel, cfg.Offset)
}