Compare commits

...

4 Commits

Author SHA1 Message Date
Andy Hsu
81e10f8939 ci: set prerelease before the build completes 2023-02-25 18:06:35 +08:00
Andy Hsu
4dd753de52 fix(aliyundrive_open): missed expire_sec while get link (close #3610) 2023-02-25 17:54:36 +08:00
Andy Hsu
79df63d319 chore(aliyundrive): change alert info 2023-02-25 14:28:27 +08:00
Andy Hsu
ec54831162 fix: only refresh token while do request (close #3591) 2023-02-24 20:31:12 +08:00
5 changed files with 52 additions and 38 deletions

19
.github/workflows/changelog.yml vendored Normal file
View File

@@ -0,0 +1,19 @@
name: auto changelog
on:
push:
tags:
- '*'
jobs:
changelog:
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- run: npx changelogithub # or changelogithub@0.12 if ensure the stable result
env:
GITHUB_TOKEN: ${{secrets.MY_TOKEN}}

View File

@@ -1,24 +1,11 @@
name: release name: release
on: on:
push: release:
tags: types: [ published ]
- '*'
jobs: jobs:
changelog:
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- run: npx changelogithub # or changelogithub@0.12 if ensure the stable result
env:
GITHUB_TOKEN: ${{secrets.MY_TOKEN}}
release: release:
needs: changelog
strategy: strategy:
matrix: matrix:
platform: [ ubuntu-latest ] platform: [ ubuntu-latest ]
@@ -26,6 +13,13 @@ jobs:
name: Release name: Release
runs-on: ${{ matrix.platform }} runs-on: ${{ matrix.platform }}
steps: steps:
- name: prerelease
uses: irongut/EditRelease@v1.2.0
with:
token: ${{ secrets.MY_TOKEN }}
id: ${{ github.event.release.id }}
prerelease: true
- name: Setup Go - name: Setup Go
uses: actions/setup-go@v3 uses: actions/setup-go@v3
with: with:
@@ -47,6 +41,13 @@ jobs:
run: | run: |
bash build.sh release bash build.sh release
- name: prerelease
uses: irongut/EditRelease@v1.2.0
with:
token: ${{ secrets.MY_TOKEN }}
id: ${{ github.event.release.id }}
prerelease: false
- name: Release - name: Release
uses: softprops/action-gh-release@v1 uses: softprops/action-gh-release@v1
with: with:

View File

@@ -18,7 +18,9 @@ type Addition struct {
var config = driver.Config{ var config = driver.Config{
Name: "Aliyundrive", Name: "Aliyundrive",
DefaultRoot: "root", DefaultRoot: "root",
Alert: "warning|Deprecated, no longer maintained and will be removed in a future version", Alert: `warning|There may be an infinite loop bug in this driver.
Deprecated, no longer maintained and will be removed in a future version.
We recommend using the official driver AliyundriveOpen.`,
} }
func init() { func init() {

View File

@@ -5,24 +5,19 @@ import (
"io" "io"
"math" "math"
"net/http" "net/http"
"time"
"github.com/alist-org/alist/v3/drivers/base" "github.com/alist-org/alist/v3/drivers/base"
"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/internal/op"
"github.com/alist-org/alist/v3/pkg/cron"
"github.com/alist-org/alist/v3/pkg/utils" "github.com/alist-org/alist/v3/pkg/utils"
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
log "github.com/sirupsen/logrus"
) )
type AliyundriveOpen struct { type AliyundriveOpen struct {
model.Storage model.Storage
Addition Addition
base string base string
cron *cron.Cron
AccessToken string AccessToken string
DriveId string DriveId string
@@ -46,22 +41,10 @@ func (d *AliyundriveOpen) Init(ctx context.Context) error {
return err return err
} }
d.DriveId = utils.Json.Get(res, "default_drive_id").ToString() d.DriveId = utils.Json.Get(res, "default_drive_id").ToString()
d.cron = cron.NewCron(time.Hour * 2)
d.cron.Do(func() {
err := d.refreshToken()
d.Status = err.Error()
op.MustSaveDriverStorage(d)
if err != nil {
log.Errorf("%+v", err)
}
})
return nil return nil
} }
func (d *AliyundriveOpen) Drop(ctx context.Context) error { func (d *AliyundriveOpen) Drop(ctx context.Context) error {
if d.cron != nil {
d.cron.Stop()
}
return nil return nil
} }
@@ -80,6 +63,7 @@ func (d *AliyundriveOpen) Link(ctx context.Context, file model.Obj, args model.L
req.SetBody(base.Json{ req.SetBody(base.Json{
"drive_id": d.DriveId, "drive_id": d.DriveId,
"file_id": file.GetID(), "file_id": file.GetID(),
"expire_sec": 14400,
}) })
}) })
if err != nil { if err != nil {

View File

@@ -44,7 +44,7 @@ func (d *AliyundriveOpen) refreshToken() error {
return nil return nil
} }
func (d *AliyundriveOpen) request(uri, method string, callback base.ReqCallback) ([]byte, error) { func (d *AliyundriveOpen) request(uri, method string, callback base.ReqCallback, retry ...bool) ([]byte, error) {
req := base.RestyClient.R() req := base.RestyClient.R()
// TODO check whether access_token is expired // TODO check whether access_token is expired
req.SetHeader("Authorization", "Bearer "+d.AccessToken) req.SetHeader("Authorization", "Bearer "+d.AccessToken)
@@ -60,7 +60,15 @@ func (d *AliyundriveOpen) request(uri, method string, callback base.ReqCallback)
if err != nil { if err != nil {
return nil, err return nil, err
} }
isRetry := len(retry) > 0 && retry[0]
if e.Code != "" { if e.Code != "" {
if !isRetry && e.Code == "AccessTokenInvalid" {
err = d.refreshToken()
if err != nil {
return nil, err
}
return d.request(uri, method, callback, true)
}
return nil, fmt.Errorf("%s:%s", e.Code, e.Message) return nil, fmt.Errorf("%s:%s", e.Code, e.Message)
} }
return res.Body(), nil return res.Body(), nil