From ee6b77b4fa2b1622efb0f3b47bb78931a6278435 Mon Sep 17 00:00:00 2001 From: namhq1989 Date: Wed, 30 Nov 2022 11:09:43 +0700 Subject: [PATCH] add support list mimetype --- google_drive.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/google_drive.go b/google_drive.go index 7ae517a..28f19c6 100644 --- a/google_drive.go +++ b/google_drive.go @@ -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