Basic folder upload for sftp electron.

This commit is contained in:
marko1616
2024-08-21 13:50:25 +08:00
parent 3f0b78edd0
commit deaa529c07
7 changed files with 97 additions and 11 deletions

View File

@@ -25,6 +25,10 @@
i.fas.fa-upload.me-1
div(translate) Upload
button.btn.btn-link.btn-sm.flex-shrink-0.d-flex((click)='uploadFolder()')
i.fas.fa-upload.me-1
div(translate) Upload Folder
button.btn.btn-link.text-decoration-none((click)='close()') !{require('../../../tabby-core/src/icons/times.svg')}
.body(dropZone, (transfer)='uploadOne($event)')

View File

@@ -176,10 +176,40 @@ export class SFTPPanelComponent {
}
async upload (): Promise<void> {
const transfers = await this.platform.startUpload({ multiple: true })
const transfers = await this.platform.startUpload({ multiple: true, directory: false })
await Promise.all(transfers.map(t => this.uploadOne(t)))
}
async uploadFolder (): Promise<void> {
const transfers = await this.platform.startUpload({ multiple: true, directory: true })
await Promise.all(transfers.map(t => this.uploadOneWithFolder(t)))
}
async uploadOneWithFolder (transfer: FileUpload): Promise<void> {
const savedPath = this.path
try {
await this.sftp.stat(path.join(this.path, transfer.getRelativePath()))
} catch (e) {
if (e instanceof Error && e.message.includes('No such file')) {
let accumPath = ""
for (const pathParts of path.posix.dirname(transfer.getRelativePath()).split(path.posix.sep)) {
accumPath = path.posix.join(accumPath,pathParts)
this.sftp.mkdir(path.join(this.path, accumPath)).then(() => {
this.notifications.notice('The directory was created successfully')
}).catch(() => {})
}
} else {
console.log("THROW HERE")
throw e;
}
}
await this.sftp.upload(path.join(this.path, transfer.getRelativePath()), transfer)
if (this.path === savedPath) {
await this.navigate(this.path)
}
}
async uploadOne (transfer: FileUpload): Promise<void> {
const savedPath = this.path
await this.sftp.upload(path.join(this.path, transfer.getName()), transfer)