gdrive-file-info
v1.2.0
Published
Fetch file information for publicly shared Google Drive items.
Downloads
148
Maintainers
Readme
gdrive-file-info
Fetch file information for publicly shared Google Drive items.
Instalation
$ npm install gdrive-file-info
API
Table of Contents
GDriveError
Extends Error
Custom error class used for wrapping HTTP errors
Properties
reason
Error original HTTP error
FileInfo
Type: Object
Properties
disposition
String Google Drive scan statusfileName
String item filenamedownloadUrl
String generated direct download urlscanResult
String Google Drive scan resultsizeBytes
Number file sizethumbnailUrl
function (Dimensions): Promise<String>
Dimensions
Type: Object
Properties
fetchInfo
Fetch file info for given item id
Parameters
input
String Google Drive item view/open url or item id
Examples
// fetch public video info
const info = await fetchInfo('https://drive.google.com/open?id=1ObJEVgO6Y4cFjfxszUb1LhdyeKrq_wGD');
console.log(info.downloadUrl);
//=> https://doc-00-6c-docs.googleusercontent.com/docs/securesc/…/1ObJEVgO6Y4cFjfxszUb1LhdyeKrq_wGD
// generate poster url
const thumbnailUrl = await info.thumbnailUrl({ width: 1280, height: 720 });
//=> https://lh3.googleusercontent.com/9CwZKAQJ2U0CjjcIt5iZCqd-w-0d5ClJuYHVlS4olLrzt6AZr9rCdDu4jVzrz9b-tK5aswE4vdA=w1280-h720-p
- Throws GDriveError throws on querying missing/private items
- Throws TypeError throws on invalid ID provided
Returns Promise<FileInfo> item info
getItemId
Extract item id from Google Drive shareable link
Parameters
url
String Google Drive item view/open url
Examples
// with _open_ link
const id = getItemId('https://drive.google.com/open?id=1ObJEVgO6Y4cFjfxszUb1LhdyeKrq_wGD');
//=> 1ObJEVgO6Y4cFjfxszUb1LhdyeKrq_wGD
// with _view_ link
const id = getItemId('https://drive.google.com/file/d/1ObJEVgO6Y4cFjfxszUb1LhdyeKrq_wGD/view?usp=sharing');
//=> 1ObJEVgO6Y4cFjfxszUb1LhdyeKrq_wGD
// with _edit_ link
const id = getItemId('https://docs.google.com/document/d/1OHA32KWVF21s0ahDMr8Qv2oDamQuLNoYkTN0N_RuRXA/edit');
// => 1OHA32KWVF21s0ahDMr8Qv2oDamQuLNoYkTN0N_RuRXA
Returns String item id