Skip to content

Commit

Permalink
modify file metas param
Browse files Browse the repository at this point in the history
  • Loading branch information
jsyzchen committed Jan 8, 2021
1 parent 98e9592 commit c9ac8b4
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
### 使用Go mod
在您的项目中的`go.mod`文件内添加这行代码
```bash
require github.com/jsyzchen/pan v0.0.1
require github.com/jsyzchen/pan v0.0.2
```
并在项目中引入`github.com/jsyzchen/pan`
```go
Expand Down
2 changes: 1 addition & 1 deletion conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type TestDataConfig struct {
TranscodingType string
}

const Version = "0.0.1"
const Version = "0.0.2"

const (
BaiduOpenApiDomain = "https://openapi.baidu.com"
Expand Down
2 changes: 1 addition & 1 deletion examples/file_metas.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ func main() {
accessToken := "122.b0a9ab31cc24b429d460cd3ce1f1af97.Yn53jGAwd_1elGgODFvYl1sp9qOYVUDRiVawin5.tbNcEw"
fileClient := file.NewFileClient(accessToken)
fsIDs := []uint64{765773701501523}
res, err := fileClient.Metas(fsIDs, 1, 0)
res, err := fileClient.Metas(fsIDs)
if err != nil {
fmt.Println("err:", err)
return
Expand Down
7 changes: 4 additions & 3 deletions file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (f *File) List(dir string, start, limit int) (ListResponse, error) {
}

// 获取文件信息
func (f *File) Metas(fsIDs []uint64, isReturnDLink, isReturnThumb int) (MetasResponse, error) {
func (f *File) Metas(fsIDs []uint64) (MetasResponse, error) {
ret := MetasResponse{}

fsIDsByte, err := json.Marshal(fsIDs)
Expand All @@ -111,8 +111,9 @@ func (f *File) Metas(fsIDs []uint64, isReturnDLink, isReturnThumb int) (MetasRes
v := url.Values{}
v.Add("access_token", f.AccessToken)
v.Add("fsids", string(fsIDsByte))
v.Add("dlink", strconv.Itoa(isReturnDLink))
v.Add("thumb", strconv.Itoa(isReturnThumb))
v.Add("dlink", "1")
v.Add("thumb", "1")
v.Add("extra", "1")
query := v.Encode()

requestUrl := conf.OpenApiDomain + MetasUri + "&" + query
Expand Down
2 changes: 1 addition & 1 deletion file/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestFile_List(t *testing.T) {

func TestFile_Metas(t *testing.T) {
fileClient := NewFileClient(conf.TestData.AccessToken)
res, err := fileClient.Metas([]uint64{conf.TestData.FsID}, 0, 0)
res, err := fileClient.Metas([]uint64{conf.TestData.FsID})
if err != nil {
t.Errorf("TestMetas failed, err:%v", err)
}
Expand Down
18 changes: 9 additions & 9 deletions utils/file/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

//FileDownloader 文件下载器
type FileDownloader struct {
type Downloader struct {
fileSize int
url string
filePath string
Expand All @@ -32,8 +32,8 @@ type filePart struct {
}

//NewFileDownloader .
func NewFileDownloader(url, filePath string, totalPart int) *FileDownloader {
return &FileDownloader{
func NewFileDownloader(url, filePath string, totalPart int) *Downloader {
return &Downloader{
fileSize: 0,
url: url,
filePath: filePath,
Expand All @@ -43,7 +43,7 @@ func NewFileDownloader(url, filePath string, totalPart int) *FileDownloader {
}

//Run 开始下载任务
func (d *FileDownloader) Download() error {
func (d *Downloader) Download() error {
if d.totalPart == 1 {
err := d.downloadWholeFile()
return err
Expand Down Expand Up @@ -97,7 +97,7 @@ func (d *FileDownloader) Download() error {
}

//head 获取要下载的文件的基本信息(header) 使用HTTP Method Head
func (d *FileDownloader) head() (bool, error) {
func (d *Downloader) head() (bool, error) {
isSupportRange := false
r, err := d.getNewRequest("HEAD")
if err != nil {
Expand Down Expand Up @@ -126,7 +126,7 @@ func (d *FileDownloader) head() (bool, error) {
}

//下载分片
func (d *FileDownloader) downloadPart(c filePart) error {
func (d *Downloader) downloadPart(c filePart) error {
r, err := d.getNewRequest("GET")
if err != nil {
return err
Expand Down Expand Up @@ -154,7 +154,7 @@ func (d *FileDownloader) downloadPart(c filePart) error {
}

//mergeFileParts 合并下载的文件
func (d *FileDownloader) mergeFileParts() error {
func (d *Downloader) mergeFileParts() error {
log.Println("开始合并文件")
mergedFile, err := os.Create(d.filePath)
if err != nil {
Expand All @@ -173,7 +173,7 @@ func (d *FileDownloader) mergeFileParts() error {
}

//直接下载整个文件
func (d *FileDownloader) downloadWholeFile() error {
func (d *Downloader) downloadWholeFile() error {
url := d.url

// Get the data
Expand All @@ -200,7 +200,7 @@ func (d *FileDownloader) downloadWholeFile() error {
}

// getNewRequest 创建一个request
func (d *FileDownloader) getNewRequest(method string) (*http.Request, error) {
func (d *Downloader) getNewRequest(method string) (*http.Request, error) {
r, err := http.NewRequest(
method,
d.url,
Expand Down

0 comments on commit c9ac8b4

Please sign in to comment.