Style fix.

This commit is contained in:
marko1616 2024-08-22 05:42:00 +08:00
parent fdda602a76
commit b0dcc5f9df
4 changed files with 25 additions and 20 deletions

View File

@ -22,7 +22,7 @@ export interface MessageBoxResult {
export abstract class FileTransfer { export abstract class FileTransfer {
abstract getName (): string abstract getName (): string
abstract getRelativePath (): string abstract getRelativePath (): string | null
abstract getMode (): number abstract getMode (): number
abstract getSize (): number abstract getSize (): number
abstract close (): void abstract close (): void
@ -204,8 +204,8 @@ export class HTMLFileUpload extends FileUpload {
return this.file.name return this.file.name
} }
getRelativePath (): string { getRelativePath (): null {
return '' return null
} }
getMode (): number { getMode (): number {

View File

@ -226,16 +226,17 @@ export class ElectronPlatformService extends PlatformService {
} }
if(options.directory) { if(options.directory) {
let allFiles: string[] = [] let fileInfos: { fullPath: string, relativePath: string }[] = []
let relativePaths: string[] = []
for (const folderPath of paths) { for (const folderPath of paths) {
const files = await this.getAllFiles(folderPath) const files = await this.getAllFiles(folderPath)
allFiles = allFiles.concat(files) fileInfos = fileInfos.concat(files.map(file => ({
relativePaths = relativePaths.concat(files.map(file => path.posix.join(path.basename(folderPath), path.posix.relative(folderPath, file)))) fullPath: file,
relativePath: path.posix.join(path.basename(folderPath), path.posix.relative(folderPath, file))
})))
} }
return Promise.all(allFiles.map(async (p, index) => { return Promise.all(fileInfos.map(async (fileInfo) => {
const transfer = new ElectronFileUpload(p, this.electron, relativePaths[index]) const transfer = new ElectronFileUpload(fileInfo.fullPath, this.electron, fileInfo.relativePath)
await wrapPromise(this.zone, transfer.open()) await wrapPromise(this.zone, transfer.open())
this.fileTransferStarted.next(transfer) this.fileTransferStarted.next(transfer)
return transfer return transfer
@ -363,8 +364,8 @@ class ElectronFileDownload extends FileDownload {
return path.basename(this.filePath) return path.basename(this.filePath)
} }
getRelativePath (): string { getRelativePath (): null {
return '' return null
} }
getMode (): number { getMode (): number {

View File

@ -187,25 +187,29 @@ export class SFTPPanelComponent {
async uploadOneWithFolder (transfer: FileUpload): Promise<void> { async uploadOneWithFolder (transfer: FileUpload): Promise<void> {
const savedPath = this.path const savedPath = this.path
const RelativePath = transfer.getRelativePath()
if (RelativePath == null){
return
}
try { try {
await this.sftp.stat(path.join(this.path, transfer.getRelativePath())) await this.sftp.stat(path.join(this.path, RelativePath))
} catch (e) { } catch (e) {
if (e instanceof Error && e.message.includes('No such file')) { if (e instanceof Error && e.message.includes('No such file')) {
let accumPath = '' let accumPath = ''
for (const pathParts of path.posix.dirname(transfer.getRelativePath()).split(path.posix.sep)) { for (const pathParts of path.posix.dirname(RelativePath).split(path.posix.sep)) {
accumPath = path.posix.join(accumPath, pathParts) accumPath = path.posix.join(accumPath, pathParts)
this.sftp.mkdir(path.join(this.path, accumPath)).then(() => { try {
this.notifications.notice('The directory was created successfully') await this.sftp.mkdir(path.join(this.path, accumPath))
}).catch(() => { } catch (e) {
// Intentionally ignoring errors from making duplicate dirs. // Intentionally ignoring errors from making duplicate dirs.
}) }
} }
} else { } else {
throw e throw e
} }
} }
await this.sftp.upload(path.join(this.path, transfer.getRelativePath()), transfer) await this.sftp.upload(path.join(this.path, RelativePath), transfer)
if (this.path === savedPath) { if (this.path === savedPath) {
await this.navigate(this.path) await this.navigate(this.path)
} }

View File

@ -159,8 +159,8 @@ class HTMLFileDownload extends FileDownload {
return this.name return this.name
} }
getRelativePath (): string { getRelativePath (): null {
return '' return null
} }
getMode (): number { getMode (): number {