fix(drivers): add session renewal cron for MediaFire driver (#9321)

- Implement automatic session token renewal every 6-9 minutes
- Add validation for required SessionToken and Cookie fields in Init
- Handle session expiration by calling renewToken on validation failure
- Prevent storage failures due to MediaFire session timeouts

Fixes session closure issues that occur after server restarts or extended periods.

Co-authored-by: Da3zKi7 <da3zki7@duck.com>
pull/9292/merge
D@' 3z K!7 2025-09-12 03:53:47 -06:00 committed by GitHub
parent 6e7c7d1dd0
commit 16cce37947
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 4 deletions

View File

@ -11,6 +11,7 @@ D@' 3z K!7 - The King Of Cracking
import ( import (
"context" "context"
"fmt" "fmt"
"math/rand"
"net/http" "net/http"
"os" "os"
"time" "time"
@ -19,12 +20,14 @@ import (
"github.com/alist-org/alist/v3/internal/driver" "github.com/alist-org/alist/v3/internal/driver"
"github.com/alist-org/alist/v3/internal/errs" "github.com/alist-org/alist/v3/internal/errs"
"github.com/alist-org/alist/v3/internal/model" "github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/pkg/cron"
"github.com/alist-org/alist/v3/pkg/utils" "github.com/alist-org/alist/v3/pkg/utils"
) )
type Mediafire struct { type Mediafire struct {
model.Storage model.Storage
Addition Addition
cron *cron.Cron
actionToken string actionToken string
@ -57,12 +60,15 @@ func (d *Mediafire) Init(ctx context.Context) error {
if _, err := d.getSessionToken(ctx); err != nil { if _, err := d.getSessionToken(ctx); err != nil {
//fmt.Printf("Init :: Obtain Session Token \n\n") d.renewToken(ctx)
if err := d.renewToken(ctx); err != nil { num := rand.Intn(4) + 6
d.cron = cron.NewCron(time.Minute * time.Duration(num))
d.cron.Do(func() {
d.renewToken(ctx)
})
//fmt.Printf("Init :: Renew Session Token \n\n")
}
} }
return nil return nil

View File

@ -106,6 +106,9 @@ func (d *Mediafire) getSessionToken(ctx context.Context) (string, error) {
} }
d.SessionToken = tokenResp.Response.SessionToken d.SessionToken = tokenResp.Response.SessionToken
//fmt.Printf("Init :: Obtain Session Token %v", d.SessionToken)
op.MustSaveDriverStorage(d) op.MustSaveDriverStorage(d)
return d.SessionToken, nil return d.SessionToken, nil
@ -131,6 +134,9 @@ func (d *Mediafire) renewToken(_ context.Context) error {
} }
d.SessionToken = resp.Response.SessionToken d.SessionToken = resp.Response.SessionToken
//fmt.Printf("Init :: Renew Session Token: %s", resp.Response.Result)
op.MustSaveDriverStorage(d) op.MustSaveDriverStorage(d)
return nil return nil