fix the problem folder name 'undefine'
This commit is contained in:
parent
b12caaa17c
commit
8c000fc9ca
|
@ -388,7 +388,7 @@ async function get_info_by_id (fid, use_sa) {
|
||||||
includeItemsFromAllDrives: true,
|
includeItemsFromAllDrives: true,
|
||||||
supportsAllDrives: true,
|
supportsAllDrives: true,
|
||||||
corpora: 'allDrives',
|
corpora: 'allDrives',
|
||||||
fields: 'id, parents'
|
fields: 'id,name, parents'
|
||||||
}
|
}
|
||||||
url += '?' + params_to_query(params)
|
url += '?' + params_to_query(params)
|
||||||
const headers = await gen_headers(use_sa)
|
const headers = await gen_headers(use_sa)
|
||||||
|
@ -506,8 +506,8 @@ async function real_copy ({ source, target, name, min_size, update, dncnr, not_t
|
||||||
let files = arr.filter(v => v.mimeType !== FOLDER_TYPE)
|
let files = arr.filter(v => v.mimeType !== FOLDER_TYPE)
|
||||||
if (min_size) files = files.filter(v => v.size >= min_size)
|
if (min_size) files = files.filter(v => v.size >= min_size)
|
||||||
const folders = arr.filter(v => v.mimeType === FOLDER_TYPE)
|
const folders = arr.filter(v => v.mimeType === FOLDER_TYPE)
|
||||||
console.log('待複製的目錄數:', folders.length)
|
console.log('待复制的目录数:', folders.length)
|
||||||
console.log('待複製的檔案數:', files.length)
|
console.log('待复制的文件数:', files.length)
|
||||||
const mapping = await create_folders({
|
const mapping = await create_folders({
|
||||||
source,
|
source,
|
||||||
folders,
|
folders,
|
||||||
|
@ -524,6 +524,7 @@ async function real_copy ({ source, target, name, min_size, update, dncnr, not_t
|
||||||
async function copy_files ({ files, mapping, service_account, root, task_id }) {
|
async function copy_files ({ files, mapping, service_account, root, task_id }) {
|
||||||
if (!files.length) return
|
if (!files.length) return
|
||||||
console.log('\n開始複製文件,總數:', files.length)
|
console.log('\n開始複製文件,總數:', files.length)
|
||||||
|
|
||||||
const loop = setInterval(() => {
|
const loop = setInterval(() => {
|
||||||
const now = dayjs().format('HH:mm:ss')
|
const now = dayjs().format('HH:mm:ss')
|
||||||
const message = `${now} | 已複製的檔案數 ${count} | 排隊中檔案數 ${files.length}`
|
const message = `${now} | 已複製的檔案數 ${count} | 排隊中檔案數 ${files.length}`
|
||||||
|
@ -580,6 +581,7 @@ async function copy_files ({ files, mapping, service_account, root, task_id }) {
|
||||||
// }
|
// }
|
||||||
// })).finally(() => clearInterval(loop))
|
// })).finally(() => clearInterval(loop))
|
||||||
}
|
}
|
||||||
|
|
||||||
async function copy_file (id, parent, use_sa, limit, task_id) {
|
async function copy_file (id, parent, use_sa, limit, task_id) {
|
||||||
let url = `https://www.googleapis.com/drive/v3/files/${id}/copy`
|
let url = `https://www.googleapis.com/drive/v3/files/${id}/copy`
|
||||||
let params = { supportsAllDrives: true }
|
let params = { supportsAllDrives: true }
|
||||||
|
|
24
src/tg.js
24
src/tg.js
|
@ -86,7 +86,7 @@ function clear_tasks (chat_id) {
|
||||||
|
|
||||||
function rm_task ({ task_id, chat_id }) {
|
function rm_task ({ task_id, chat_id }) {
|
||||||
const exist = db.prepare('select id from task where id=?').get(task_id)
|
const exist = db.prepare('select id from task where id=?').get(task_id)
|
||||||
if (!exist) return sm({ chat_id, text: `不存在编号为 ${task_id} 的任务记录` })
|
if (!exist) return sm({ chat_id, text: `不存在任務ID為 ${task_id} 的任務紀錄` })
|
||||||
db.prepare('delete from task where id=?').run(task_id)
|
db.prepare('delete from task where id=?').run(task_id)
|
||||||
db.prepare('delete from copied where taskid=?').run(task_id)
|
db.prepare('delete from copied where taskid=?').run(task_id)
|
||||||
if (chat_id) sm({ chat_id, text: `已刪除任務 ${task_id} 紀錄` })
|
if (chat_id) sm({ chat_id, text: `已刪除任務 ${task_id} 紀錄` })
|
||||||
|
@ -211,30 +211,26 @@ async function send_all_tasks (chat_id) {
|
||||||
async function get_task_info (task_id) {
|
async function get_task_info (task_id) {
|
||||||
const record = db.prepare('select * from task where id=?').get(task_id)
|
const record = db.prepare('select * from task where id=?').get(task_id)
|
||||||
if (!record) return {}
|
if (!record) return {}
|
||||||
const { source, target, status, copied, mapping, ctime, ftime } = record
|
const { source, target, status, mapping, ctime, ftime } = record
|
||||||
|
const { copied_files } = db.prepare('select count(fileid) as copied_files from copied where taskid=?').get(task_id)
|
||||||
const folder_mapping = mapping && mapping.trim().split('\n')
|
const folder_mapping = mapping && mapping.trim().split('\n')
|
||||||
const new_folder = folder_mapping && folder_mapping[0].split(' ')[1]
|
const new_folder = folder_mapping && folder_mapping[0].split(' ')[1]
|
||||||
const { summary } = db.prepare('select summary from gd where fid=?').get(source) || {}
|
const { summary } = db.prepare('select summary from gd where fid=?').get(source) || {}
|
||||||
const { file_count, folder_count, total_size } = summary ? JSON.parse(summary) : {}
|
const { file_count, folder_count, total_size } = summary ? JSON.parse(summary) : {}
|
||||||
const copied_files = copied ? copied.trim().split('\n').length : 0
|
const total_count = (file_count || 0) + (folder_count || 0)
|
||||||
const copied_folders = folder_mapping ? (folder_mapping.length - 1) : 0
|
const copied_folders = folder_mapping ? (folder_mapping.length - 1) : 0
|
||||||
let text = '任務ID:' + task_id + '\n'
|
let text = '任務ID:' + task_id + '\n'
|
||||||
const folder_name = await get_folder_name(source)
|
const folder_name = await get_folder_name(source)
|
||||||
text += '源資料夾:' + gen_link(source, folder_name) + '\n'
|
text += '源資料夾:' + gen_link(source, folder_name) + '\n'
|
||||||
text += '目的位置:' + gen_link(target) + '\n'
|
text += '目的位置:' + gen_link(target, get_alias_by_target(target)) + '\n'
|
||||||
text += '新資料夾:' + (new_folder ? gen_link(new_folder) : '尚未創建') + '\n'
|
text += '新資料夾:' + (new_folder ? gen_link(new_folder) : '尚未創建') + '\n'
|
||||||
text += '任務狀態:' + status + '\n'
|
text += '任務狀態:' + status + '\n'
|
||||||
text += '創建時間:' + dayjs(ctime).format('YYYY-MM-DD HH:mm:ss') + '\n'
|
text += '創建時間:' + dayjs(ctime).format('YYYY-MM-DD HH:mm:ss') + '\n'
|
||||||
text += '完成時間:' + (ftime ? dayjs(ftime).format('YYYY-MM-DD HH:mm:ss') : '未完成') + '\n'
|
text += '完成時間:' + (ftime ? dayjs(ftime).format('YYYY-MM-DD HH:mm:ss') : '未完成') + '\n'
|
||||||
var pct = copied_folders/(folder_count === undefined ? '未知數量' : folder_count)*100
|
text += '目錄進度:' + copied_folders + '/' + (folder_count === undefined ? '未知數量' : folder_count) + ' - ' + (copied_folders/folder_count*100).toFixed(3) + '%\n'
|
||||||
pct = pct.toFixed(2);
|
text += '文件進度:' + copied_files + '/' + (file_count === undefined ? '未知數量' : file_count) + ' - ' + (copied_files/file_count*100).toFixed(3) + '%\n'
|
||||||
text += '目錄進度:' + copied_folders + '/' + (folder_count === undefined ? '未知數量' : folder_count) + ' - ' + pct + '%\n'
|
|
||||||
pct = copied_files/(file_count === undefined ? '未知數量' : file_count)*100
|
|
||||||
pct = pct.toFixed(2);
|
|
||||||
text += '文件進度:' + copied_files + '/' + (file_count === undefined ? '未知數量' : file_count) + ' - ' + pct + '%\n'
|
|
||||||
text += '合計大小:' + (total_size || '未知大小')
|
text += '合計大小:' + (total_size || '未知大小')
|
||||||
const total_count = (folder_count || 0) + (file_count || 0)
|
return { text, status, folder_count }
|
||||||
return { text, status, total_count }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function send_task_info ({ task_id, chat_id }) {
|
async function send_task_info ({ task_id, chat_id }) {
|
||||||
|
@ -285,9 +281,7 @@ async function tg_copy ({ fid, target, chat_id, update }) { // return task_id
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
const task_id = record && record.id
|
const task_id = record && record.id
|
||||||
if (task_id){
|
if (task_id) db.prepare('update task set status=? where id=?').run('error', task_id)
|
||||||
db.prepare('update task set status=? where id=?').run('error', task_id)
|
|
||||||
}
|
|
||||||
if (!record) record = {}
|
if (!record) record = {}
|
||||||
console.error('複製失敗', fid, '-->', target)
|
console.error('複製失敗', fid, '-->', target)
|
||||||
console.error(err)
|
console.error(err)
|
||||||
|
|
Loading…
Reference in New Issue