Skip to content

Commit

Permalink
Updated to v1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
tanaikech committed Dec 12, 2018
1 parent 349b502 commit a972d8a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ $ go get -u github.com/tanaikech/go-getfilelist
| Do(*http.Client) | Retrieve file list with folder structure from a folder |
| Folder(string) | Set folder ID. |
| Fields(string) | Set fields of files.list of Drive API. |
| MimeType([]string) | Set mimeType of files.list of Drive API. By this, you can retrieve files with the mimeType. |

# Usage
There are 3 patterns for using this library.
Expand Down Expand Up @@ -78,7 +79,7 @@ func main() {
}
// When you want to retrieve the file list in the folder,
res, err := getfilelist.Folder(folderID).Fields("files(name,id)").Do(client)
res, err := getfilelist.Folder(folderID).Fields("files(name,id)").MimeType([]string{"application/pdf", "image/png"}).Do(client)
// When you want to retrieve only folder tree in the folder,
res, err := getfilelist.Folder(folderID).GetFolderTree(client)
Expand Down Expand Up @@ -466,4 +467,9 @@ If you have any questions and commissions for me, feel free to tell me.
- By this, when the values are retrieved from this library, users can use the structure of ``drive.File``.
- Script using this library can be seen at [goodls](https://github.com/tanaikech/goodls).

* v1.0.2 (December 12, 2018)

1. New method for selecting mimeType was added. When this method is used, files with the specific mimeType in the specific folder can be retrieved.


[TOP](#TOP)
30 changes: 24 additions & 6 deletions getfilelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ const (

// BaseInfo : Base information
type BaseInfo struct {
Client *http.Client
CustomFields string
FolderID string
SearchFolder *drive.File
Srv *drive.Service
Client *http.Client
CustomFields string
FolderID string
InputtedMimeType []string
SearchFolder *drive.File
Srv *drive.Service
}

// FileListDl : Retrieved file list.
Expand Down Expand Up @@ -86,8 +87,19 @@ func (b *BaseInfo) getFilesFromFolder(FolderTree *FolderTree) *FileListDl {
}
return b.CustomFields
}()
var mType string
if len(b.InputtedMimeType) > 0 {
for i, e := range b.InputtedMimeType {
if i == 0 {
mType = " and (mimeType='" + e + "'"
continue
}
mType += " or mimeType='" + e + "'"
}
mType += ")"
}
for i, id := range FolderTree.Folders {
q := "'" + id + "' in parents and mimeType != 'application/vnd.google-apps.folder' and trashed=false"
q := "'" + id + "' in parents and mimeType != 'application/vnd.google-apps.folder' and trashed=false" + mType
fm, err := b.getListLoop(q, fields)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
Expand Down Expand Up @@ -271,6 +283,12 @@ func Folder(folderID string) *BaseInfo {
return b
}

// MimeType : Set mimeType
func (b *BaseInfo) MimeType(mimeType []string) *BaseInfo {
b.InputtedMimeType = mimeType
return b
}

// GetFolderTree : Retrieve only folder tree under the specific folder.
func (b *BaseInfo) GetFolderTree(client *http.Client) (*FolderTree, error) {
b.Client = client
Expand Down

0 comments on commit a972d8a

Please sign in to comment.