fix: issues
This commit is contained in:
5
.vscode/launch.json
vendored
5
.vscode/launch.json
vendored
@@ -11,8 +11,9 @@
|
||||
"mode": "auto",
|
||||
"program": "${workspaceFolder}/main.go",
|
||||
"args": [
|
||||
"publish",
|
||||
// "export",
|
||||
"channel",
|
||||
"export",
|
||||
"--pk=3"
|
||||
// https://t.me/yunpanshare/26640
|
||||
// "--alias", "yunpanshare",
|
||||
// https://t.me/Aliyun_4K_Movies/26640
|
||||
|
||||
@@ -28,6 +28,7 @@ func (t *TClient) Channel(ctx context.Context, channel *tg.Channel, cfg *DBChann
|
||||
request.OffsetID = cfg.MinID + limit
|
||||
request.MinID = cfg.MinID
|
||||
|
||||
logger.Info("get channel message history", zap.Int("min_id", request.MinID), zap.Int("offset", request.OffsetID), zap.Int("limit", request.Limit))
|
||||
history, err := t.Client.API().MessagesGetHistory(ctx, request)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "messages.getHistory")
|
||||
@@ -36,7 +37,11 @@ func (t *TClient) Channel(ctx context.Context, channel *tg.Channel, cfg *DBChann
|
||||
messages := history.(*tg.MessagesChannelMessages).GetMessages()
|
||||
if len(messages) == 0 {
|
||||
if cfg.OffsetID > 0 && request.OffsetID < cfg.OffsetID {
|
||||
cfg.Update(ctx, request.OffsetID)
|
||||
logger.Info("no new message, but update config", zap.Int64("channel", channel.ID), zap.Int("offset", request.OffsetID))
|
||||
if err := cfg.Update(ctx, request.OffsetID); err != nil {
|
||||
logger.Error("update config failed", zap.Error(err), zap.Int64("channel", channel.ID))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
logger.Info("no new message", zap.Int64("channel", channel.ID))
|
||||
@@ -52,14 +57,35 @@ func (t *TClient) Channel(ctx context.Context, channel *tg.Channel, cfg *DBChann
|
||||
for _, item := range messages {
|
||||
switch item.(type) {
|
||||
case *tg.MessageEmpty:
|
||||
|
||||
logger.Info("update config", zap.Int64("channel", channel.ID), zap.Int("msg_id", item.GetID()))
|
||||
if err := cfg.Update(ctx, item.GetID()); err != nil {
|
||||
logger.Error("update config failed", zap.Error(err), zap.Int64("channel", channel.ID))
|
||||
return err
|
||||
}
|
||||
|
||||
continue
|
||||
case *tg.MessageService:
|
||||
|
||||
logger.Info("update config", zap.Int64("channel", channel.ID), zap.Int("msg_id", item.GetID()))
|
||||
if err := cfg.Update(ctx, item.GetID()); err != nil {
|
||||
logger.Error("update config failed", zap.Error(err), zap.Int64("channel", channel.ID))
|
||||
return err
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
msg, ok := item.(*tg.Message)
|
||||
if !ok {
|
||||
logger.Error("convert msg to *tg.Message failed", zap.Int64("channel", channel.ID))
|
||||
|
||||
logger.Info("update config", zap.Int64("channel", channel.ID), zap.Int("msg_id", item.GetID()))
|
||||
if err := cfg.Update(ctx, item.GetID()); err != nil {
|
||||
logger.Error("update config failed", zap.Error(err), zap.Int64("channel", channel.ID))
|
||||
return err
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@@ -41,11 +41,13 @@ func channelExportCmd(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
logger.Info("get remote channel info", zap.Int64("uuid", cfg.UUID), zap.String("title", cfg.Title))
|
||||
channel, err := client.ChannelInfoByID(ctx, cfg.UUID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logger.Info("exporting history msg", zap.Int64("uuid", cfg.UUID))
|
||||
var continueRetryTimes int
|
||||
for {
|
||||
if err := client.Channel(ctx, channel, cfg, false); err != nil {
|
||||
|
||||
@@ -21,8 +21,8 @@ func InitLogger(cfg *config.Config) error {
|
||||
logWriter := zapcore.AddSync(&lj.Logger{
|
||||
Filename: cfg.LogFile,
|
||||
MaxBackups: 3,
|
||||
MaxSize: 1, // megabytes
|
||||
MaxAge: 7, // days
|
||||
MaxSize: 100, // megabytes
|
||||
MaxAge: 7, // days
|
||||
})
|
||||
logCore := zapcore.NewCore(
|
||||
zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()),
|
||||
|
||||
Reference in New Issue
Block a user