npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@abrifq/google-drive-downloader

v1.1.0

Published

Get direct download link for a PUBLIC google drive file link. Not tested with folders.

Downloads

13

Readme

Google Drive Public File Downloader

Open Google Drive. Upload a file. Right click the file, make it viewable with anyone with a link, copy the link to your program and voilà! You can now use the file stored in Google Drive in your program/site -- with the help of this tiny library!

Usage

The library is written both as an ES6 module (index.mjs) and a CommonJS module (index.js).

import gDriveDownloader from "gdrive-downloader/index.mjs";

const links = {
    catPic: "https://drive.google.com/file/d/totes_real_cat_link/view?usp=share_link"
};

gDriveDownloader(links.catPic)
.then(fetch)
.then(rsp=>rsp.blob())
.then(showDialogWithImgBlob)
.catch(logger.error);

Notes

File Link

Make sure the link passed is at least viewable by anyone with the link. Otherwise Google Drive will just redirect downloading it since the library itself doesn't supply any credentials by default.

Errors and being outdated

On the cases the fetch fails, say, due to a network blocking, the error will escalate!

On the cases the library can't handle the response, the library will return an empty string.

Since the intended usage is directly feeding it to fetch - which throws on invalid urls like empty strings, you can just catch at the end of the promise chain.

However, if you just await it, you can use if(url.length == 0) to determine if the fetching has failed.

How it works

The library first gets the file ID from the file link, then uses it to make a download start link, and uses it to get the actual download link.

By utilizing the manual redirect mode of fetch, the library can see if the download needs a confirmation due to "virus scan fails".

If it passes the scan, Drive redirects us to the file link. Since we stop at the first redirect, the developer can choose to download the file later.

If it fails the scan, the library extracts the confirmation link from the page -- which just redirects you to the file upon requesting it.

If it fails with an unknown status code due to not existing (404 Not Found) or something else like spam (429 Too Many Requests), the library will just return an empty string and log the file ID and status code to the console.