From 7dd12c17c81ec1e1e39d9dad58fd417f92116954 Mon Sep 17 00:00:00 2001 From: "@feng-yu4279" Date: Mon, 19 May 2025 14:43:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/ets/download/RequestDownload.ets | 12 +++++++++ .../src/main/ets/upload/RequestUpload.ets | 25 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/features/uploadanddownload/src/main/ets/download/RequestDownload.ets b/features/uploadanddownload/src/main/ets/download/RequestDownload.ets index 34aeafa..a3940f0 100644 --- a/features/uploadanddownload/src/main/ets/download/RequestDownload.ets +++ b/features/uploadanddownload/src/main/ets/download/RequestDownload.ets @@ -13,18 +13,24 @@ * limitations under the License. */ +// [Start common1] import { common } from '@kit.AbilityKit'; import { promptAction } from '@kit.ArkUI'; import { request } from '@kit.BasicServicesKit'; +// [End common1] import { logger } from '../utils/Logger'; import { TOAST_BOTTOM, TASK_MAX, TASK_PAUSE_MSG, TASK_NET_PAUSE_MSG, TASK_RESUME_MSG, TASK_NET_RESUME_MSG } from '../utils/Constants'; const TAG: string = 'RequestDownload'; let isNetPause = false; +// [Start request_down_load] class RequestDownload { private context: common.UIAbilityContext | undefined = undefined; + // [Start wait_list] private waitList: Array = []; private downloadTask: request.agent.Task | undefined = undefined; + // [End wait_list] + // [StartExclude progress_callback] progressCallback: Function | undefined = undefined; completedCallback: Function | undefined = undefined; failedCallback: Function | undefined = undefined; @@ -61,6 +67,7 @@ class RequestDownload { } } + // [Start create_background_task] async createBackgroundTask(downloadList: Array) { if (this.context === undefined) { return; @@ -80,13 +87,16 @@ class RequestDownload { gauge: true } let downTask = await request.agent.create(this.context, downloadConfig); + // [Start down_task1] await downTask.start(); + // [Start down_task1] } catch (err) { logger.error(TAG, `task err, err = ${JSON.stringify(err)}`); this.waitList.push(downloadList[i]); } } } + // [End create_background_task] async pause() { if (this.downloadTask) { @@ -203,6 +213,8 @@ class RequestDownload { } this.downloadTask = undefined; } + // [EndExclude progress_callback] } +// [End request_down_load] export const requestDownload = new RequestDownload(); \ No newline at end of file diff --git a/features/uploadanddownload/src/main/ets/upload/RequestUpload.ets b/features/uploadanddownload/src/main/ets/upload/RequestUpload.ets index 4b4e3f1..0adcc2e 100644 --- a/features/uploadanddownload/src/main/ets/upload/RequestUpload.ets +++ b/features/uploadanddownload/src/main/ets/upload/RequestUpload.ets @@ -13,9 +13,11 @@ * limitations under the License. */ +// [Start common] import { common } from '@kit.AbilityKit'; import { promptAction } from '@kit.ArkUI'; import { request } from '@kit.BasicServicesKit'; +// [End common] import { urlUtils } from '../utils/UrlUtils'; import { logger } from '../utils/Logger'; import { MediaUtils } from '../utils/MediaUtils'; @@ -24,8 +26,10 @@ import { BackgroundTaskState, UPLOAD_TOKEN, TOAST_BOTTOM, TASK_MAX } from '../ut const TAG: string = 'RequestUpload'; const HEADER: Record = { 'Content-Type': 'multipart/form-data' }; +// [Start upload] class Upload { private mediaUtils: MediaUtils = new MediaUtils(); + // [Start config] private config: request.agent.Config = { action: request.agent.Action.UPLOAD, headers: HEADER, @@ -37,10 +41,15 @@ class Upload { data: [], token: UPLOAD_TOKEN } + // [End config] private context: common.UIAbilityContext | undefined = undefined; private uploadTask: request.agent.Task | undefined = undefined; + // [Start background_task] private backgroundTask: request.agent.Task | undefined = undefined; private waitList: Array = []; + // [End background_task] + // [StartExclude upload] + progressCallback: Function | undefined = undefined; completedCallback: Function | undefined = undefined; failedCallback: Function | undefined = undefined; @@ -80,6 +89,7 @@ class Upload { } } + // [Start create_background_task] async createBackgroundTask(fileUris: Array) { if (this.context === undefined) { return; @@ -89,7 +99,9 @@ class Upload { this.config.mode = request.agent.Mode.BACKGROUND; try { this.backgroundTask = await request.agent.create(this.context, this.config); + // [Start await] await this.backgroundTask.start(); + // [End await] let state = AppStorage.get('backTaskState'); if (state === BackgroundTaskState.PAUSE) { await this.backgroundTask.pause(); @@ -99,6 +111,7 @@ class Upload { logger.error(TAG, `task err, err = ${JSON.stringify(err)}`); } } + // [End create_background_task] async uploadFiles(fileUris: Array, callback: (progress: number, isSucceed: boolean) => void): Promise { logger.info(TAG, `uploadFiles begin, ${JSON.stringify(fileUris)}`); @@ -182,8 +195,11 @@ class Upload { } } + // [Start pause] async pause() { + // [StartExclude logger] logger.info(TAG, 'pause'); + // [EndExclude logger] if (this.backgroundTask === undefined) { return; } @@ -193,9 +209,13 @@ class Upload { logger.info(TAG, `pause fail,err= ${JSON.stringify(err)}`); } } + // [End pause] + // [Start resume] async resume() { + // [StartExclude logger1] logger.info(TAG, 'resume'); + // [EndExclude logger1] if (this.backgroundTask === undefined) { return; } @@ -205,8 +225,10 @@ class Upload { logger.info(TAG, `resume fail,err= ${JSON.stringify(err)}`); } } + // [End resume] private async getFilesAndData(cacheDir: string, fileUris: Array): Promise> { + // [StartExclude get_file_sand_data] logger.info(TAG, `getFilesAndData begin`); let files: Array = []; for (let i = 0; i < fileUris.length; i++) { @@ -223,7 +245,10 @@ class Upload { } logger.info(TAG, `getFilesAndData ${JSON.stringify(files)}`); return files; + // [EndExclude get_file_sand_data] } + // [EndExclude upload] } +// [End upload] export const requestUpload = new Upload(); \ No newline at end of file -- Gitee