add support list mimetype

This commit is contained in:
namhq1989 2022-11-30 11:09:43 +07:00
parent 51b3e634ab
commit ee6b77b4fa
1 changed files with 8 additions and 3 deletions

View File

@ -45,18 +45,23 @@ func NewGoogleDrive(apiKey string) (*GoogleDrive, error) {
return &ggdrive, nil
}
func (g GoogleDrive) GetFilesByFolderID(folderID string) ([]GoogleDriveFile, error) {
func (g GoogleDrive) GetFilesByFolderID(folderID string, mimeType []string) ([]GoogleDriveFile, error) {
var (
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 {
err := fmt.Errorf("error when fetch folder %s: %s", folderID, err.Error())
return result, err
}
// if there is more than 1 subfolder
// if there is more than 1 sub folder
if len(res.FileList) != 1 {
err := fmt.Errorf("folder %s have more than 1 subfolder", folderID)
return result, err