forked from iwestlin/gd-utils
-
Notifications
You must be signed in to change notification settings - Fork 38
/
count
executable file
·31 lines (29 loc) · 2.57 KB
/
count
1
2
3
4
5
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
#!/usr/bin/env node
const { argv } = require('yargs')
.usage('Usage: ./$0 <FolderID> [options]')
.example('./$0 1ULY8ISgWSOVc0UrzejykVgXfVL_I4r75', 'Get statistics of all files contained in https://drive.google.com/drive/folders/1ULY8ISgWSOVc0UrzejykVgXfVL_I4r75')
.example('./$0 root -s size -t html -o out.html', 'Get the personal drive root directory statistics, the results are output in HTML form, sorted in reverse order according to the total size, and saved to the out.html file in this directory (create new if it does not exist, overwrite if it exists) ')
.example('./$0 root -s name -t json -o out.json', 'Get the statistics information of the root directory of the personal drive. The results are output in JSON format, sorted by file extension, and saved to the out.json file in this directory')
.example('./$0 root -t all -o all.json', 'Get the statistics of the root Folder of the personal drive, output all file information (including folders) in JSON format, and save it to the all.json file in this Folder')
.alias('u', 'update')
.describe('u', 'Force to get information online (regardless of whether there is a local cache)')
.alias('N', 'not_teamdrive')
.describe('N', 'If it is not a team drive link, you can add this parameter to improve interface query efficiency and reduce latency. If you want to count a personal drive and the service account in the ./sa directory does not have relevant permissions, please make sure to add this flag to use personal auth information for query')
.alias('S', 'service_account')
.describe('S', 'Specify the use of service account for statistics,The thing is that the SA json file must be placed in the sa Folder')
.alias('s', 'sort')
.describe('s', 'Sorting method of statistical results,Optional value name or size,If it is not filled in, it will be arranged in reverse order according to the number of files by default')
.alias('t', 'type')
.describe('t', 'The output type of the statistical result, the optional value is html/tree/snap/json/all, all means output the data as a json, it is best to use with -o. If not filled, the command line form will be output by default')
.alias('o', 'output')
.describe('o', 'Statistics output file, suitable to use with -t')
.help('h')
.alias('h', 'help')
const { count, validate_fid } = require('./src/gd')
const [fid] = argv._
if (validate_fid(fid)) {
const { update, sort, type, output, not_teamdrive, service_account } = argv
count({ fid, update, sort, type, output, not_teamdrive, service_account }).catch(console.error)
} else {
console.warn('FolderID is wrong or invalid')
}