perf: 🚀 Support file manager upload to the current directory

This commit is contained in:
viarotel 2024-09-08 03:10:30 +08:00
parent f5206b5bd9
commit 737c2a36e2
8 changed files with 26 additions and 23 deletions

View File

@ -225,10 +225,13 @@ async function readdir(id, filePath) {
} }
async function push(id, filePath, args = {}) { async function push(id, filePath, args = {}) {
const { progress, savePath = `/sdcard/Download/${path.basename(filePath)}` } const { progress, savePath = '/sdcard/Download' } = args
= args
const transfer = await client.getDevice(id).push(filePath, savePath) const fileName = path.basename(filePath)
const fullSavePath = `${savePath}/${fileName}`.replace(/\/+/g, '/')
const transfer = await client.getDevice(id).push(filePath, fullSavePath)
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
transfer.on('progress', (stats) => { transfer.on('progress', (stats) => {
@ -236,7 +239,7 @@ async function push(id, filePath, args = {}) {
}) })
transfer.on('end', () => { transfer.on('end', () => {
resolve(savePath) resolve(fullSavePath)
}) })
transfer.on('error', (err) => { transfer.on('error', (err) => {
@ -246,8 +249,11 @@ async function push(id, filePath, args = {}) {
} }
async function pull(id, filePath, args = {}) { async function pull(id, filePath, args = {}) {
const { progress, savePath = path.resolve('../', path.basename(filePath)) } const { progress, savePath = '../' } = args
= args
const fileName = path.basename(filePath)
const fullSavePath = path.resolve(savePath, fileName)
const transfer = await client.getDevice(id).pull(filePath) const transfer = await client.getDevice(id).pull(filePath)
@ -257,14 +263,14 @@ async function pull(id, filePath, args = {}) {
}) })
transfer.on('end', () => { transfer.on('end', () => {
resolve(savePath) resolve(fullSavePath)
}) })
transfer.on('error', (err) => { transfer.on('error', (err) => {
reject(err) reject(err)
}) })
transfer.pipe(fs.createWriteStream(savePath)) transfer.pipe(fs.createWriteStream(fullSavePath))
}) })
} }

View File

@ -33,6 +33,7 @@ export default antfu(
'antfu/top-level-function': 'off', 'antfu/top-level-function': 'off',
'import/default': 'off', 'import/default': 'off',
'import/order': 'off',
'node/prefer-global/process': 'off', 'node/prefer-global/process': 'off',

View File

@ -168,9 +168,7 @@
<script setup> <script setup>
import { useDialog, useFileActions } from '$/composables/index.js' import { useDialog, useFileActions } from '$/composables/index.js'
import { usePreferenceStore } from '$/store' import { usePreferenceStore } from '$/store'
import { ElMessageBox } from 'element-plus' import { ElMessageBox } from 'element-plus'
import AddPopover from './AddPopover/index.vue' import AddPopover from './AddPopover/index.vue'
const preferenceStore = usePreferenceStore() const preferenceStore = usePreferenceStore()
@ -288,7 +286,10 @@ async function handleRemove(row) {
} }
async function handleUpload() { async function handleUpload() {
await fileActions.send(device.value) await fileActions.send(device.value, {
savePath: currentPath.value,
})
getTableData() getTableData()
} }
@ -312,18 +313,13 @@ async function handleDownload(row) {
.filter(item => item.type === 'file') .filter(item => item.type === 'file')
.map(item => item.id) .map(item => item.id)
const deviceConfig = preferenceStore.getData(device.value.id) const savePath = preferenceStore.getData(device.value.id)?.savePath
const closeLoading = ElMessage.loading(window.t('common.downloading')).close const closeLoading = ElMessage.loading(window.t('common.downloading')).close
for (let index = 0; index < pathList.length; index++) { for (let index = 0; index < pathList.length; index++) {
const item = pathList[index] const item = pathList[index]
const savePath = window.nodePath.resolve(
deviceConfig.savePath,
window.nodePath.basename(item),
)
await window.adbkit await window.adbkit
.pull(device.value.id, item, { savePath }) .pull(device.value.id, item, { savePath })
.catch(e => console.warn(e?.message)) .catch(e => console.warn(e?.message))

View File

@ -41,7 +41,7 @@ export function useFileActions() {
} }
} }
async function singleSend(device, { files, silent = false } = {}) { async function singleSend(device, { savePath, files, silent = false } = {}) {
if (!files) { if (!files) {
try { try {
files = await selectFiles() files = await selectFiles()
@ -68,7 +68,7 @@ export function useFileActions() {
let failCount = 0 let failCount = 0
await allSettledWrapper(files, (item) => { await allSettledWrapper(files, (item) => {
return window.adbkit.push(device.id, item).catch(() => { return window.adbkit.push(device.id, item, { savePath }).catch(() => {
++failCount ++failCount
}) })
}) })

View File

@ -141,7 +141,7 @@
"device.control.file.push.loading": "Push file...", "device.control.file.push.loading": "Push file...",
"device.control.file.push.success.name": "Push files successfully", "device.control.file.push.success.name": "Push files successfully",
"device.control.file.push.success": "Successfully pushed {totalCount} files to {deviceName}, {successCount} succeeded, and {failCount} failed", "device.control.file.push.success": "Successfully pushed {totalCount} files to {deviceName}, {successCount} succeeded, and {failCount} failed",
"device.control.file.push.success.single": "Files successfully pushed to the /sdcard/Download/ directory of {deviceName}", "device.control.file.push.success.single": "Files successfully pushed to {deviceName}",
"device.control.file.push.error": "Failed to push the file, please check the file and try again", "device.control.file.push.error": "Failed to push the file, please check the file and try again",
"device.control.file.manager.storage": "Internal Storage", "device.control.file.manager.storage": "Internal Storage",
"device.control.file.manager.add": "New Folder", "device.control.file.manager.add": "New Folder",

View File

@ -141,7 +141,7 @@
"device.control.file.push.loading": "推送文件中...", "device.control.file.push.loading": "推送文件中...",
"device.control.file.push.success.name": "推送文件成功", "device.control.file.push.success.name": "推送文件成功",
"device.control.file.push.success": "已成功将 {totalCount} 个文件推送到 {deviceName}{successCount} 成功,{failCount} 失败。", "device.control.file.push.success": "已成功将 {totalCount} 个文件推送到 {deviceName}{successCount} 成功,{failCount} 失败。",
"device.control.file.push.success.single": "文件已成功推送到 {deviceName} 的 /sdcard/Download/ 目录", "device.control.file.push.success.single": "文件已成功推送到 {deviceName}",
"device.control.file.push.error": "推送文件失败,请检查文件后重试", "device.control.file.push.error": "推送文件失败,请检查文件后重试",
"device.control.file.manager.storage": "内部存储空间", "device.control.file.manager.storage": "内部存储空间",
"device.control.file.manager.add": "新建文件夹", "device.control.file.manager.add": "新建文件夹",

View File

@ -141,7 +141,7 @@
"device.control.file.push.loading": "推送檔案中...", "device.control.file.push.loading": "推送檔案中...",
"device.control.file.push.success.name": "推送檔案成功", "device.control.file.push.success.name": "推送檔案成功",
"device.control.file.push.success": "已成功將 {totalCount} 個檔案推送到 {deviceName}{successCount} 成功,{failCount} 失敗。", "device.control.file.push.success": "已成功將 {totalCount} 個檔案推送到 {deviceName}{successCount} 成功,{failCount} 失敗。",
"device.control.file.push.success.single": "檔案已成功推送到 {deviceName} 的 /sdcard/Download/ 目錄", "device.control.file.push.success.single": "檔案已成功推送到 {deviceName}",
"device.control.file.push.error": "推送檔案失敗,請檢查檔案後重試", "device.control.file.push.error": "推送檔案失敗,請檢查檔案後重試",
"device.control.file.manager.storage": "內部儲存空間", "device.control.file.manager.storage": "內部儲存空間",
"device.control.file.manager.add": "新增資料夾", "device.control.file.manager.add": "新增資料夾",

View File

@ -1,5 +1,6 @@
import { replaceIP, restoreIP } from '$/utils/index.js' import { replaceIP, restoreIP } from '$/utils/index.js'
import { cloneDeep, get, pickBy, set } from 'lodash-es' import { cloneDeep, get, pickBy, set } from 'lodash-es'
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import { import {
@ -10,7 +11,6 @@ import {
mergeConfig, mergeConfig,
setStoreData, setStoreData,
} from './helpers/index.js' } from './helpers/index.js'
import model from './model/index.js' import model from './model/index.js'
const { adbPath, scrcpyPath, gnirehtetPath } = window.electron?.configs || {} const { adbPath, scrcpyPath, gnirehtetPath } = window.electron?.configs || {}