mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-08-19 03:13:58 +08:00
fix: refresh alist token after startup 401s
The init login no longer satisfies the dedup window, so an early 401 triggers a real refresh; later 401s reuse it. Clarify that streaming uploads cannot replay their body.
This commit is contained in:
@@ -95,6 +95,11 @@ func (a *Alist) Init(ctx context.Context, cfg config.StorageConfig) error {
|
||||
if err := a.getToken(ctx); err != nil {
|
||||
return fmt.Errorf("failed to login to Alist: %w", err)
|
||||
}
|
||||
// The init login must not satisfy the refresh dedup window: a 401 right
|
||||
// after startup has to trigger a real refresh, not reuse this token.
|
||||
a.tokenMu.Lock()
|
||||
a.lastLoginAt = time.Time{}
|
||||
a.tokenMu.Unlock()
|
||||
a.logger.Debug("Logged in to Alist")
|
||||
|
||||
go a.refreshToken(ctx, *alistConfig)
|
||||
@@ -136,7 +141,7 @@ func (a *Alist) Save(ctx context.Context, reader io.Reader, storagePath string)
|
||||
rs, seekable := reader.(io.ReadSeeker)
|
||||
if !seekable {
|
||||
a.logger.Warnf("Upload rejected with %s; reader is not seekable, cannot retry", status)
|
||||
return fmt.Errorf("failed to save file to Alist: %s", status)
|
||||
return fmt.Errorf("failed to save file to Alist: %s (streaming reader cannot be replayed for retry)", status)
|
||||
}
|
||||
if _, err := rs.Seek(0, io.SeekStart); err != nil {
|
||||
return fmt.Errorf("failed to rewind reader before retry: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user