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