mirror of https://github.com/Xhofe/alist
chore: Merge pull request #1079 from foxxorcat/dev
commit
279111a8e2
|
@ -448,6 +448,7 @@ func (driver Cloud139) Upload(file *model.FileStream, account *model.Account) er
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Debugf("%+v", res)
|
log.Debugf("%+v", res)
|
||||||
|
res.Body.Close()
|
||||||
start += byteSize
|
start += byteSize
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -577,6 +577,7 @@ func (driver Cloud189) NewUpload(file *model.FileStream, account *model.Account)
|
||||||
|
|
||||||
r, err := base.HttpClient.Do(req)
|
r, err := base.HttpClient.Do(req)
|
||||||
log.Debugf("%+v %+v", r, r.Request.Header)
|
log.Debugf("%+v %+v", r, r.Request.Header)
|
||||||
|
r.Body.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -619,8 +619,10 @@ func (driver Cloud189) CommonUpload(file *model.FileStream, parentFile *model.Fi
|
||||||
}
|
}
|
||||||
if r.StatusCode != http.StatusOK {
|
if r.StatusCode != http.StatusOK {
|
||||||
data, _ := io.ReadAll(r.Body)
|
data, _ := io.ReadAll(r.Body)
|
||||||
|
r.Body.Close()
|
||||||
return fmt.Errorf(string(data))
|
return fmt.Errorf(string(data))
|
||||||
}
|
}
|
||||||
|
r.Body.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
fileMd5Hex := strings.ToUpper(hex.EncodeToString(fileMd5.Sum(nil)))
|
fileMd5Hex := strings.ToUpper(hex.EncodeToString(fileMd5.Sum(nil)))
|
||||||
|
@ -727,8 +729,10 @@ func (driver Cloud189) FastUpload(file *model.FileStream, parentFile *model.File
|
||||||
}
|
}
|
||||||
if r.StatusCode != http.StatusOK {
|
if r.StatusCode != http.StatusOK {
|
||||||
data, _ := io.ReadAll(r.Body)
|
data, _ := io.ReadAll(r.Body)
|
||||||
|
r.Body.Close()
|
||||||
return fmt.Errorf(string(data))
|
return fmt.Errorf(string(data))
|
||||||
}
|
}
|
||||||
|
r.Body.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -424,10 +424,17 @@ func (driver AliDrive) Upload(file *model.FileStream, account *model.Account) er
|
||||||
}
|
}
|
||||||
|
|
||||||
if account.Bool1 {
|
if account.Bool1 {
|
||||||
buf := make([]byte, 1024)
|
buf := bytes.NewBuffer(make([]byte, 0, 1024))
|
||||||
n, _ := file.Read(buf[:])
|
io.CopyN(buf, file, 1024)
|
||||||
reqBody["pre_hash"] = utils.GetSHA1Encode(string(buf[:n]))
|
reqBody["pre_hash"] = utils.GetSHA1Encode(buf.String())
|
||||||
file.File = io.NopCloser(io.MultiReader(bytes.NewReader(buf[:n]), file.File))
|
// 把头部拼接回去
|
||||||
|
file.File = struct {
|
||||||
|
io.Reader
|
||||||
|
io.Closer
|
||||||
|
}{
|
||||||
|
Reader: io.MultiReader(buf, file.File),
|
||||||
|
Closer: file.File,
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
reqBody["content_hash_name"] = "none"
|
reqBody["content_hash_name"] = "none"
|
||||||
reqBody["proof_version"] = "v1"
|
reqBody["proof_version"] = "v1"
|
||||||
|
@ -454,7 +461,7 @@ func (driver AliDrive) Upload(file *model.FileStream, account *model.Account) er
|
||||||
return fmt.Errorf("%s", e.Message)
|
return fmt.Errorf("%s", e.Message)
|
||||||
}
|
}
|
||||||
|
|
||||||
if e.Code == "PreHashMatched" && account.Bool1 {
|
if account.Bool1 && e.Code == "PreHashMatched" {
|
||||||
tempFile, err := ioutil.TempFile(conf.Conf.TempDir, "file-*")
|
tempFile, err := ioutil.TempFile(conf.Conf.TempDir, "file-*")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -499,6 +506,7 @@ func (driver AliDrive) Upload(file *model.FileStream, account *model.Account) er
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 秒传失败
|
||||||
if _, err = tempFile.Seek(0, io.SeekStart); err != nil {
|
if _, err = tempFile.Seek(0, io.SeekStart); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -515,6 +523,7 @@ func (driver AliDrive) Upload(file *model.FileStream, account *model.Account) er
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Debugf("%+v", res)
|
log.Debugf("%+v", res)
|
||||||
|
res.Body.Close()
|
||||||
//res, err := base.BaseClient.R().
|
//res, err := base.BaseClient.R().
|
||||||
// SetHeader("Content-Type","").
|
// SetHeader("Content-Type","").
|
||||||
// SetBody(byteData).Put(resp.PartInfoList[i].UploadUrl)
|
// SetBody(byteData).Put(resp.PartInfoList[i].UploadUrl)
|
||||||
|
|
|
@ -87,7 +87,7 @@ func (driver Baidu) GetAllFile(account *model.Account) (files []File, err error)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
var resp FileListResp
|
var resp FileListResp
|
||||||
_, err = driver.Request(http.MethodGet, FILE_API_URL+"/list", func(r *resty.Request) {
|
_, err = driver.Request(http.MethodGet, FILE_API_URL_V1+"/list", func(r *resty.Request) {
|
||||||
r.SetQueryParams(map[string]string{
|
r.SetQueryParams(map[string]string{
|
||||||
"need_thumbnail": "1",
|
"need_thumbnail": "1",
|
||||||
"need_filter_hidden": "0",
|
"need_filter_hidden": "0",
|
||||||
|
|
|
@ -43,6 +43,14 @@ func (driver Baidu) Items() []base.Item {
|
||||||
Label: "album_id",
|
Label: "album_id",
|
||||||
Type: base.TypeString,
|
Type: base.TypeString,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "internal_type",
|
||||||
|
Label: "download api",
|
||||||
|
Type: base.TypeSelect,
|
||||||
|
Required: true,
|
||||||
|
Values: "file,album",
|
||||||
|
Default: "album",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "client_id",
|
Name: "client_id",
|
||||||
Label: "client id",
|
Label: "client id",
|
||||||
|
@ -156,6 +164,13 @@ func (driver Baidu) Files(path string, account *model.Account) ([]model.File, er
|
||||||
}
|
}
|
||||||
|
|
||||||
func (driver Baidu) Link(args base.Args, account *model.Account) (*base.Link, error) {
|
func (driver Baidu) Link(args base.Args, account *model.Account) (*base.Link, error) {
|
||||||
|
if account.InternalType == "file" {
|
||||||
|
return driver.LinkFile(args, account)
|
||||||
|
}
|
||||||
|
return driver.LinkAlbum(args, account)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (driver Baidu) LinkAlbum(args base.Args, account *model.Account) (*base.Link, error) {
|
||||||
file, err := driver.File(args.Path, account)
|
file, err := driver.File(args.Path, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -190,6 +205,42 @@ func (driver Baidu) Link(args base.Args, account *model.Account) (*base.Link, er
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (driver Baidu) LinkFile(args base.Args, account *model.Account) (*base.Link, error) {
|
||||||
|
file, err := driver.File(args.Path, account)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !IsAlbumFile(file) {
|
||||||
|
return nil, base.ErrNotSupport
|
||||||
|
}
|
||||||
|
|
||||||
|
album, err := driver.File(utils.Dir(utils.ParsePath(args.Path)), account)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// 拷贝到根目录
|
||||||
|
cfile, err := driver.CopyAlbumFile(album.Id, account, file.Id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := driver.Request(http.MethodGet, FILE_API_URL_V2+"/download", func(r *resty.Request) {
|
||||||
|
r.SetQueryParams(map[string]string{
|
||||||
|
"fsid": fmt.Sprint(cfile.Fsid),
|
||||||
|
})
|
||||||
|
}, account)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &base.Link{
|
||||||
|
Headers: []base.Header{
|
||||||
|
{Name: "User-Agent", Value: base.UserAgent},
|
||||||
|
},
|
||||||
|
Url: utils.Json.Get(res.Body(), "dlink").ToString(),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (driver Baidu) Path(path string, account *model.Account) (*model.File, []model.File, error) {
|
func (driver Baidu) Path(path string, account *model.Account) (*model.File, []model.File, error) {
|
||||||
path = utils.ParsePath(path)
|
path = utils.ParsePath(path)
|
||||||
file, err := driver.File(path, account)
|
file, err := driver.File(path, account)
|
||||||
|
@ -402,7 +453,7 @@ func (driver Baidu) Upload(file *model.FileStream, account *model.Account) error
|
||||||
|
|
||||||
// 预上传
|
// 预上传
|
||||||
var precreateResp PrecreateResp
|
var precreateResp PrecreateResp
|
||||||
_, err = driver.Request(http.MethodPost, FILE_API_URL+"/precreate", func(r *resty.Request) {
|
_, err = driver.Request(http.MethodPost, FILE_API_URL_V1+"/precreate", func(r *resty.Request) {
|
||||||
r.SetFormData(params)
|
r.SetFormData(params)
|
||||||
r.SetResult(&precreateResp)
|
r.SetResult(&precreateResp)
|
||||||
}, account)
|
}, account)
|
||||||
|
@ -431,7 +482,7 @@ func (driver Baidu) Upload(file *model.FileStream, account *model.Account) error
|
||||||
fallthrough
|
fallthrough
|
||||||
case 2: // 创建文件
|
case 2: // 创建文件
|
||||||
params["uploadid"] = precreateResp.UploadID
|
params["uploadid"] = precreateResp.UploadID
|
||||||
_, err = driver.Request(http.MethodPost, FILE_API_URL+"/create", func(r *resty.Request) {
|
_, err = driver.Request(http.MethodPost, FILE_API_URL_V1+"/create", func(r *resty.Request) {
|
||||||
r.SetFormData(params)
|
r.SetFormData(params)
|
||||||
r.SetResult(&precreateResp)
|
r.SetResult(&precreateResp)
|
||||||
}, account)
|
}, account)
|
||||||
|
|
|
@ -97,7 +97,7 @@ type (
|
||||||
type (
|
type (
|
||||||
UploadFile struct {
|
UploadFile struct {
|
||||||
FsID int64 `json:"fs_id"`
|
FsID int64 `json:"fs_id"`
|
||||||
Size int `json:"size"`
|
Size int64 `json:"size"`
|
||||||
Md5 string `json:"md5"`
|
Md5 string `json:"md5"`
|
||||||
ServerFilename string `json:"server_filename"`
|
ServerFilename string `json:"server_filename"`
|
||||||
Path string `json:"path"`
|
Path string `json:"path"`
|
||||||
|
|
|
@ -13,9 +13,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
API_URL = "https://photo.baidu.com/youai"
|
API_URL = "https://photo.baidu.com/youai"
|
||||||
ALBUM_API_URL = API_URL + "/album/v1"
|
ALBUM_API_URL = API_URL + "/album/v1"
|
||||||
FILE_API_URL = API_URL + "/file/v1"
|
FILE_API_URL_V1 = API_URL + "/file/v1"
|
||||||
|
FILE_API_URL_V2 = API_URL + "/file/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -307,8 +307,10 @@ func (driver Onedrive) UploadBig(file *model.FileStream, account *model.Account)
|
||||||
res, err := base.HttpClient.Do(req)
|
res, err := base.HttpClient.Do(req)
|
||||||
if res.StatusCode != 201 && res.StatusCode != 202 {
|
if res.StatusCode != 201 && res.StatusCode != 202 {
|
||||||
data, _ := ioutil.ReadAll(res.Body)
|
data, _ := ioutil.ReadAll(res.Body)
|
||||||
|
res.Body.Close()
|
||||||
return errors.New(string(data))
|
return errors.New(string(data))
|
||||||
}
|
}
|
||||||
|
res.Body.Close()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,7 +105,7 @@ func (driver XunLeiCloud) Items() []base.Item {
|
||||||
Label: "device id",
|
Label: "device id",
|
||||||
Default: utils.GetMD5Encode(uuid.NewString()),
|
Default: utils.GetMD5Encode(uuid.NewString()),
|
||||||
Type: base.TypeString,
|
Type: base.TypeString,
|
||||||
Required: false,
|
Required: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,8 +118,10 @@ func (driver XunLeiCloud) Save(account *model.Account, old *model.Account) error
|
||||||
client := GetClient(account)
|
client := GetClient(account)
|
||||||
// 指定验证通过的captchaToken
|
// 指定验证通过的captchaToken
|
||||||
if client.captchaToken != "" {
|
if client.captchaToken != "" {
|
||||||
|
client.Lock()
|
||||||
client.captchaToken = account.CaptchaToken
|
client.captchaToken = account.CaptchaToken
|
||||||
account.CaptchaToken = ""
|
account.CaptchaToken = ""
|
||||||
|
client.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
if client.token == "" {
|
if client.token == "" {
|
||||||
|
|
|
@ -73,6 +73,8 @@ func (c *Client) requestCaptchaToken(action string, meta map[string]string) erro
|
||||||
SetBody(¶m).
|
SetBody(¶m).
|
||||||
SetError(&e).
|
SetError(&e).
|
||||||
SetResult(&resp).
|
SetResult(&resp).
|
||||||
|
SetHeader("X-Device-Id", c.deviceID).
|
||||||
|
SetQueryParam("client_id", c.clientID).
|
||||||
Post(XLUSER_API_URL + "/shield/captcha/init")
|
Post(XLUSER_API_URL + "/shield/captcha/init")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -133,6 +135,8 @@ func (c *Client) Login(account *model.Account) (err error) {
|
||||||
Username: account.Username,
|
Username: account.Username,
|
||||||
Password: account.Password,
|
Password: account.Password,
|
||||||
}).
|
}).
|
||||||
|
SetHeader("X-Device-Id", c.deviceID).
|
||||||
|
SetQueryParam("client_id", c.clientID).
|
||||||
Post(url)
|
Post(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -184,6 +188,8 @@ func (c *Client) RefreshToken() error {
|
||||||
"client_id": c.clientID,
|
"client_id": c.clientID,
|
||||||
"client_secret": c.clientSecret,
|
"client_secret": c.clientSecret,
|
||||||
}).
|
}).
|
||||||
|
SetHeader("X-Device-Id", c.deviceID).
|
||||||
|
SetQueryParam("client_id", c.clientID).
|
||||||
Post(XLUSER_API_URL + "/auth/token")
|
Post(XLUSER_API_URL + "/auth/token")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -211,7 +217,8 @@ func (c *Client) Request(method string, url string, callback func(*resty.Request
|
||||||
"X-Captcha-Token": c.captchaToken,
|
"X-Captcha-Token": c.captchaToken,
|
||||||
"User-Agent": c.userAgent,
|
"User-Agent": c.userAgent,
|
||||||
"client_id": c.clientID,
|
"client_id": c.clientID,
|
||||||
}).SetQueryParam("client_id", c.clientID)
|
}).
|
||||||
|
SetQueryParam("client_id", c.clientID)
|
||||||
if callback != nil {
|
if callback != nil {
|
||||||
callback(req)
|
callback(req)
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,7 +213,8 @@ func (driver Yandex) Upload(file *model.FileStream, account *model.Account) erro
|
||||||
}
|
}
|
||||||
req.Header.Set("Content-Length", strconv.FormatUint(file.Size, 10))
|
req.Header.Set("Content-Length", strconv.FormatUint(file.Size, 10))
|
||||||
req.Header.Set("Content-Type", "application/octet-stream")
|
req.Header.Set("Content-Type", "application/octet-stream")
|
||||||
_, err = base.HttpClient.Do(req)
|
res, err := base.HttpClient.Do(req)
|
||||||
|
res.Body.Close()
|
||||||
//res, err := base.RestyClient.R().
|
//res, err := base.RestyClient.R().
|
||||||
// SetHeader("Content-Length", strconv.FormatUint(file.Size, 10)).
|
// SetHeader("Content-Length", strconv.FormatUint(file.Size, 10)).
|
||||||
// SetBody(file).Put(resp.Href)
|
// SetBody(file).Put(resp.Href)
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/fs"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"net/http/pprof"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/Xhofe/alist/conf"
|
"github.com/Xhofe/alist/conf"
|
||||||
"github.com/Xhofe/alist/public"
|
"github.com/Xhofe/alist/public"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"io/fs"
|
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitIndex() {
|
func InitIndex() {
|
||||||
|
@ -48,6 +50,8 @@ func Static(r *gin.Engine) {
|
||||||
c.Status(200)
|
c.Status(200)
|
||||||
if strings.HasPrefix(c.Request.URL.Path, "/@manage") {
|
if strings.HasPrefix(c.Request.URL.Path, "/@manage") {
|
||||||
_, _ = c.Writer.WriteString(conf.ManageHtml)
|
_, _ = c.Writer.WriteString(conf.ManageHtml)
|
||||||
|
} else if strings.HasPrefix(c.Request.URL.Path, "/debug/pprof") {
|
||||||
|
pprof.Index(c.Writer, c.Request)
|
||||||
} else {
|
} else {
|
||||||
_, _ = c.Writer.WriteString(conf.IndexHtml)
|
_, _ = c.Writer.WriteString(conf.IndexHtml)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue