add -D option to ./copy, means do not create new root while copying by @iwestlin

This commit is contained in:
liaojack8 2020-07-05 21:53:20 +08:00
parent 010c23a060
commit 6fe42e3462
1 changed files with 5 additions and 3 deletions

8
copy
View File

@ -16,6 +16,8 @@ const { argv } = require('yargs')
.describe('s', '不填默认拷贝全部文件如果设置了这个值则过滤掉小于这个size的文件必须以b结尾比如10mb') .describe('s', '不填默认拷贝全部文件如果设置了这个值则过滤掉小于这个size的文件必须以b结尾比如10mb')
.alias('S', 'service_account') .alias('S', 'service_account')
.describe('S', '指定使用service account进行操作前提是必须在 ./sa 目录下放置json授权文件请确保sa帐号拥有操作权限。') .describe('S', '指定使用service account进行操作前提是必须在 ./sa 目录下放置json授权文件请确保sa帐号拥有操作权限。')
.alias('D', 'dncnr')
.describe('D', 'do not create new root, 不在目的地创建同名文件夹,直接将源文件夹中的文件原样复制到目的文件夹中')
.help('h') .help('h')
.alias('h', 'help') .alias('h', 'help')
@ -25,11 +27,11 @@ const { DEFAULT_TARGET } = require('./config')
let [source, target] = argv._ let [source, target] = argv._
if (validate_fid(source)) { if (validate_fid(source)) {
const { name, update, file, not_teamdrive, size, service_account } = argv const { name, update, file, not_teamdrive, size, service_account, dncnr } = argv
if (file) { if (file) {
target = target || DEFAULT_TARGET target = target || DEFAULT_TARGET
if (!validate_fid(target)) throw new Error('target id 格式不正确') if (!validate_fid(target)) throw new Error('target id 格式不正确')
return copy_file(source, target).then(r => { return copy_file(source, target, service_account).then(r => {
const link = 'https://drive.google.com/drive/folders/' + target const link = 'https://drive.google.com/drive/folders/' + target
console.log('任务完成,文件所在位置:\n', link) console.log('任务完成,文件所在位置:\n', link)
}).catch(console.error) }).catch(console.error)
@ -39,7 +41,7 @@ if (validate_fid(source)) {
console.log(`不复制大小低于 ${size} 的文件`) console.log(`不复制大小低于 ${size} 的文件`)
min_size = bytes.parse(size) min_size = bytes.parse(size)
} }
copy({ source, target, name, min_size, update, not_teamdrive, service_account }).then(folder => { copy({ source, target, name, min_size, update, not_teamdrive, service_account, dncnr }).then(folder => {
if (!folder) return if (!folder) return
const link = 'https://drive.google.com/drive/folders/' + folder.id const link = 'https://drive.google.com/drive/folders/' + folder.id
console.log('\n任务完成新文件夹链接\n', link) console.log('\n任务完成新文件夹链接\n', link)