30 lines
960 B
Go
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
|
|
}
|