@d0whc3r/node-gdrive 3.4.1 → 3.5.1
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 +21 -0
- package/README.md +174 -92
- package/bin/cli.js +2 -634
- package/dist/auth.d.ts +25 -0
- package/dist/config.d.ts +16 -0
- package/dist/crypto.d.ts +4 -0
- package/dist/gdrive.cjs.js +1 -1
- package/dist/gdrive.esm.mjs +812 -0
- package/dist/index.d.ts +67 -48
- package/dist/retry.d.ts +3 -0
- package/dist/types.d.ts +96 -0
- package/package.json +83 -139
- package/CHANGELOG.md +0 -10
- package/dist/gdrive.esm.js +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,50 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import type { Readable } from 'node:stream';
|
|
2
|
+
import { drive_v3 } from '@googleapis/drive';
|
|
3
|
+
import { ManipulateType } from 'dayjs';
|
|
4
|
+
import Auth from './auth';
|
|
5
|
+
import Config from './config';
|
|
6
|
+
import { decryptBuffer, decryptFile, encryptBuffer, encryptFile } from './crypto';
|
|
7
|
+
import { isRetryableError, withRetry } from './retry';
|
|
8
|
+
import { CleanOlderOptions, DownloadOptions, FieldsType, GDriveConfig, Schema$File$Modded, UploadOptions, UploadOptionsBasic, UploadStreamOptions } from './types';
|
|
9
|
+
export declare function escapeDriveQuery(value: string): string;
|
|
10
|
+
export declare function parseTimeSpace(timeSpace: string): {
|
|
11
|
+
amount: number;
|
|
12
|
+
unit: ManipulateType;
|
|
13
|
+
};
|
|
5
14
|
export declare class GDrive {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
15
|
+
readonly DEFAULT_FIELDS: FieldsType[];
|
|
16
|
+
private readonly MIME_FOLDER;
|
|
17
|
+
private readonly gdriveAuth?;
|
|
18
|
+
private readonly injectedAuth?;
|
|
19
|
+
private readonly sharedDriveId?;
|
|
20
|
+
private readonly defaultDryRun;
|
|
21
|
+
private readonly defaultConcurrency;
|
|
22
|
+
private readonly defaultCompressionLevel;
|
|
23
|
+
private readonly defaultOnProgress?;
|
|
24
|
+
private readonly retryOptions;
|
|
25
|
+
private readonly logger;
|
|
26
|
+
private _drive?;
|
|
27
|
+
private _initPromise?;
|
|
28
|
+
constructor(config?: GDriveConfig);
|
|
29
|
+
private ensureInitiated;
|
|
30
|
+
private get auth();
|
|
31
|
+
private get drive();
|
|
32
|
+
private get sharedDriveListParams();
|
|
33
|
+
private get sharedDriveItemParams();
|
|
34
|
+
private get rootParentId();
|
|
35
|
+
isFolder(file: drive_v3.Schema$File): boolean | undefined;
|
|
36
|
+
isDeleted(file: drive_v3.Schema$File): boolean;
|
|
37
|
+
listFiles(fields?: boolean | FieldsType[], pageSize?: number, q?: string): Promise<Schema$File$Modded[]>;
|
|
38
|
+
getFile(fileId?: string | null): Promise<drive_v3.Schema$File>;
|
|
39
|
+
private resolveDownloadFileId;
|
|
40
|
+
downloadFile(fileIdOrName: string, destPath: string, options?: DownloadOptions): Promise<string>;
|
|
41
|
+
emptyTrash(): Promise<{
|
|
42
|
+
status: number;
|
|
43
|
+
data: unknown;
|
|
44
|
+
}>;
|
|
45
|
+
deleteFile(file: Schema$File$Modded): Promise<unknown>;
|
|
46
|
+
uploadFile(file: string, folderName?: string | boolean, options?: UploadOptionsBasic): Promise<Schema$File$Modded>;
|
|
47
|
+
uploadStream(stream: Readable, fileName: string, folderName?: string | boolean, options?: UploadStreamOptions): Promise<Schema$File$Modded>;
|
|
48
|
+
uploadFiles(files: string | string[], folderName?: string | boolean, options?: UploadOptions): Promise<Record<string, Schema$File$Modded>>;
|
|
49
|
+
cleanOlder(timeSpace: string, folderName?: string, options?: CleanOlderOptions): Promise<Schema$File$Modded[]>;
|
|
50
|
+
private expandFileInputs;
|
|
51
|
+
private getListFiles;
|
|
52
|
+
private replaceExistingFile;
|
|
53
|
+
private getUploadFolderId;
|
|
54
|
+
private deleteOlder;
|
|
55
|
+
private parseFileMeta;
|
|
56
|
+
private parseFilesMeta;
|
|
57
|
+
private genericError;
|
|
58
|
+
private readonly inFlightFolders;
|
|
59
|
+
private findFolderId;
|
|
60
|
+
private resolveFolderId;
|
|
61
|
+
private resolveFolderSegments;
|
|
62
|
+
private findFile;
|
|
63
|
+
private createFolder;
|
|
64
|
+
private createPrivateTempDir;
|
|
65
|
+
private sanitizeFilename;
|
|
66
|
+
private compressFiles;
|
|
35
67
|
}
|
|
36
|
-
export
|
|
37
|
-
export
|
|
38
|
-
isDeleted: boolean;
|
|
39
|
-
isFolder: boolean;
|
|
40
|
-
parentFolder?: string;
|
|
41
|
-
}
|
|
42
|
-
export interface UploadOptions extends UploadOptionsBasic {
|
|
43
|
-
compress?: string | boolean;
|
|
44
|
-
}
|
|
45
|
-
export interface UploadOptionsBasic {
|
|
46
|
-
create?: boolean;
|
|
47
|
-
replace?: boolean;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export {};
|
|
68
|
+
export { Auth, Config, decryptBuffer, decryptFile, encryptBuffer, encryptFile, isRetryableError, withRetry };
|
|
69
|
+
export * from './types';
|
package/dist/retry.d.ts
ADDED
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { drive_v3 } from '@googleapis/drive';
|
|
2
|
+
import type { GoogleAuth, OAuth2Client } from 'google-auth-library';
|
|
3
|
+
export type Params$Resource$Files$Get = drive_v3.Params$Resource$Files$Get;
|
|
4
|
+
export type Params$Resource$Files$List = drive_v3.Params$Resource$Files$List;
|
|
5
|
+
export type Params$Resource$Files$Create = drive_v3.Params$Resource$Files$Create;
|
|
6
|
+
export type Params$Resource$Files$Delete = drive_v3.Params$Resource$Files$Delete;
|
|
7
|
+
export declare const allFileTypes: readonly ['appProperties', 'capabilities', 'contentHints', 'createdTime', 'description', 'explicitlyTrashed', 'fileExtension', 'folderColorRgb', 'fullFileExtension', 'hasAugmentedPermissions', 'hasThumbnail', 'headRevisionId', 'iconLink', 'id', 'imageMediaMetadata', 'isAppAuthorized', 'lastModifyingUser', 'md5Checksum', 'mimeType', 'modifiedByMe', 'modifiedByMeTime', 'modifiedTime', 'name', 'originalFilename', 'ownedByMe', 'owners', 'parents', 'properties', 'quotaBytesUsed', 'shared', 'sharedWithMeTime', 'sharingUser', 'size', 'spaces', 'starred', 'teamDriveId', 'thumbnailLink', 'thumbnailVersion', 'trashed', 'trashedTime', 'trashingUser', 'version', 'videoMediaMetadata', 'viewedByMe', 'viewedByMeTime', 'viewersCanCopyContent', 'webContentLink', 'webViewLink', 'writersCanShare'];
|
|
8
|
+
export type FieldsType = (typeof allFileTypes)[number];
|
|
9
|
+
export interface Schema$File$Modded extends drive_v3.Schema$File {
|
|
10
|
+
isDeleted: boolean;
|
|
11
|
+
isFolder: boolean;
|
|
12
|
+
parentFolder?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface Logger {
|
|
15
|
+
info: (...args: unknown[]) => void;
|
|
16
|
+
warn: (...args: unknown[]) => void;
|
|
17
|
+
error: (...args: unknown[]) => void;
|
|
18
|
+
}
|
|
19
|
+
export interface UploadProgressEvent {
|
|
20
|
+
fileName: string;
|
|
21
|
+
bytesRead: number;
|
|
22
|
+
totalBytes: number;
|
|
23
|
+
percentage: number;
|
|
24
|
+
}
|
|
25
|
+
export interface RetryOptions {
|
|
26
|
+
maxRetries?: number;
|
|
27
|
+
baseDelayMs?: number;
|
|
28
|
+
maxDelayMs?: number;
|
|
29
|
+
jitter?: boolean;
|
|
30
|
+
sleep?: (ms: number) => Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
export interface AuthConfig {
|
|
33
|
+
credentialsFile?: string;
|
|
34
|
+
tokenFile?: string;
|
|
35
|
+
serviceAccountFile?: string;
|
|
36
|
+
useADC?: boolean;
|
|
37
|
+
scopes?: string[];
|
|
38
|
+
logger?: Logger;
|
|
39
|
+
}
|
|
40
|
+
export interface GDriveConfig extends AuthConfig {
|
|
41
|
+
sharedDriveId?: string;
|
|
42
|
+
dryRun?: boolean;
|
|
43
|
+
concurrency?: number;
|
|
44
|
+
compressionLevel?: number;
|
|
45
|
+
onProgress?: (event: UploadProgressEvent) => void;
|
|
46
|
+
retry?: RetryOptions;
|
|
47
|
+
auth?: OAuth2Client | GoogleAuth;
|
|
48
|
+
drive?: drive_v3.Drive;
|
|
49
|
+
}
|
|
50
|
+
export interface UploadOptionsBasic {
|
|
51
|
+
create?: boolean;
|
|
52
|
+
replace?: boolean;
|
|
53
|
+
dryRun?: boolean;
|
|
54
|
+
encryptKey?: string;
|
|
55
|
+
onProgress?: (event: UploadProgressEvent) => void;
|
|
56
|
+
}
|
|
57
|
+
export interface UploadOptions extends UploadOptionsBasic {
|
|
58
|
+
compress?: string | boolean;
|
|
59
|
+
compressionLevel?: number;
|
|
60
|
+
exclude?: string[];
|
|
61
|
+
followSymlinks?: boolean;
|
|
62
|
+
concurrency?: number;
|
|
63
|
+
}
|
|
64
|
+
export interface UploadStreamOptions extends UploadOptionsBasic {
|
|
65
|
+
mimeType?: string;
|
|
66
|
+
size?: number;
|
|
67
|
+
}
|
|
68
|
+
export interface CleanOlderOptions {
|
|
69
|
+
dryRun?: boolean;
|
|
70
|
+
keepLast?: number;
|
|
71
|
+
concurrency?: number;
|
|
72
|
+
}
|
|
73
|
+
export interface DownloadOptions {
|
|
74
|
+
decryptKey?: string;
|
|
75
|
+
folderName?: string;
|
|
76
|
+
}
|
|
77
|
+
export interface Installed {
|
|
78
|
+
client_id: string;
|
|
79
|
+
project_id?: string;
|
|
80
|
+
auth_uri?: string;
|
|
81
|
+
token_uri?: string;
|
|
82
|
+
auth_provider_x509_cert_url?: string;
|
|
83
|
+
client_secret: string;
|
|
84
|
+
redirect_uris?: string[];
|
|
85
|
+
}
|
|
86
|
+
export interface CredentialsFile {
|
|
87
|
+
installed?: Installed;
|
|
88
|
+
web?: Installed;
|
|
89
|
+
}
|
|
90
|
+
export interface TokenFile {
|
|
91
|
+
access_token?: string | null;
|
|
92
|
+
refresh_token?: string | null;
|
|
93
|
+
scope?: string;
|
|
94
|
+
token_type?: string | null;
|
|
95
|
+
expiry_date?: number | null;
|
|
96
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d0whc3r/node-gdrive",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.1",
|
|
4
|
+
"keywords": [
|
|
5
|
+
"backup",
|
|
6
|
+
"compress",
|
|
7
|
+
"copy",
|
|
8
|
+
"drive",
|
|
9
|
+
"gdrive",
|
|
10
|
+
"google",
|
|
11
|
+
"googleapi",
|
|
12
|
+
"node",
|
|
13
|
+
"upload"
|
|
14
|
+
],
|
|
4
15
|
"license": "MIT",
|
|
5
16
|
"author": {
|
|
6
|
-
"email": "d0whc3r@gmail.com",
|
|
7
17
|
"name": "d0whc3r",
|
|
18
|
+
"email": "d0whc3r@gmail.com",
|
|
8
19
|
"url": "https://github.com/d0whc3r"
|
|
9
20
|
},
|
|
10
21
|
"repository": {
|
|
@@ -19,152 +30,85 @@
|
|
|
19
30
|
"bin"
|
|
20
31
|
],
|
|
21
32
|
"main": "dist/gdrive.cjs.js",
|
|
22
|
-
"module": "dist/gdrive.esm.
|
|
33
|
+
"module": "dist/gdrive.esm.mjs",
|
|
23
34
|
"types": "dist/index.d.ts",
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"import": "./dist/gdrive.esm.mjs",
|
|
39
|
+
"require": "./dist/gdrive.cjs.js"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public",
|
|
44
|
+
"registry": "https://registry.npmjs.org"
|
|
45
|
+
},
|
|
35
46
|
"scripts": {
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"build:
|
|
43
|
-
"build:
|
|
44
|
-
"build:
|
|
45
|
-
"
|
|
46
|
-
"build
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"coverage:coveralls": "cat ./coverage/lcov.info | coveralls",
|
|
59
|
-
"coverage:codacy": "wget -q https://coverage.codacy.com/get.sh && bash get.sh report -l typescript -r coverage/lcov.info",
|
|
60
|
-
"eslint": "eslint -c .eslintrc.js --ext .ts,.js src cli",
|
|
61
|
-
"eslint:fix": "yarn eslint --fix",
|
|
62
|
-
"format": "pretty-quick \"{src,cli}/**/*.ts\" --write --staged",
|
|
63
|
-
"commit": "git-cz",
|
|
64
|
-
"semantic-release": "semantic-release",
|
|
65
|
-
"postversion": "git commit -am 'chore(bump): bump version [skip-ci]' && git push --follow-tags"
|
|
47
|
+
"clean": "node -e \"import('node:fs').then(fs => ['dist','bin','build','coverage','node-gdrive','node-gdrive.exe'].forEach(p => fs.rmSync(p, {recursive:true,force:true})))\"",
|
|
48
|
+
"cli:dev": "node --env-file=.env cli/cli.ts",
|
|
49
|
+
"cli": "node cli/cli.ts",
|
|
50
|
+
"typecheck": "tsc --noEmit",
|
|
51
|
+
"build:clean": "node -e \"import('node:fs').then(fs => ['dist','bin'].forEach(p => fs.rmSync(p, {recursive:true,force:true})))\"",
|
|
52
|
+
"build:lib": "vite build --config vite.config.mts",
|
|
53
|
+
"build:cli": "vite build --config vite.cli.config.mts",
|
|
54
|
+
"build:dts": "tsc -p tsconfig.build.json --emitDeclarationOnly",
|
|
55
|
+
"build:base": "pnpm build:clean && pnpm build:lib && pnpm build:cli && pnpm build:dts",
|
|
56
|
+
"build:sea": "vite build --config vite.sea.config.mts && node scripts/build-sea.mjs",
|
|
57
|
+
"build": "pnpm build:base && pnpm build:sea",
|
|
58
|
+
"test": "vitest run",
|
|
59
|
+
"test:unit": "vitest run --exclude tests/gdrive.integration.spec.ts",
|
|
60
|
+
"test:integration": "vitest run tests/gdrive.integration.spec.ts",
|
|
61
|
+
"test:watch": "vitest",
|
|
62
|
+
"test:coverage": "vitest run --coverage",
|
|
63
|
+
"lint": "oxlint",
|
|
64
|
+
"lint:fix": "oxlint --fix",
|
|
65
|
+
"format": "oxfmt --write",
|
|
66
|
+
"format:check": "oxfmt --check",
|
|
67
|
+
"prepare": "husky",
|
|
68
|
+
"semantic-release": "semantic-release"
|
|
66
69
|
},
|
|
67
70
|
"dependencies": {
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"command-line-args": "
|
|
71
|
-
"command-line-usage": "
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"mime-types": "
|
|
75
|
-
"
|
|
76
|
-
"mysqldump": "3.2.0"
|
|
71
|
+
"@googleapis/drive": "^27.1.0",
|
|
72
|
+
"archiver": "^8.0.0",
|
|
73
|
+
"command-line-args": "^6.0.2",
|
|
74
|
+
"command-line-usage": "^7.0.4",
|
|
75
|
+
"dayjs": "^1.11.23",
|
|
76
|
+
"google-auth-library": "^11.3.4",
|
|
77
|
+
"mime-types": "^3.0.2",
|
|
78
|
+
"mysqldump": "^3.2.0"
|
|
77
79
|
},
|
|
78
80
|
"devDependencies": {
|
|
79
|
-
"@
|
|
80
|
-
"@
|
|
81
|
-
"@
|
|
82
|
-
"@
|
|
83
|
-
"@
|
|
84
|
-
"@
|
|
85
|
-
"@
|
|
86
|
-
"@
|
|
87
|
-
"@
|
|
88
|
-
"@
|
|
89
|
-
"@
|
|
90
|
-
"@
|
|
91
|
-
"@
|
|
92
|
-
"@
|
|
93
|
-
"
|
|
94
|
-
"
|
|
95
|
-
"
|
|
96
|
-
"
|
|
97
|
-
"
|
|
98
|
-
"
|
|
99
|
-
"
|
|
100
|
-
"
|
|
101
|
-
"@typescript-eslint/eslint-plugin": "3.6.1",
|
|
102
|
-
"@typescript-eslint/parser": "3.6.1",
|
|
103
|
-
"builtin-modules": "3.1.0",
|
|
104
|
-
"commitizen": "4.1.2",
|
|
105
|
-
"core-js": "3.6.5",
|
|
106
|
-
"coveralls": "3.1.0",
|
|
107
|
-
"cz-conventional-changelog": "3.2.0",
|
|
108
|
-
"dotenv": "8.2.0",
|
|
109
|
-
"dotenv-cli": "3.2.0",
|
|
110
|
-
"dts-bundle-generator": "5.0.0",
|
|
111
|
-
"esbuild": "0.6.3",
|
|
112
|
-
"eslint": "7.4.0",
|
|
113
|
-
"eslint-config-prettier": "6.11.0",
|
|
114
|
-
"eslint-plugin-prettier": "3.1.4",
|
|
115
|
-
"eslint-plugin-sonarjs": "0.5.0",
|
|
116
|
-
"find-node-modules": "2.1.0",
|
|
117
|
-
"google-auth-library": "6.0.5",
|
|
118
|
-
"husky": "4.2.5",
|
|
119
|
-
"jest": "26.1.0",
|
|
120
|
-
"jest-chain": "1.1.5",
|
|
121
|
-
"jest-extended": "0.11.5",
|
|
122
|
-
"jest-junit": "11.0.1",
|
|
123
|
-
"jest-sonar-reporter": "2.0.0",
|
|
124
|
-
"lint-staged": "10.2.11",
|
|
125
|
-
"mock-stdin": "1.0.0",
|
|
126
|
-
"nock": "13.0.2",
|
|
127
|
-
"npm-run-all": "4.1.5",
|
|
128
|
-
"pkg": "4.4.9",
|
|
129
|
-
"prettier": "2.0.5",
|
|
130
|
-
"pretty-quick": "2.0.1",
|
|
131
|
-
"regenerator-runtime": "0.13.5",
|
|
132
|
-
"rimraf": "3.0.2",
|
|
133
|
-
"rollup": "2.21.0",
|
|
134
|
-
"rollup-plugin-auto-external": "2.0.0",
|
|
135
|
-
"rollup-plugin-esbuild": "2.3.0",
|
|
136
|
-
"rollup-plugin-node-builtins": "2.1.2",
|
|
137
|
-
"semantic-release": "17.1.1",
|
|
138
|
-
"sonar-scanner": "3.1.0",
|
|
139
|
-
"ts-jest": "26.1.3",
|
|
140
|
-
"ts-node": "8.10.2",
|
|
141
|
-
"tsconfig-paths": "3.9.0",
|
|
142
|
-
"typescript": "3.9.7"
|
|
143
|
-
},
|
|
144
|
-
"jestSonar": {
|
|
145
|
-
"reportPath": "coverage",
|
|
146
|
-
"reportFile": "test-report.xml"
|
|
147
|
-
},
|
|
148
|
-
"jest-junit": {
|
|
149
|
-
"outputDirectory": "./coverage",
|
|
150
|
-
"outputName": "./junit.xml"
|
|
151
|
-
},
|
|
152
|
-
"husky": {
|
|
153
|
-
"hooks": {
|
|
154
|
-
"pre-commit": "yarn eslint:fix && lint-staged",
|
|
155
|
-
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
|
|
156
|
-
}
|
|
81
|
+
"@commitlint/cli": "^21.2.4",
|
|
82
|
+
"@commitlint/config-conventional": "^21.2.4",
|
|
83
|
+
"@semantic-release/changelog": "^7.0.0",
|
|
84
|
+
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
85
|
+
"@semantic-release/git": "^11.0.1",
|
|
86
|
+
"@semantic-release/github": "^12.0.11",
|
|
87
|
+
"@semantic-release/npm": "^13.2.0",
|
|
88
|
+
"@semantic-release/release-notes-generator": "^14.1.1",
|
|
89
|
+
"@types/archiver": "^8.0.0",
|
|
90
|
+
"@types/command-line-args": "^5.2.3",
|
|
91
|
+
"@types/command-line-usage": "^5.0.4",
|
|
92
|
+
"@types/mime-types": "^3.0.1",
|
|
93
|
+
"@types/node": "^26.6.10",
|
|
94
|
+
"@vitest/coverage-v8": "^5.1.2",
|
|
95
|
+
"husky": "^9.1.7",
|
|
96
|
+
"lint-staged": "^17.6.2",
|
|
97
|
+
"oxfmt": "^0.80.0",
|
|
98
|
+
"oxlint": "^1.95.0",
|
|
99
|
+
"semantic-release": "^26.0.1",
|
|
100
|
+
"typescript": "^7.0.2",
|
|
101
|
+
"vite": "^8.3.8",
|
|
102
|
+
"vitest": "^5.1.2"
|
|
157
103
|
},
|
|
158
104
|
"lint-staged": {
|
|
159
|
-
"{src,cli}/**/*.ts": [
|
|
160
|
-
"
|
|
105
|
+
"{src,cli,tests}/**/*.ts": [
|
|
106
|
+
"pnpm lint:fix",
|
|
107
|
+
"pnpm format"
|
|
161
108
|
]
|
|
162
109
|
},
|
|
163
|
-
"
|
|
164
|
-
"
|
|
165
|
-
"access": "public"
|
|
110
|
+
"engines": {
|
|
111
|
+
"node": ">=26.0.0"
|
|
166
112
|
},
|
|
167
|
-
"
|
|
168
|
-
"path": "node_modules/cz-conventional-changelog"
|
|
169
|
-
}
|
|
113
|
+
"packageManager": "pnpm@12.16.1"
|
|
170
114
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
## [3.4.1](https://github.com/d0whc3r/node-gdrive/compare/v3.4.0...v3.4.1) (2020-07-17)
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
### Bug Fixes
|
|
5
|
-
|
|
6
|
-
* **build:** use es2015 for build output ([f4614b6](https://github.com/d0whc3r/node-gdrive/commit/f4614b6a0cc2bb58d7faa6bbd91379f8c120d7d8)), closes [#306](https://github.com/d0whc3r/node-gdrive/issues/306)
|
|
7
|
-
* **deps:** update dependecies ([7b9ba4c](https://github.com/d0whc3r/node-gdrive/commit/7b9ba4c32fce166b04465fee53235869e370e6a7))
|
|
8
|
-
* docker copy files ([cc87f3b](https://github.com/d0whc3r/node-gdrive/commit/cc87f3bc978994fe939be03c5e4343c2c3d87f5e))
|
|
9
|
-
* docker copy files ([76067d4](https://github.com/d0whc3r/node-gdrive/commit/76067d4c5379025c9fa49742390e080403391183))
|
|
10
|
-
* update relase config ([205d4db](https://github.com/d0whc3r/node-gdrive/commit/205d4db62fe0ef7067351a47d5d1686ec7313af0))
|
package/dist/gdrive.esm.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{google as v,drive_v3 as s}from"googleapis";import n,{existsSync as t,mkdirSync as B,readFileSync as w,writeFile as C}from"fs";import D from"mime-types";import o,{isAbsolute as E,resolve as F,sep as G}from"path";import H from"archiver";import u from"moment";import x from"glob";import I from"readline";import y from"colors";import J from"os";class j{}j.TOKEN_FILE=process.env.TOKEN_FILE||"./secrets/token.json",j.CREDENTIALS_FILE=process.env.CREDENTIALS_FILE||"./secrets/credentials.json",j.TAG="[node-gdrive]";class K{static mkdirp(a){const d=G,c=E(a)?d:"",b=a.split(d).reduce((h,i)=>{const f=F(h,i);return t(f)||B(f),f},c);console.info(`${j.TAG} Result file ${b}`)}}var L=(a,d,c)=>new Promise((b,h)=>{var i=e=>{try{k(c.next(e))}catch(g){h(g)}},f=e=>{try{k(c.throw(e))}catch(g){h(g)}},k=e=>e.done?b(e.value):Promise.resolve(e.value).then(i,f);k((c=c.apply(a,d)).next())});class M{constructor(){this.ready=!0,this.SCOPES=["https://www.googleapis.com/auth/drive","https://www.googleapis.com/auth/drive.file","https://www.googleapis.com/auth/drive.metadata","https://www.googleapis.com/auth/drive.metadata.readonly"],this.TOKEN_FILE=j.TOKEN_FILE,this.CREDENTIALS_FILE=j.CREDENTIALS_FILE,this.existsCredentials||(this.ready=!1,console.error(y.bold(`${j.TAG} ERROR: Credentials file not found in ${this.CREDENTIALS_FILE}`).red))}get existsToken(){return t(this.TOKEN_FILE)}get existsCredentials(){return t(this.CREDENTIALS_FILE)}initiate(){return L(this,[],function*(){return this.ready?this.existsToken?Promise.resolve(!0):this.generateAccessToken():Promise.reject(!1)})}oAuth2Client(a=!0){if(!this._oAuth2Client){const d=JSON.parse(w(this.CREDENTIALS_FILE,"utf8")),{client_secret:c,client_id:b,redirect_uris:h}=d.installed;this._oAuth2Client=new v.auth.OAuth2(b,c,h[0]);if(a){const i=JSON.parse(w(this.TOKEN_FILE,"utf8"));this._oAuth2Client.setCredentials(i)}}return this._oAuth2Client}generateAccessToken(){return new Promise((a,d)=>{const c=this.oAuth2Client(!1).generateAuthUrl({access_type:"offline",scope:this.SCOPES});console.log(`${j.TAG} Authorize this app by visiting this url:`,c);const b=I.createInterface({input:process.stdin,output:process.stdout});b.question(`${j.TAG} Enter the code from that page here: `,h=>{b.close(),this.oAuthGetToken(h,{resolve:a,reject:d})})})}oAuthGetToken(a,d){this.oAuth2Client(!1).getToken(a).then(({tokens:c})=>{this.oAuth2Client(!1).setCredentials(c),this.writeToken(c,d)}).catch(c=>(console.error(y.bold(`${j.TAG} Error retrieving access token`).red,c.message),d.reject(c)))}writeToken(a,{resolve:d,reject:c}){C(this.TOKEN_FILE,JSON.stringify(a),b=>{b?(console.error(b),void c(b)):(console.log(`${j.TAG} Token stored to`,this.TOKEN_FILE),void d(!0))})}}var _=s.Params$Resource$Files$Get,$=s.Params$Resource$Files$List,aa=s.Params$Resource$Files$Create;const N=["appProperties","capabilities","contentHints","createdTime","description","explicitlyTrashed","fileExtension","folderColorRgb","fullFileExtension","hasAugmentedPermissions","hasThumbnail","headRevisionId","iconLink","id","imageMediaMetadata","isAppAuthorized","lastModifyingUser","md5Checksum","mimeType","modifiedByMe","modifiedByMeTime","modifiedTime","name","originalFilename","ownedByMe","owners","parents","properties","quotaBytesUsed","shared","sharedWithMeTime","sharingUser","size","spaces","starred","teamDriveId","thumbnailLink","thumbnailVersion","trashed","trashedTime","trashingUser","version","videoMediaMetadata","viewedByMe","viewedByMeTime","viewersCanCopyContent","webContentLink","webViewLink","writersCanShare"];var q=Object.assign,l=(a,d,c)=>new Promise((b,h)=>{var i=e=>{try{k(c.next(e))}catch(g){h(g)}},f=e=>{try{k(c.throw(e))}catch(g){h(g)}},k=e=>e.done?b(e.value):Promise.resolve(e.value).then(i,f);k((c=c.apply(a,d)).next())});class O{constructor(){this.DEFAULT_FIELDS=["createdTime","id","md5Checksum","mimeType","name","parents","trashed"],this.MIME_FOLDER="application/vnd.google-apps.folder",this.gdriveAuth=new M(),this.initiated=this.gdriveAuth.initiate(),this.initiated.catch(()=>{const a=`${j.TAG} ERROR! could not get credentials file. GDrive will not work`;throw console.error(a),new Error(a)})}get auth(){return this.gdriveAuth.oAuth2Client(!0)}get drive(){return v.drive({version:"v3",auth:this.auth})}isFolder(a){return Object.prototype.hasOwnProperty.call(a,"mimeType")?a.mimeType===this.MIME_FOLDER:void 0}isDeleted(a){return Object.prototype.hasOwnProperty.call(a,"trashed")?!!a.trashed:!1}listFiles(a,d=50){return l(this,[],function*(){yield this.initiated,a?a===!0&&(a=N):a=this.DEFAULT_FIELDS;const c={pageSize:d,fields:`kind, nextPageToken, incompleteSearch, files(${a.join(", ")})`,prettyPrint:!0,includeTeamDriveItems:!1};return this.getListFiles(c)})}getFile(a){return l(this,[],function*(){yield this.initiated;if(!a)return Promise.reject(this.genericError(new Error("File id not found")));const d={fileId:a},c=this.drive.files.get(d).then(({data:b})=>b);return c.catch(b=>{this.genericError(b)}),c})}emptyTrash(){return l(this,[],function*(){return yield this.initiated,this.drive.files.emptyTrash()})}deleteFile(a){return l(this,[],function*(){yield this.initiated;if(a.id){const d=this.drive.files.delete({fileId:a.id}).then(({data:c})=>(a.name&&console.warn(`${j.TAG} Deleted ${a.isFolder?"folder":"file"}: ${a.name}`),c));return d.catch(c=>{this.genericError(c)}),d}})}uploadFile(a,d,c={}){return l(this,[],function*(){yield this.initiated;const{create:b=!0,replace:h=!1}=c,i=o.basename(a),f=D.contentType(i)||void 0,k={name:i,mimeType:f};let e=null;try{e=yield this.getUploadFolderId(d||!1,b,k)}catch(m){return Promise.reject(m)}try{yield this.replaceExistingFolder(h,i,e)}catch(m){return Promise.reject(m)}const g=n.createReadStream(a),p={requestBody:k,media:{body:g},fields:`kind, ${this.DEFAULT_FIELDS.join(", ")}`},r=n.statSync(a).size,P=m=>{const A=m.bytesRead/r*100;A===100&&console.warn(`${j.TAG} Upload ${i}: ${Math.round(A)}% complete`)},z=this.drive.files.create(p,{onUploadProgress:P}).then(({data:m})=>this.parseFileMeta(m)).finally(()=>{g.destroy()});return z.catch(m=>{this.genericError(m)}),z})}uploadFiles(a,d,c={}){return l(this,[],function*(){yield this.initiated;const{compress:b,replace:h,create:i}=c;Array.isArray(a)||(a=[a]);let f=a;if(b){let e=b;typeof e!=="string"&&(e=`zipped_${u().format("YYYY-MM-DD.HHmmss")}.zip`);const g=yield this.compressFiles(a,e);f=[g]}const k={};for(const e of f)if(e.includes("*"))yield this.uploadFiles(x.sync(e),d,c);else if(n.lstatSync(e).isDirectory())yield this.uploadFiles(x.sync(`${e}/*`),d,c);else{const g=o.basename(e),p=yield this.uploadFile(e,d,{replace:h,create:i});k[g]=this.parseFileMeta(p)}return k})}cleanOlder(a,d){return l(this,[],function*(){const c=/([0-9]+)(\w+)/.exec(a);if(!c)return console.error(`${j.TAG} Unknown timesSpace "${a}"`),Promise.reject(!1);yield this.initiated;let b="";if(d)try{b=yield this.findFolderId(d,!1)}catch(h){return console.error("Could not find folder",d,h),Promise.reject(!1)}yield this.deleteOlder(c,b)})}getListFiles(a,d=[]){const c=this.drive.files.list(a).then(({data:b})=>l(this,[],function*(){return d=d.concat(b.files),b.nextPageToken?(a.pageToken=b.nextPageToken,this.getListFiles(a,d)):d})).then(b=>this.parseFilesMeta(b));return c.catch(b=>{this.genericError(b)}),c}replaceExistingFolder(a,d,c){return l(this,[],function*(){if(a!==void 0){const b=yield this.findFile(d,c);if(b)if(a)console.warn(`${j.TAG} File "${d}" already exists and will be deleted before upload`),yield this.deleteFile(b);else throw new Error(`${j.TAG} File "${d}" already exists and will not be replaced`)}})}getUploadFolderId(a,d,c){return l(this,[],function*(){let b="";if(a&&typeof a==="string"){b=yield this.findFolderId(a,d===void 0?!0:d);if(b)c.parents=[b];else return Promise.reject(new Error(`${j.TAG} Folder "${a}" does not exists and will not be created`))}return Promise.resolve(b)})}deleteOlder(a,d){return l(this,[],function*(){const c=yield this.listFiles();if(c&&c.length){const[,b,h]=a,i=c.filter(f=>!d||d&&!f.isFolder).filter(f=>!d||d&&f.parents&&f.parents.includes(d)).map(f=>q(q({},f),{toDelete:u(f.createdTime||void 0).isSameOrBefore(u().subtract(+b,h))})).filter(f=>f.toDelete);if(i&&i.length)for(const f of i)yield this.deleteFile(f)}})}parseFileMeta(a){return q(q({},a),{isDeleted:this.isDeleted(a),isFolder:!!this.isFolder(a)})}parseFilesMeta(a){return[...a].map(d=>this.parseFileMeta(d))}genericError(a){return console.error(`${j.TAG} The API returned an error: ${a}`),a}findFolderId(a,d=!1){return l(this,[],function*(){const c=(yield this.listFiles()).filter(b=>b.isFolder).filter(b=>!b.isDeleted).filter(b=>b.name===a).map(b=>b.id);if(c&&c.length)return Promise.resolve(c[0]||"");if(d){const b=yield this.createFolder(a);return Promise.resolve(b.id||"")}return Promise.reject(!1)})}findFile(a,d){return l(this,[],function*(){const c=(yield this.listFiles()).filter(b=>!b.isFolder).filter(b=>!b.isDeleted).filter(b=>b.name===a).filter(b=>!d||b.parents&&b.parents.some(h=>h===d));return c&&c.length?c[0]:null})}createFolder(a){return l(this,[],function*(){const d=this.drive.files.create({requestBody:{name:a,mimeType:this.MIME_FOLDER},fields:"id"}).then(({data:b})=>b);d.catch(b=>{this.genericError(b)});const c=yield d;return(c==null?void 0:c.id)&&console.warn(`${j.TAG} Created folder "${a}" with id: "${c.id}"`),c})}compressFiles(a,d){return new Promise((c,b)=>{const h=J.tmpdir(),i=o.resolve(h,d);K.mkdirp(o.dirname(i));const f=n.createWriteStream(i),k=[],e=H("zip",{zlib:{level:9}});f.on("close",()=>{c(i),f.destroy()}),f.on("end",()=>{c(i),f.destroy()}),e.on("warning",g=>{console.warn(`${j.TAG} Warning compressing file`,g),g.code!=="ENOENT"&&b(g)}),e.on("error",g=>{console.error(`${j.TAG} Error compressing file`),b(g)}),e.pipe(f),a.forEach(g=>{if(g.includes("*"))e.glob(g);else if(n.lstatSync(g).isDirectory())e.directory(g,!1);else{const p=o.basename(g),r=n.createReadStream(g);e.append(r,{name:p}),k.push(r)}}),e.finalize().finally(()=>{k.forEach(g=>{g.destroy()})})})}}export{O as GDrive};
|