Skip to content

Commit

Permalink
fix(terabox): missing JsToken field on request (close #5189)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Sep 8, 2023
1 parent 3504f01 commit 8e43335
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
13 changes: 7 additions & 6 deletions drivers/terabox/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import (
"crypto/md5"
"encoding/hex"
"fmt"
"github.com/alist-org/alist/v3/drivers/base"
"github.com/alist-org/alist/v3/pkg/utils"
log "github.com/sirupsen/logrus"
"io"
"math"
stdpath "path"
"strconv"
"strings"

"github.com/alist-org/alist/v3/drivers/base"
"github.com/alist-org/alist/v3/pkg/utils"
log "github.com/sirupsen/logrus"

"github.com/alist-org/alist/v3/internal/driver"
"github.com/alist-org/alist/v3/internal/model"
)
Expand Down Expand Up @@ -119,9 +120,6 @@ func (d *Terabox) Put(ctx context.Context, dstDir model.Obj, stream model.FileSt
if err != nil {
return err
}
defer func() {
_ = tempFile.Close()
}()
var Default int64 = 4 * 1024 * 1024
defaultByteData := make([]byte, Default)
count := int(math.Ceil(float64(stream.GetSize()) / float64(Default)))
Expand Down Expand Up @@ -168,6 +166,9 @@ func (d *Terabox) Put(ctx context.Context, dstDir model.Obj, stream model.FileSt
return err
}
log.Debugf("%+v", precreateResp)
if precreateResp.Errno != 0 {
return fmt.Errorf("[terabox] failed to precreate file, errno: %s", precreateResp.Errno)
}
if precreateResp.ReturnType == 2 {
return nil
}
Expand Down
1 change: 1 addition & 0 deletions drivers/terabox/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
type Addition struct {
driver.RootPath
Cookie string `json:"cookie" required:"true"`
JsToken string `json:"js_token" type:"string" required:"true"`
DownloadAPI string `json:"download_api" type:"select" options:"official,crack" default:"official"`
OrderBy string `json:"order_by" type:"select" options:"name,time,size" default:"name"`
OrderDirection string `json:"order_direction" type:"select" options:"asc,desc" default:"asc"`
Expand Down
11 changes: 7 additions & 4 deletions drivers/terabox/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ func (d *Terabox) request(furl string, method string, callback base.ReqCallback,
"User-Agent": base.UserAgent,
"X-Requested-With": "XMLHttpRequest",
})
req.SetQueryParam("app_id", "250528")
req.SetQueryParam("web", "1")
req.SetQueryParam("channel", "dubox")
req.SetQueryParam("clienttype", "0")
req.SetQueryParams(map[string]string{
"app_id": "250528",
"web": "1",
"channel": "dubox",
"clienttype": "0",
"jsToken": d.JsToken,
})
if callback != nil {
callback(req)
}
Expand Down

0 comments on commit 8e43335

Please sign in to comment.