fix: issues

This commit is contained in:
Rogee
2024-09-02 16:20:28 +08:00
parent 73ce8585bb
commit 772421c40d
4 changed files with 12 additions and 4 deletions

3
.vscode/launch.json vendored
View File

@@ -13,7 +13,8 @@
"args": [ "args": [
"export", "export",
"--alias", "--alias",
"yunpanshare" "yunpanshare",
"--history",
] ]
} }
] ]

View File

@@ -15,7 +15,7 @@ func (t *TClient) Channel(ctx context.Context, channel *tg.Channel, cfg *Channel
request := &tg.MessagesGetHistoryRequest{ request := &tg.MessagesGetHistoryRequest{
Peer: inputPeer, Peer: inputPeer,
Limit: 1, Limit: 10,
} }
if modeHistory { // 提供此ID供遍历历史消息 if modeHistory { // 提供此ID供遍历历史消息

View File

@@ -17,6 +17,9 @@ type ChannelConfig struct {
} }
func NewChannelConfig(channelID int64) *ChannelConfig { func NewChannelConfig(channelID int64) *ChannelConfig {
if channelID == 0 {
panic("channel id is required")
}
return &ChannelConfig{ID: channelID} return &ChannelConfig{ID: channelID}
} }
@@ -53,7 +56,7 @@ func (c *ChannelConfig) file(_ context.Context) (string, error) {
// if file not exists then create it // if file not exists then create it
if _, err := os.Stat(channelConfigFile); os.IsNotExist(err) { if _, err := os.Stat(channelConfigFile); os.IsNotExist(err) {
// create config file // create config file
data, _ := json.Marshal(&ChannelConfig{ID: channelID}) data, _ := json.Marshal(c)
if err := os.WriteFile(channelConfigFile, data, 0o644); err != nil { if err := os.WriteFile(channelConfigFile, data, 0o644); err != nil {
return "", errors.Wrap(err, "write channel config") return "", errors.Wrap(err, "write channel config")
} }

View File

@@ -47,7 +47,11 @@ func exportCmd(ctx context.Context) error {
} }
} }
cfg := NewChannelConfig(channel.ID) if channel.GetID() == 0 {
return errors.New("channel not found")
}
cfg := NewChannelConfig(channel.GetID())
if err := cfg.Read(ctx); err != nil { if err := cfg.Read(ctx); err != nil {
return err return err
} }