forked from roshanconnor123/gd-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy
executable file
·53 lines (48 loc) · 2.42 KB
/
copy
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env node
const bytes = require('bytes')
const { argv } = require('yargs')
.usage('Usage: ./$0 <source id> <target id> [options]\ntarget id Optional,If not filled, use DEFAULT_TARGET in config.js')
.alias('u', 'update')
.describe('u', 'Do not use local cache,Obtain source folder information online')
.alias('y', 'yes')
.describe('yes', 'If an existing Copy task is found, continue from where it left off without asking')
.alias('f', 'file')
.describe('f', 'Copy a single file')
.alias('n', 'name')
.describe('n', 'Rename the target folder,Leave the original Folder name if not given')
.alias('N', 'not_teamdrive')
.describe('N', 'If it is not a team drive link,This parameter can be added to improve interface query efficiency,Reduce latency')
.alias('s', 'size')
.describe('s', 'Copy all files by default,If this value is set,Then filter out files smaller than this size,Must end with b,For example 10mb')
.alias('S', 'service_account')
.describe('S', 'Specify to use service account for operation,The premise is that the json authorization file must be placed in the ./sa directory,Make sure that the sa account has proper rights.')
.alias('D', 'dncnr')
.describe('D', 'do not create new root, Do not create a folder with the same name at the destination,Copy the files in the source folder directly to the destination folder')
.help('h')
.alias('h', 'help')
const { copy, copy_file, validate_fid } = require('./src/gd')
const { DEFAULT_TARGET } = require('./config')
let [source, target] = argv._
if (validate_fid(source)) {
const { name, update, file, not_teamdrive, size, service_account, dncnr } = argv
if (file) {
target = target || DEFAULT_TARGET
if (!validate_fid(target)) throw new Error('target id Wrong')
return copy_file(source, target, service_account).then(r => {
const link = 'https://drive.google.com/drive/folders/' + target
console.log('Copy completed,Here is your Link:\n', link)
}).catch(console.error)
}
let min_size
if (size) {
console.log(`Do not copy below ${size} Document`)
min_size = bytes.parse(size)
}
copy({ source, target, name, min_size, update, not_teamdrive, service_account, dncnr }).then(folder => {
if (!folder) return
const link = 'https://drive.google.com/drive/folders/' + folder.id
console.log('\Copy Completed,Here is your Link:\n', link)
})
} else {
console.warn('Wrong FolderID')
}