DriveLoader Logo
DriveLoaderv1.2.0

API Reference

Complete TypeScript API documentation for components, hooks, core resolution utilities, and error classes.

React Components

<DriveImage />

React.ForwardRefExoticComponent<DriveImageProps>

Renders Google Drive images with automatic endpoint failover, skeleton placeholders, fade-in animations, and lazy loading.

Prop / KeyTypeDefaultDescription
srcstringGoogle Drive share link or File ID
altstring''Image alt description text
widthnumber | stringautoImage width
heightnumber | stringautoImage height
fadebooleantrueEnable CSS opacity fade-in transition
lazybooleantrueEnable IntersectionObserver lazy loading
placeholderReactNodeSkeletonCustom React node during resolution
fallbackReactNodeFallback UICustom React node if resolution fails
onResolveSuccess(result: ResolveResult) => voidCallback when DriveLoader resolves URL

<DriveVideo />

React.ForwardRefExoticComponent<DriveVideoProps>

Streams Google Drive video files with HTML5 controls, poster thumbnails, metadata extraction, and lazy loading.

Prop / KeyTypeDefaultDescription
srcstringGoogle Drive video share link or File ID
controlsbooleantrueShow native HTML5 playback controls
autoPlaybooleanfalseAuto play video stream
mutedbooleanfalseMute video audio
loopbooleanfalseLoop playback
posterstringThumbnail URLPoster preview image URL
preload'metadata' | 'auto' | 'none''metadata'Video preload strategy
onLoadedMetadata(e, metadata?: DriveVideoMetadata) => voidCallback when video metadata is loaded

<DriveGallery />

React.FC<DriveGalleryProps>

Responsive grid layout for displaying collections of images and videos, or entire public Google Drive folders.

Prop / KeyTypeDefaultDescription
imagesArray<string | DriveGalleryItem>Array of media URLs or objects
folderUrlstringPublic Google Drive folder share link
apiKeystringPublic Google Drive API Key for folder loading
columnsnumber | { sm?: number, md?: number, lg?: number }3Responsive column grid counts
gapnumber | string'1rem'Grid gap spacing
mediaTypes('image' | 'video')[]['image','video']Filter media types from folder

React Hooks

useDriveImage(src, options?)

(src: string, options?: ResolveOptions) => UseDriveImageResult

Custom hook for stateful image resolution with candidate endpoints and reload callbacks.

Prop / KeyTypeDefaultDescription
imageUrlstring | nullnullWorking direct CDN image URL
loadingbooleantrueTrue while resolving
errorError | nullnullError object if resolution fails
reload(options?: { bypassCache?: boolean }) => voidFunction to reload resolution

useDriveVideo(src, options?)

(src: string, options?: ResolveOptions) => UseDriveVideoResult

Custom hook for video resolution and metadata extraction (duration, width, height, mimeType).

Prop / KeyTypeDefaultDescription
videoUrlstring | nullnullWorking direct CDN video stream URL
metadataDriveVideoMetadata | nullnullVideo duration, width, height, size, mimeType
thumbnailUrlstring | nullnullPreview thumbnail image URL

useDriveFolder(options)

(options: LoadFolderOptions) => UseDriveFolderResult

Hook for fetching and paginating public Google Drive folder assets.

Prop / KeyTypeDefaultDescription
assetsDriveAsset[][]Accumulated media assets
loadMore() => voidFunction to fetch next page
hasMorebooleanfalseTrue if additional pages exist

Core Utilities & Functions

resolveDriveImage(src, options?)

(src: string, options?: ResolveOptions) => Promise<ResolveResult>

Resolves any Google Drive image URL or File ID into a direct working CDN link with endpoint learning and caching.

resolveDriveVideo(src, options?)

(src: string, options?: ResolveOptions) => Promise<ResolveVideoResult>

Resolves any Google Drive video URL or File ID into a direct CDN streaming link and extracts video metadata.

resolveDriveImages(urls, options?)

(urls: string[], options?: BatchResolveOptions) => Promise<BatchResolveResult>

Concurrently resolves multiple URLs with worker queue concurrency controls.

isDriveVideo(urlOrId)

(urlOrId: string) => boolean

Checks whether an input string or link represents a video asset.

getVideoThumbnail(src, options?)

(src: string, options?: { width?: number }) => string

Generates or retrieves direct preview thumbnail URLs for Google Drive videos.

extractVideoMetadata(src, options?)

(src: string, options?: ResolveOptions) => Promise<DriveVideoMetadata>

Extracts video duration, width, height, MIME type, and file size.

analyzeDriveUrl(urlOrId)

(urlOrId: string) => UrlDiagnostics

Analyzes link validity, format variants, TTL, and actionable recommendations.

Error Hierarchy

DriveLoaderError

extends Error

Base custom error class for all @driveloader/react errors.

InvalidDriveUrlError

extends DriveLoaderError

Thrown when input string is not a valid Google Drive URL or File ID.

InvalidVideoError

extends DriveLoaderError

Thrown when input video URL or ID is invalid.

VideoResolutionError

extends DriveLoaderError

Thrown when video resolution fails across candidate endpoints.

UnsupportedVideoFormatError

extends DriveLoaderError

Thrown when video format is unsupported by HTML5 video player.

PrivateFileError

extends DriveLoaderError

Thrown when file access is private or restricted.