mirror of https://github.com/Xhofe/alist
commit
79c9b6ac77
|
@ -3,14 +3,15 @@ package _23
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/Xhofe/alist/drivers/base"
|
"github.com/Xhofe/alist/drivers/base"
|
||||||
"github.com/Xhofe/alist/model"
|
"github.com/Xhofe/alist/model"
|
||||||
"github.com/Xhofe/alist/utils"
|
"github.com/Xhofe/alist/utils"
|
||||||
"github.com/go-resty/resty/v2"
|
"github.com/go-resty/resty/v2"
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (driver Pan123) Login(account *model.Account) error {
|
func (driver Pan123) Login(account *model.Account) error {
|
||||||
|
@ -46,6 +47,7 @@ func (driver Pan123) FormatFile(file *File) *model.File {
|
||||||
Size: file.Size,
|
Size: file.Size,
|
||||||
Driver: driver.Config().Name,
|
Driver: driver.Config().Name,
|
||||||
UpdatedAt: file.UpdateAt,
|
UpdatedAt: file.UpdateAt,
|
||||||
|
Thumbnail: file.DownloadUrl,
|
||||||
}
|
}
|
||||||
f.Type = file.GetType()
|
f.Type = file.GetType()
|
||||||
return f
|
return f
|
||||||
|
@ -65,7 +67,7 @@ func (driver Pan123) GetFiles(parentId string, account *model.Account) ([]File,
|
||||||
"parentFileId": parentId,
|
"parentFileId": parentId,
|
||||||
"trashed": "false",
|
"trashed": "false",
|
||||||
}
|
}
|
||||||
_, err := driver.Request("https://www.123pan.com/api/file/list",
|
_, err := driver.Request("https://www.123pan.com/api/file/list/new",
|
||||||
base.Get, nil, query, nil, &resp, false, account)
|
base.Get, nil, query, nil, &resp, false, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -4,6 +4,13 @@ import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/Xhofe/alist/conf"
|
"github.com/Xhofe/alist/conf"
|
||||||
"github.com/Xhofe/alist/drivers/base"
|
"github.com/Xhofe/alist/drivers/base"
|
||||||
"github.com/Xhofe/alist/model"
|
"github.com/Xhofe/alist/model"
|
||||||
|
@ -13,12 +20,6 @@ import (
|
||||||
"github.com/aws/aws-sdk-go/aws/session"
|
"github.com/aws/aws-sdk-go/aws/session"
|
||||||
"github.com/aws/aws-sdk-go/service/s3/s3manager"
|
"github.com/aws/aws-sdk-go/service/s3/s3manager"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"net/url"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Pan123 struct{}
|
type Pan123 struct{}
|
||||||
|
@ -125,7 +126,7 @@ func (driver Pan123) Files(path string, account *model.Account) ([]model.File, e
|
||||||
_ = base.SetCache(path, rawFiles, account)
|
_ = base.SetCache(path, rawFiles, account)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
files := make([]model.File, 0)
|
files := make([]model.File, 0, len(rawFiles))
|
||||||
for _, file := range rawFiles {
|
for _, file := range rawFiles {
|
||||||
files = append(files, *driver.FormatFile(&file))
|
files = append(files, *driver.FormatFile(&file))
|
||||||
}
|
}
|
||||||
|
@ -300,46 +301,36 @@ func (driver Pan123) Upload(file *model.FileStream, account *model.Account) erro
|
||||||
if !parentFile.IsDir() {
|
if !parentFile.IsDir() {
|
||||||
return base.ErrNotFolder
|
return base.ErrNotFolder
|
||||||
}
|
}
|
||||||
parentFileId, _ := strconv.Atoi(parentFile.Id)
|
|
||||||
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
|
||||||
}
|
}
|
||||||
defer func() {
|
defer tempFile.Close()
|
||||||
_ = tempFile.Close()
|
defer os.Remove(tempFile.Name())
|
||||||
_ = os.Remove(tempFile.Name())
|
|
||||||
}()
|
|
||||||
_, err = io.Copy(tempFile, file)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, err = tempFile.Seek(0, io.SeekStart)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
h := md5.New()
|
h := md5.New()
|
||||||
_, err = io.Copy(h, tempFile)
|
if _, err = io.Copy(io.MultiWriter(tempFile, h), file); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
etag := hex.EncodeToString(h.Sum(nil))
|
etag := hex.EncodeToString(h.Sum(nil))
|
||||||
log.Debugln("md5:", etag)
|
|
||||||
_, err = tempFile.Seek(0, io.SeekStart)
|
_, err = tempFile.Seek(0, io.SeekStart)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
data := base.Json{
|
data := base.Json{
|
||||||
"driveId": 0,
|
"driveId": 0,
|
||||||
"duplicate": true,
|
"duplicate": 2, // 2->覆盖 1->重命名 0->默认
|
||||||
"etag": etag,
|
"etag": etag,
|
||||||
"fileName": file.GetFileName(),
|
"fileName": file.GetFileName(),
|
||||||
"parentFileId": parentFileId,
|
"parentFileId": parentFile.Id,
|
||||||
"size": file.GetSize(),
|
"size": file.GetSize(),
|
||||||
"type": 0,
|
"type": 0,
|
||||||
}
|
}
|
||||||
var resp UploadResp
|
var resp UploadResp
|
||||||
_, err = driver.Request("https://www.123pan.com/api/file/upload_request",
|
_, err = driver.Request("https://www.123pan.com/api/file/upload_request",
|
||||||
base.Post, nil, nil, &data, &resp, false, account)
|
base.Post, map[string]string{"app-version": "1.1"}, nil, &data, &resp, false, account)
|
||||||
//res, err := driver.Post("https://www.123pan.com/api/file/upload_request", data, account)
|
//res, err := driver.Post("https://www.123pan.com/api/file/upload_request", data, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -1,20 +1,22 @@
|
||||||
package _23
|
package _23
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/Xhofe/alist/conf"
|
|
||||||
"github.com/Xhofe/alist/utils"
|
|
||||||
"path"
|
"path"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/Xhofe/alist/conf"
|
||||||
|
"github.com/Xhofe/alist/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type File struct {
|
type File struct {
|
||||||
FileName string `json:"FileName"`
|
FileName string `json:"FileName"`
|
||||||
Size int64 `json:"Size"`
|
Size int64 `json:"Size"`
|
||||||
UpdateAt *time.Time `json:"UpdateAt"`
|
UpdateAt *time.Time `json:"UpdateAt"`
|
||||||
FileId int64 `json:"FileId"`
|
FileId int64 `json:"FileId"`
|
||||||
Type int `json:"Type"`
|
Type int `json:"Type"`
|
||||||
Etag string `json:"Etag"`
|
Etag string `json:"Etag"`
|
||||||
S3KeyFlag string `json:"S3KeyFlag"`
|
S3KeyFlag string `json:"S3KeyFlag"`
|
||||||
|
DownloadUrl string `json:"DownloadUrl"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f File) GetSize() uint64 {
|
func (f File) GetSize() uint64 {
|
||||||
|
|
Loading…
Reference in New Issue