add support list mimetype
This commit is contained in:
parent
51b3e634ab
commit
ee6b77b4fa
|
@ -45,18 +45,23 @@ func NewGoogleDrive(apiKey string) (*GoogleDrive, error) {
|
||||||
return &ggdrive, nil
|
return &ggdrive, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g GoogleDrive) GetFilesByFolderID(folderID string) ([]GoogleDriveFile, error) {
|
func (g GoogleDrive) GetFilesByFolderID(folderID string, mimeType []string) ([]GoogleDriveFile, error) {
|
||||||
var (
|
var (
|
||||||
result = make([]GoogleDriveFile, 0)
|
result = make([]GoogleDriveFile, 0)
|
||||||
)
|
)
|
||||||
|
|
||||||
res, err := getfilelist.Folder(folderID).Fields("files(name,id)").Do(g.svc)
|
chain := getfilelist.Folder(folderID).Fields("files(id,name)")
|
||||||
|
if len(mimeType) > 0 {
|
||||||
|
chain.MimeType(mimeType)
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := chain.Do(g.svc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("error when fetch folder %s: %s", folderID, err.Error())
|
err := fmt.Errorf("error when fetch folder %s: %s", folderID, err.Error())
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// if there is more than 1 subfolder
|
// if there is more than 1 sub folder
|
||||||
if len(res.FileList) != 1 {
|
if len(res.FileList) != 1 {
|
||||||
err := fmt.Errorf("folder %s have more than 1 subfolder", folderID)
|
err := fmt.Errorf("folder %s have more than 1 subfolder", folderID)
|
||||||
return result, err
|
return result, err
|
||||||
|
|
Loading…
Reference in New Issue