Files
houston-be/pkg/google/googleDrive/drive_interface.go
Sriram Bhargav 53da5c81b0 TP-48508 | Adding helper to download files form a google drive directory (#305)
* TP-48508 | Adding helper to download files form a google drive directory
2023-12-07 17:24:13 +05:30

30 lines
960 B
Go

package googleDrive
import (
"context"
"go.uber.org/zap"
"google.golang.org/api/drive/v3"
"google.golang.org/api/option"
"houston/internal/clients"
"houston/logger"
"net/http"
"time"
)
type DriveActions interface {
SearchInDrive(timeout time.Duration, query string) (*drive.FileList, error)
CreateDirectory(timeout time.Duration, directoryName string) (*drive.File, error)
DeleteFile(timeout time.Duration, fileId string) error
CopyFile(timeout time.Duration, fileId string, directoryId string) (*drive.File, error)
ExportFile(timeout time.Duration, fileId string, mimeType string) (*http.Response, error)
}
func NewGoogleDriveActions() (*ActionsImpl, error) {
driveService, err := drive.NewService(context.Background(), option.WithTokenSource(clients.GetGoogleTokenSource()))
if err != nil {
logger.Error("Unable to retrieve Drive client", zap.Error(err))
return nil, err
}
return &ActionsImpl{filesService: driveService.Files}, nil
}