Skip to content

Commit

Permalink
[CP-2148][Files Manager] Center doesn't stops uploading files after d…
Browse files Browse the repository at this point in the history
…evice disconecting (#1389)
  • Loading branch information
OskarMichalkiewicz authored and dkarski committed Sep 27, 2023
1 parent 7c1656c commit 5355ca6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export class FileUploadCommand extends BaseCommand {
): Promise<ResultObject<undefined>> {
let data: Buffer | Uint8Array
const maxFileSize = 2000000000

try {
const fileSize = await this.fileSystemService.getFileSize(filePath)
if (fileSize >= maxFileSize) {
Expand Down Expand Up @@ -112,6 +111,9 @@ export class FileUploadCommand extends BaseCommand {
chunkNo,
data: chunkedBuffer.toString("base64"),
},
options: {
connectionTimeOut: 5000,
},
})

if (!response.ok) {
Expand Down
84 changes: 37 additions & 47 deletions packages/app/src/files-manager/services/file-manager.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,43 +54,38 @@ export class FileManagerService {
directory,
filePaths,
}: UploadFilesInput): Promise<ResultObject<string[] | undefined>> {
const results = []

for await (const filePath of filePaths) {
results.push(await this.fileUploadCommand.exec(directory, filePath))
}

const success = results.every((result) => result.ok)
const noSpaceLeft = results.some(
(result) => result.error?.type === DeviceFileSystemError.NoSpaceLeft
)
const unsupportedFileSize = results.some(
(result) =>
result.error?.type === DeviceFileSystemError.UnsupportedFileSize
)

if (noSpaceLeft) {
return Result.failed(
new AppError(
FilesManagerError.NotEnoughSpace,
"Not enough space on your device"
for (const filePath of filePaths) {
try {
const { error, ok } = await this.fileUploadCommand.exec(
directory,
filePath
)
)
}

if (unsupportedFileSize) {
return Result.failed(
new AppError(
FilesManagerError.UnsupportedFileSize,
"Unsupported file size"
if (error?.type === DeviceFileSystemError.NoSpaceLeft) {
return Result.failed(
new AppError(
FilesManagerError.NotEnoughSpace,
"Not enough space on your device"
)
)
}
if (error?.type === DeviceFileSystemError.UnsupportedFileSize) {
return Result.failed(
new AppError(
FilesManagerError.UnsupportedFileSize,
"Unsupported file size"
)
)
}
if (!ok) {
return Result.failed(
new AppError(FilesManagerError.UploadFiles, "Upload failed")
)
}
} catch (error) {
return Result.failed(
new AppError(FilesManagerError.UploadFiles, "Upload failed")
)
)
}

if (!success) {
return Result.failed(
new AppError(FilesManagerError.UploadFiles, "Upload failed")
)
}
}

return Result.success(filePaths)
Expand All @@ -99,18 +94,13 @@ export class FileManagerService {
public async deleteFiles(
filePaths: string[]
): Promise<ResultObject<string[] | undefined>> {
const results = []

for await (const filePath of filePaths) {
results.push(await this.fileDeleteCommand.exec(filePath))
}

const success = results.every((result) => result.ok)

if (!success) {
return Result.failed(
new AppError(FilesManagerError.DeleteFiles, "Delete failed")
)
for (const filePath of filePaths) {
const { ok } = await this.fileDeleteCommand.exec(filePath)
if (!ok) {
return Result.failed(
new AppError(FilesManagerError.DeleteFiles, "Delete failed")
)
}
}

return Result.success(filePaths)
Expand Down

0 comments on commit 5355ca6

Please sign in to comment.