@ultirequiem/drive-link 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +9 -0
- package/README.md +72 -0
- package/esm/mod.js +41 -0
- package/esm/package.json +3 -0
- package/package.json +39 -0
- package/script/mod.js +45 -0
- package/script/package.json +3 -0
- package/types/mod.d.ts +18 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Eliaz Bobadilla <eliaz.bobadilladev@gmail.com> (https://ultirequiem.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Drive Link
|
|
2
|
+
|
|
3
|
+
[](https://codecov.io/gh/UltiRequiem/drive_link)
|
|
4
|
+
[](https://doc.deno.land/https/deno.land/x/drive_link/mod.ts)
|
|
5
|
+
|
|
6
|
+
Generate a [Google Drive](https://google.com/drive) direct download link based
|
|
7
|
+
on the URL or ID.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
The API is the same on all this platforms ✔️
|
|
12
|
+
|
|
13
|
+
### [Deno 🦕](https://deno.land/x/drive-link)
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
import { driveLink } from "https://deno.land/x/drive_link/mod.ts";
|
|
17
|
+
|
|
18
|
+
driveLink(
|
|
19
|
+
"https://drive.google.com/file/d/1Px8bePd7pFSz5r6bTA7GKN9HloCzMfFk/view?usp=sharing",
|
|
20
|
+
);
|
|
21
|
+
//=> 'https://drive.google.com/uc?export=download&id=1Px8bePd7pFSz5r6bTA7GKN9HloCzMfFk'
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### [Node.js 🐢🚀](https://npmjs.com/package/@ultirequiem/drive-link)
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
import { driveLink } from "@ultirequiem/drive-link";
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### [Browser 🌐](https://developer.mozilla.org/en-US/docs/Glossary/Browser)
|
|
31
|
+
|
|
32
|
+
You can use any [CDN](https://en.wikipedia.org/wiki/Content_delivery_network) 🔥
|
|
33
|
+
|
|
34
|
+
Eg 👉
|
|
35
|
+
[ESM](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) ↔️
|
|
36
|
+
[SkyPack](https://cdn.skypack.dev/@ultirequiem/drive_link) 🆚
|
|
37
|
+
[Script Tag](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script)
|
|
38
|
+
↔️ [JSDelivr](https://cdn.jsdelivr.net/npm/@ultirequiem/drive_link)
|
|
39
|
+
|
|
40
|
+
## Documentation
|
|
41
|
+
|
|
42
|
+
Is hosted on
|
|
43
|
+
[Deno Doc](https://doc.deno.land/https://deno.land/x/drive_link/mod.ts) 📄
|
|
44
|
+
|
|
45
|
+
## Support
|
|
46
|
+
|
|
47
|
+
Open an Issue, I will check it a soon as possible 👀
|
|
48
|
+
|
|
49
|
+
If you want to hurry me up a bit
|
|
50
|
+
[send me a tweet](https://twitter.com/UltiRequiem) 😆
|
|
51
|
+
|
|
52
|
+
Consider [supporting me on Patreon](https://patreon.com/UltiRequiem) if you like
|
|
53
|
+
my work 🙏
|
|
54
|
+
|
|
55
|
+
Don't forget to start the repo ⭐
|
|
56
|
+
|
|
57
|
+
## Authors
|
|
58
|
+
|
|
59
|
+
[Eliaz Bobadilla](https://ultirequiem.com) - Creator and Maintainer 💪
|
|
60
|
+
|
|
61
|
+
See also the full list of
|
|
62
|
+
[contributors](https://github.com/UltiRequiem/drive_link/contributors) who
|
|
63
|
+
participated in this project ✨
|
|
64
|
+
|
|
65
|
+
## Versioning
|
|
66
|
+
|
|
67
|
+
We use [Semantic Versioning](http://semver.org). For the versions available, see
|
|
68
|
+
the [tags](https://github.com/UltiRequiem/drive_link/tags) 🏷️
|
|
69
|
+
|
|
70
|
+
## Licence
|
|
71
|
+
|
|
72
|
+
Licensed under the MIT License 📄
|
package/esm/mod.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const formatRegexes = [
|
|
2
|
+
/https:\/\/drive\.google\.com\/file\/d\/(?<id>.*?)\/(?:edit|view)\?usp=sharing/,
|
|
3
|
+
/https:\/\/drive\.google\.com\/open\?id=(?<id>.*?)$/,
|
|
4
|
+
];
|
|
5
|
+
const alphanumericRegex = /^[\w-]+$/;
|
|
6
|
+
function extractId(urlOrId) {
|
|
7
|
+
for (const format of formatRegexes) {
|
|
8
|
+
if (format.test(urlOrId)) {
|
|
9
|
+
const result = format.exec(urlOrId);
|
|
10
|
+
return result?.groups?.id;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
if (alphanumericRegex.test(urlOrId)) {
|
|
14
|
+
return urlOrId;
|
|
15
|
+
}
|
|
16
|
+
throw new Error("Invalid URL provided.");
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
Generate a Google Drive direct download link based on the URL or ID.
|
|
20
|
+
|
|
21
|
+
@param URLorID The URL or ID of the drive content.
|
|
22
|
+
|
|
23
|
+
@example
|
|
24
|
+
```javascript
|
|
25
|
+
driveLink('https://drive.google.com/file/d/1Px8bePd7pFSz5r6bTA7GKN9HloCzMfFk/view?usp=sharing');
|
|
26
|
+
//=> 'https://drive.google.com/uc?export=download&id=1Px8bePd7pFSz5r6bTA7GKN9HloCzMfFk'
|
|
27
|
+
```
|
|
28
|
+
*/
|
|
29
|
+
export function driveLink(URLorID, { apiKey } = {}) {
|
|
30
|
+
if (typeof URLorID !== "string") {
|
|
31
|
+
throw new TypeError("Invalid URL provided.");
|
|
32
|
+
}
|
|
33
|
+
if (typeof apiKey === "string" && !alphanumericRegex.test(apiKey)) {
|
|
34
|
+
throw new TypeError("Invalid API key provided.");
|
|
35
|
+
}
|
|
36
|
+
const id = extractId(URLorID.trim());
|
|
37
|
+
const parsedKey = apiKey?.trim();
|
|
38
|
+
return parsedKey
|
|
39
|
+
? `https://www.googleapis.com/drive/v3/files/${id}?alt=media&key=${parsedKey}`
|
|
40
|
+
: `https://drive.google.com/uc?export=download&id=${id}`;
|
|
41
|
+
}
|
package/esm/package.json
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"module": "./esm/mod.js",
|
|
3
|
+
"main": "./script/mod.js",
|
|
4
|
+
"types": "./types/mod.d.ts",
|
|
5
|
+
"name": "@ultirequiem/drive-link",
|
|
6
|
+
"description": "Generate a Google Drive direct download link based on the URL or ID.",
|
|
7
|
+
"version": "1.0.0",
|
|
8
|
+
"homepage": "https://ulti.js.org/drive_link",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"funding": {
|
|
11
|
+
"type": "patreon",
|
|
12
|
+
"url": "https://www.patreon.com/ultirequiem"
|
|
13
|
+
},
|
|
14
|
+
"repository": "github:ultirequiem/drive-link",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/ultirequiem/drive-link/issues",
|
|
17
|
+
"email": "eliaz.bobadilladev@gmail.com"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"drive",
|
|
21
|
+
"google"
|
|
22
|
+
],
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"import": "./esm/mod.js",
|
|
26
|
+
"require": "./script/mod.js",
|
|
27
|
+
"types": "./types/mod.d.ts"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"test": "node test_runner.js"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/node": "16.11.26",
|
|
36
|
+
"chalk": "4.1.2",
|
|
37
|
+
"@deno/shim-deno": "~0.4.3"
|
|
38
|
+
}
|
|
39
|
+
}
|
package/script/mod.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.driveLink = void 0;
|
|
4
|
+
const formatRegexes = [
|
|
5
|
+
/https:\/\/drive\.google\.com\/file\/d\/(?<id>.*?)\/(?:edit|view)\?usp=sharing/,
|
|
6
|
+
/https:\/\/drive\.google\.com\/open\?id=(?<id>.*?)$/,
|
|
7
|
+
];
|
|
8
|
+
const alphanumericRegex = /^[\w-]+$/;
|
|
9
|
+
function extractId(urlOrId) {
|
|
10
|
+
for (const format of formatRegexes) {
|
|
11
|
+
if (format.test(urlOrId)) {
|
|
12
|
+
const result = format.exec(urlOrId);
|
|
13
|
+
return result?.groups?.id;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (alphanumericRegex.test(urlOrId)) {
|
|
17
|
+
return urlOrId;
|
|
18
|
+
}
|
|
19
|
+
throw new Error("Invalid URL provided.");
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
Generate a Google Drive direct download link based on the URL or ID.
|
|
23
|
+
|
|
24
|
+
@param URLorID The URL or ID of the drive content.
|
|
25
|
+
|
|
26
|
+
@example
|
|
27
|
+
```javascript
|
|
28
|
+
driveLink('https://drive.google.com/file/d/1Px8bePd7pFSz5r6bTA7GKN9HloCzMfFk/view?usp=sharing');
|
|
29
|
+
//=> 'https://drive.google.com/uc?export=download&id=1Px8bePd7pFSz5r6bTA7GKN9HloCzMfFk'
|
|
30
|
+
```
|
|
31
|
+
*/
|
|
32
|
+
function driveLink(URLorID, { apiKey } = {}) {
|
|
33
|
+
if (typeof URLorID !== "string") {
|
|
34
|
+
throw new TypeError("Invalid URL provided.");
|
|
35
|
+
}
|
|
36
|
+
if (typeof apiKey === "string" && !alphanumericRegex.test(apiKey)) {
|
|
37
|
+
throw new TypeError("Invalid API key provided.");
|
|
38
|
+
}
|
|
39
|
+
const id = extractId(URLorID.trim());
|
|
40
|
+
const parsedKey = apiKey?.trim();
|
|
41
|
+
return parsedKey
|
|
42
|
+
? `https://www.googleapis.com/drive/v3/files/${id}?alt=media&key=${parsedKey}`
|
|
43
|
+
: `https://drive.google.com/uc?export=download&id=${id}`;
|
|
44
|
+
}
|
|
45
|
+
exports.driveLink = driveLink;
|
package/types/mod.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface DriveOptions {
|
|
2
|
+
/**
|
|
3
|
+
A Drive api key that can be used to exceed the download limit of 100MB.
|
|
4
|
+
*/
|
|
5
|
+
apiKey?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
Generate a Google Drive direct download link based on the URL or ID.
|
|
9
|
+
|
|
10
|
+
@param URLorID The URL or ID of the drive content.
|
|
11
|
+
|
|
12
|
+
@example
|
|
13
|
+
```javascript
|
|
14
|
+
driveLink('https://drive.google.com/file/d/1Px8bePd7pFSz5r6bTA7GKN9HloCzMfFk/view?usp=sharing');
|
|
15
|
+
//=> 'https://drive.google.com/uc?export=download&id=1Px8bePd7pFSz5r6bTA7GKN9HloCzMfFk'
|
|
16
|
+
```
|
|
17
|
+
*/
|
|
18
|
+
export declare function driveLink(URLorID: string, { apiKey }?: DriveOptions): string;
|