-
Notifications
You must be signed in to change notification settings - Fork 47
/
copy
53 lines (48 loc) · 2.48 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 folderid> <destination folderid> [options]\ndestination folderid is Optional,If its not filled, it use DEFAULT_TARGET in config.js')
.alias('u', 'update')
.describe('u', 'Do not use local cache, force to obtain source folder information online')
.alias('y', 'yes')
.describe('yes', 'If a copy record is found, resume 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 blank')
.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')
.alias('s', 'size')
.describe('s', 'If you add this, all files are copied by default. If this value is set, files smaller than this size will be filtered out - must end with b, such as 10mb')
.alias('S', 'service_account')
.describe('S', 'Specify the service account for operation, provided that the json authorization file must be placed in the /sa Folder, please ensure that the SA account has Proper permissions。')
.alias('D', 'dncnr')
.describe('D', 'do not create new root, Does not create a folder with the same name at the destination, will directly copy the files in the source folder to the destination folder as they are')
.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('Drive ID is incorrect')
return copy_file(source, target, service_account).then(r => {
const link = 'https://drive.google.com/drive/folders/' + target
console.log('Clone is completed,File Location:\n', link)
}).catch(console.error)
}
let min_size
if (size) {
console.log(`Do not Copy Size File Below ${size} `)
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('\nClone Completed,Folder Link:\n', link)
})
} else {
console.warn('FolderID is wrong or invalid')
}