gdrive

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2023 License: GPL-3.0 Imports: 22 Imported by: 1

Documentation

Index

Constants

View Source
const (
	HTTP3_SUPPORTED        = true
	GDRIVE_ERROR_FILENAME  = "gdrive_download.log"
	BASE_API_KEY_REGEX_STR = `AIza[\w-]{35}`

	// file fields to fetch from GDrive API:
	// https://developers.google.com/drive/api/v3/reference/files
	GDRIVE_FILE_FIELDS   = "id,name,size,mimeType,md5Checksum"
	GDRIVE_FOLDER_FIELDS = "nextPageToken,files(id,name,size,mimeType,md5Checksum)"
)

Variables

View Source
var (
	API_KEY_REGEX       = regexp.MustCompile(fmt.Sprintf(`^%s$`, BASE_API_KEY_REGEX_STR))
	API_KEY_PARAM_REGEX = regexp.MustCompile(fmt.Sprintf(`key=%s`, BASE_API_KEY_REGEX_STR))
)

Functions

func GetFileIdAndTypeFromUrl

func GetFileIdAndTypeFromUrl(url string) (string, string)

Uses regex to extract the file ID and the file type (type: file, folder) from the given URL

func ProcessPostText

func ProcessPostText(postBodyStr, postFolderPath string, downloadGdrive bool, logUrls bool) []*httpfuncs.ToDownload

Process and detects for any external download links from the post's text content

Types

type GDrive

type GDrive struct {
	Ctx context.Context
	// contains filtered or unexported fields
}

func (*GDrive) DownloadFile

func (gdrive *GDrive) DownloadFile(fileInfo *GdriveFileToDl, filePath string, config *configs.Config, queue chan struct{}) error

Downloads the given GDrive file using GDrive API v3

If the md5Checksum has a mismatch, the file will be overwritten and downloaded again Downloads the given GDrive file using GDrive API v3

If the md5Checksum has a mismatch, the file will be overwritten and downloaded again

func (*GDrive) DownloadGdriveUrls

func (gdrive *GDrive) DownloadGdriveUrls(gdriveUrls []*httpfuncs.ToDownload, config *configs.Config, apiProg progress.Progress, dlProg progress.Progress) error

Downloads multiple GDrive files based on a slice of GDrive URL strings in parallel

func (*GDrive) DownloadMultipleFiles

func (gdrive *GDrive) DownloadMultipleFiles(files []*GdriveFileToDl, config *configs.Config, prog progress.Progress)

Downloads the multiple GDrive file in parallel using GDrive API v3

func (*GDrive) GDriveKeyIsValid

func (gdrive *GDrive) GDriveKeyIsValid(userAgent string) (bool, error)

Checks if the given Google Drive API key is valid

Will return true if the given Google Drive API key is valid

func (*GDrive) GetFileDetails

func (gdrive *GDrive) GetFileDetails(gdriveInfo *GDriveToDl, config *configs.Config) (*GdriveFileToDl, error)

Retrieves the file details of the given GDrive file using GDrive API v3

func (*GDrive) GetFolderContents

func (gdrive *GDrive) GetFolderContents(folderId, logPath string, config *configs.Config) ([]*GdriveFileToDl, error)

Returns the contents of the given GDrive folder

func (*GDrive) GetNestedFolderContents

func (gdrive *GDrive) GetNestedFolderContents(folderId, logPath string, config *configs.Config) ([]*GdriveFileToDl, error)

Retrieves the content of a GDrive folder and its subfolders recursively using GDrive API v3

func (*GDrive) SetApiKey

func (gdrive *GDrive) SetApiKey(apiKey string)

func (*GDrive) SetApiUrl added in v1.0.2

func (gdrive *GDrive) SetApiUrl(apiUrl string)

func (*GDrive) SetClient

func (gdrive *GDrive) SetClient(client *drive.Service)

func (*GDrive) SetContext

func (gdrive *GDrive) SetContext(ctx context.Context)

func (*GDrive) SetDownloadTimeout

func (gdrive *GDrive) SetDownloadTimeout(downloadTimeout int)

func (*GDrive) SetMaxDownloadWorkers

func (gdrive *GDrive) SetMaxDownloadWorkers(maxDownloadWorkers int)

func (*GDrive) SetTimeout

func (gdrive *GDrive) SetTimeout(timeout int)

type GDriveFile

type GDriveFile struct {
	Kind        string `json:"kind"`
	Id          string `json:"id"`
	Name        string `json:"name"`
	Size        string `json:"size"`
	MimeType    string `json:"mimeType"`
	Md5Checksum string `json:"md5Checksum"`
}

type GDriveFolder

type GDriveFolder struct {
	Kind             string       `json:"kind"`
	IncompleteSearch bool         `json:"incompleteSearch"`
	Files            []GDriveFile `json:"files"`
	NextPageToken    string       `json:"nextPageToken"`
}

type GDriveToDl

type GDriveToDl struct {
	Id       string
	Type     string
	FilePath string
}

type GdriveError

type GdriveError struct {
	Err      error
	FilePath string
}

type GdriveFileToDl

type GdriveFileToDl struct {
	Id          string
	Name        string
	Size        string
	MimeType    string
	Md5Checksum string
	FilePath    string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL