From 50599a8a4d9801f904aa6e8228a55f1174389582 Mon Sep 17 00:00:00 2001 From: "1362134550@qq.com" <1362134550@qq.com> Date: Sun, 28 Sep 2025 15:49:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E4=BC=98=E5=8C=96=20=E5=8E=BB=E6=8E=89=E4=B8=8D?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E7=9A=84=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entry/build-profile.json5 | 3 - .../src/main/ets/pages/FileUploadPage.ets | 83 ----------------- .../main/ets/pages/RequestDownloadPage.ets | 55 ----------- .../main/ets/pages/UploadAndDownloadPage.ets | 93 ------------------- .../src/main/ets/pages/ZipUploadPage.ets | 3 + .../entry/src/mock/mock-config.json5 | 2 - .../src/ohosTest/ets/test/Ability.test.ets | 35 ------- .../entry/src/ohosTest/ets/test/List.test.ets | 5 - .../entry/src/ohosTest/module.json5 | 13 --- .../entry/src/test/List.test.ets | 5 - .../entry/src/test/LocalUnit.test.ets | 33 ------- .../oh-package-lock.json5 | 27 ------ 12 files changed, 3 insertions(+), 354 deletions(-) delete mode 100644 FileUploadAndDownloadSlow/entry/src/main/ets/pages/FileUploadPage.ets delete mode 100644 FileUploadAndDownloadSlow/entry/src/main/ets/pages/RequestDownloadPage.ets delete mode 100644 FileUploadAndDownloadSlow/entry/src/main/ets/pages/UploadAndDownloadPage.ets delete mode 100644 FileUploadAndDownloadSlow/entry/src/mock/mock-config.json5 delete mode 100644 FileUploadAndDownloadSlow/entry/src/ohosTest/ets/test/Ability.test.ets delete mode 100644 FileUploadAndDownloadSlow/entry/src/ohosTest/ets/test/List.test.ets delete mode 100644 FileUploadAndDownloadSlow/entry/src/ohosTest/module.json5 delete mode 100644 FileUploadAndDownloadSlow/entry/src/test/List.test.ets delete mode 100644 FileUploadAndDownloadSlow/entry/src/test/LocalUnit.test.ets delete mode 100644 FileUploadAndDownloadSlow/oh-package-lock.json5 diff --git a/FileUploadAndDownloadSlow/entry/build-profile.json5 b/FileUploadAndDownloadSlow/entry/build-profile.json5 index 4d611879..0311b505 100644 --- a/FileUploadAndDownloadSlow/entry/build-profile.json5 +++ b/FileUploadAndDownloadSlow/entry/build-profile.json5 @@ -20,9 +20,6 @@ "targets": [ { "name": "default" - }, - { - "name": "ohosTest", } ] } \ No newline at end of file diff --git a/FileUploadAndDownloadSlow/entry/src/main/ets/pages/FileUploadPage.ets b/FileUploadAndDownloadSlow/entry/src/main/ets/pages/FileUploadPage.ets deleted file mode 100644 index 38689691..00000000 --- a/FileUploadAndDownloadSlow/entry/src/main/ets/pages/FileUploadPage.ets +++ /dev/null @@ -1,83 +0,0 @@ -// [Start import_request] -import { common } from '@kit.AbilityKit'; -import { request } from '@kit.BasicServicesKit'; -// [End import_request] - -// [Start class_upload] -class Upload { - // Background tasks - private backgroundTask: request.agent.Task | undefined = undefined; - // The uri stored before creating the task - private waitList: Array = []; - // ... -} -// [End class_upload] - -@Component -struct FileUploadPage { - // [Start file_upload_page] - private config: request.agent.Config = { - action: request.agent.Action.UPLOAD, - headers: HEADER, - url: '', - mode: request.agent.Mode.BACKGROUND, - method: 'POST', - title: 'upload', - network: request.agent.Network.ANY, - data: [], - token: 'UPLOAD_TOKEN' - } - // ... - // Convert uri - private async getFilesAndData(cacheDir: string, fileUris: Array): Promise> { - // ... - } - // Create a file upload background task - async createBackgroundTask(fileUris: Array) { - if (this.context === undefined) { - return; - } - // Get the upload URL - this.config.url = await urlUtils.getUrl(this.context); - this.config.data = await this.getFilesAndData(this.context.cacheDir, fileUris); - this.config.mode = request.agent.Mode.BACKGROUND; - try { - this.backgroundTask = await request.agent.create(this.context, this.config); - // [Start background_task_start] - await this.backgroundTask.start(); - // [End background_task_start] - let state = AppStorage.get('backTaskState'); - if (state === BackgroundTaskState.PAUSE) { - await this.backgroundTask.pause(); - } - logger.info(TAG, `createBackgroundTask success`); - } catch (err) { - logger.error(TAG, `task err, err = ${JSON.stringify(err)}`); - } - } - // [End file_upload_page] - - // [Start background_task_pause] - async pause() { - // ... - if (this.backgroundTask === undefined) { - return; - } - await this.backgroundTask.pause(); - } - // [End background_task_pause] - - // [Start background_task_resume] - async resume() { - // ... - if (this.backgroundTask === undefined) { - return; - } - await this.backgroundTask.resume(); - } - // [End background_task_resume] - - build() { - - } -} \ No newline at end of file diff --git a/FileUploadAndDownloadSlow/entry/src/main/ets/pages/RequestDownloadPage.ets b/FileUploadAndDownloadSlow/entry/src/main/ets/pages/RequestDownloadPage.ets deleted file mode 100644 index 3a0f384a..00000000 --- a/FileUploadAndDownloadSlow/entry/src/main/ets/pages/RequestDownloadPage.ets +++ /dev/null @@ -1,55 +0,0 @@ -// [Start import_request_download] -import { common } from '@kit.AbilityKit'; -import { request } from '@kit.BasicServicesKit'; -// [End import_request_download] - -// [Start request_download] -class RequestDownload { - // Uri before the task is stored - private waitList: Array = []; - // Uri before the task is stored - private downloadTask: request.agent.Task | undefined = undefined; - // ... -} -// [End request_download] - -@Component -struct RequestDownloadPage { - // [Start request_download_page] - async createBackgroundTask(downloadList: Array) { - if (this.context === undefined) { - return; - } - for (let i = 0; i < downloadList.length; i++) { - try { - let splitUrl = downloadList[i][1].split('//')[1].split('/'); - let downloadConfig: request.agent.Config = { - action: request.agent.Action.DOWNLOAD, - url: downloadList[i][1], - method: 'POST', - title: 'download', - mode: request.agent.Mode.BACKGROUND, // It must be a background task to continue. - network: request.agent.Network.ANY, - saveas: `./${downloadList[i][0]}/${splitUrl[splitUrl.length-1]}`, - overwrite: true, - gauge: true - } - let downTask = await request.agent.create(this.context, downloadConfig); - // [Start down_task_start] - // [StartExclude down_task_start] - // [EndExclude down_task_start] - await downTask.start(); - // [StartExclude down_task_start] - // [EndExclude down_task_start] - // [End down_task_start] - } catch (err) { - logger.error(TAG, `task err, err = ${JSON.stringify(err)}`); - this.waitList.push(downloadList[i]); - } - } - } - // [End request_download_page] - build() { - - } -} \ No newline at end of file diff --git a/FileUploadAndDownloadSlow/entry/src/main/ets/pages/UploadAndDownloadPage.ets b/FileUploadAndDownloadSlow/entry/src/main/ets/pages/UploadAndDownloadPage.ets deleted file mode 100644 index 0dfec90f..00000000 --- a/FileUploadAndDownloadSlow/entry/src/main/ets/pages/UploadAndDownloadPage.ets +++ /dev/null @@ -1,93 +0,0 @@ -// [Start create_config] -let config: request.agent.Config = { - action: request.agent.Action.DOWNLOAD, // Configure task options, which are configured as download tasks. - url: downloadUrl, // Configure the download task url - overwrite: true, // Solution selection when the path already exists during the download process. True means overwriting existing files. - method: 'GET', // HTTP standard method. When downloading, use GET or POST - saveas: './', // Here'. /' indicates that the download is downloaded to the current cache path of the application. - mode: request.agent.Mode.BACKGROUND, // Task mode setting background tasks - gauge: true // The process progress notification strategy of background tasks is only applicable to background tasks. True means to send a notification that each progress has been completed or failed. -}; -// [End create_config] - -@Component -struct UploadAndDownloadPage { - - create() { - // [Start request_agent_create] - request.agent.create(context, this.downloadConfig).then((task: request.agent.Task) => { - // Callbacks related to the registration download task - task.on('completed', this.completedCallback); // Complete the callback - task.on('failed', this.failedCallback); // Failed callback - task.on('pause', this.pauseCallback); // Pause the callback - task.on('resume', this.resumeCallback); // Restart the callback - task.on('progress', this.progressCallback); // Progress update callback - task.on('response', this.progressCallback); // Response header data callback - }).catch((err: BusinessError) => { - logger.error(TAG, `Failed to task create with error message: ${err.message}, error code: ${err.code}`); - }); - // [End request_agent_create] - } - - start() { - // [Start task_start] - task.start().then(() => { - this.downloadTask = task; - }).catch((err: Error) => { - logger.error(TAG, 'task start error:', err); - }) - // [End task_start] - } - - // [Start file_download_item] - FileDownloadItem() { - // Determine whether the current download task status meets the pause conditions - if (this.downloadTask && (taskInfo.progress.state === request.agent.State.WAITING || taskInfo.progress.state - === request.agent.State.RUNNING || taskInfo.progress.state === request.agent.State.RETRYING)) { - this.downloadTask.pause().then(() => { - }).catch((err: Error) => { - logger.error(TAG, 'task pause error:', err); - }); - } - - // Determine if the task is suspended, restart the download task. - if (this.downloadTask && taskInfo.progress.state === request.agent.State.PAUSED) { - this.downloadTask.resume().then(() => { - }).catch((err: Error) => { - logger.error(TAG, 'task resume error:', err); - }); - } - } - // [End file_download_item] - - - // [Start request_agent_create] - private completedCallback = (progress: request.agent.Progress) => { - // The download status is set to download completion. - this.state = "下载完成"; - if (this.sFileSize === '未知大小') { - this.nCurrentDownloadSize = 1; - } - // The file download is completed, and the number of tasks to be downloaded will be reduced by 1 - this.downloadCount--; - this.isShow = false; - } - // [End request_agent_create] - - build() { - Column() { - // [Start download_config_array] - ForEach(this.downloadConfigArray, (item: request.agent.Config) => { - ListItem() { - // Create a file download monitoring instance - FileDownloadItem({ - downloadConfig: item, // File download configuration - isStartAllDownload: this.isStartAllDownload, // Do you start downloading all? - downloadCount: this.downloadCount // Number of tasks to be downloaded - }) - } - }, (item: request.agent.Config) => JSON.stringify(item)) - // [End download_config_array] - } - } -} \ No newline at end of file diff --git a/FileUploadAndDownloadSlow/entry/src/main/ets/pages/ZipUploadPage.ets b/FileUploadAndDownloadSlow/entry/src/main/ets/pages/ZipUploadPage.ets index 24e3d55d..29f0002b 100644 --- a/FileUploadAndDownloadSlow/entry/src/main/ets/pages/ZipUploadPage.ets +++ b/FileUploadAndDownloadSlow/entry/src/main/ets/pages/ZipUploadPage.ets @@ -16,6 +16,9 @@ class ZipUpload { @Component struct ZipUploadPage { + private context: common.UIAbilityContext | undefined = undefined; + private waitList: Array = []; + // [Start zip_upload_page] // Data compression processing async zipUploadFiles(fileUris: Array): Promise { diff --git a/FileUploadAndDownloadSlow/entry/src/mock/mock-config.json5 b/FileUploadAndDownloadSlow/entry/src/mock/mock-config.json5 deleted file mode 100644 index 7a73a41b..00000000 --- a/FileUploadAndDownloadSlow/entry/src/mock/mock-config.json5 +++ /dev/null @@ -1,2 +0,0 @@ -{ -} \ No newline at end of file diff --git a/FileUploadAndDownloadSlow/entry/src/ohosTest/ets/test/Ability.test.ets b/FileUploadAndDownloadSlow/entry/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100644 index 85c78f67..00000000 --- a/FileUploadAndDownloadSlow/entry/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,35 +0,0 @@ -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; - -export default function abilityTest() { - describe('ActsAbilityTest', () => { - // Defines a test suite. Two parameters are supported: test suite name and test suite function. - beforeAll(() => { - // Presets an action, which is performed only once before all test cases of the test suite start. - // This API supports only one parameter: preset action function. - }) - beforeEach(() => { - // Presets an action, which is performed before each unit test case starts. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: preset action function. - }) - afterEach(() => { - // Presets a clear action, which is performed after each unit test case ends. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: clear action function. - }) - afterAll(() => { - // Presets a clear action, which is performed after all test cases of the test suite end. - // This API supports only one parameter: clear action function. - }) - it('assertContain', 0, () => { - // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. - hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); - let a = 'abc'; - let b = 'b'; - // Defines a variety of assertion methods, which are used to declare expected boolean conditions. - expect(a).assertContain(b); - expect(a).assertEqual(a); - }) - }) -} \ No newline at end of file diff --git a/FileUploadAndDownloadSlow/entry/src/ohosTest/ets/test/List.test.ets b/FileUploadAndDownloadSlow/entry/src/ohosTest/ets/test/List.test.ets deleted file mode 100644 index 794c7dc4..00000000 --- a/FileUploadAndDownloadSlow/entry/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,5 +0,0 @@ -import abilityTest from './Ability.test'; - -export default function testsuite() { - abilityTest(); -} \ No newline at end of file diff --git a/FileUploadAndDownloadSlow/entry/src/ohosTest/module.json5 b/FileUploadAndDownloadSlow/entry/src/ohosTest/module.json5 deleted file mode 100644 index 55725a92..00000000 --- a/FileUploadAndDownloadSlow/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,13 +0,0 @@ -{ - "module": { - "name": "entry_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/FileUploadAndDownloadSlow/entry/src/test/List.test.ets b/FileUploadAndDownloadSlow/entry/src/test/List.test.ets deleted file mode 100644 index bb5b5c37..00000000 --- a/FileUploadAndDownloadSlow/entry/src/test/List.test.ets +++ /dev/null @@ -1,5 +0,0 @@ -import localUnitTest from './LocalUnit.test'; - -export default function testsuite() { - localUnitTest(); -} \ No newline at end of file diff --git a/FileUploadAndDownloadSlow/entry/src/test/LocalUnit.test.ets b/FileUploadAndDownloadSlow/entry/src/test/LocalUnit.test.ets deleted file mode 100644 index 165fc161..00000000 --- a/FileUploadAndDownloadSlow/entry/src/test/LocalUnit.test.ets +++ /dev/null @@ -1,33 +0,0 @@ -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; - -export default function localUnitTest() { - describe('localUnitTest', () => { - // Defines a test suite. Two parameters are supported: test suite name and test suite function. - beforeAll(() => { - // Presets an action, which is performed only once before all test cases of the test suite start. - // This API supports only one parameter: preset action function. - }); - beforeEach(() => { - // Presets an action, which is performed before each unit test case starts. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: preset action function. - }); - afterEach(() => { - // Presets a clear action, which is performed after each unit test case ends. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: clear action function. - }); - afterAll(() => { - // Presets a clear action, which is performed after all test cases of the test suite end. - // This API supports only one parameter: clear action function. - }); - it('assertContain', 0, () => { - // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. - let a = 'abc'; - let b = 'b'; - // Defines a variety of assertion methods, which are used to declare expected boolean conditions. - expect(a).assertContain(b); - expect(a).assertEqual(a); - }); - }); -} \ No newline at end of file diff --git a/FileUploadAndDownloadSlow/oh-package-lock.json5 b/FileUploadAndDownloadSlow/oh-package-lock.json5 deleted file mode 100644 index 7fcf8182..00000000 --- a/FileUploadAndDownloadSlow/oh-package-lock.json5 +++ /dev/null @@ -1,27 +0,0 @@ -{ - "meta": { - "stableOrder": true - }, - "lockfileVersion": 3, - "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", - "specifiers": { - "@ohos/hamock@1.0.0": "@ohos/hamock@1.0.0", - "@ohos/hypium@1.0.21": "@ohos/hypium@1.0.21" - }, - "packages": { - "@ohos/hamock@1.0.0": { - "name": "@ohos/hamock", - "version": "1.0.0", - "integrity": "sha512-K6lDPYc6VkKe6ZBNQa9aoG+ZZMiwqfcR/7yAVFSUGIuOAhPvCJAo9+t1fZnpe0dBRBPxj2bxPPbKh69VuyAtDg==", - "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hamock/-/hamock-1.0.0.har", - "registryType": "ohpm" - }, - "@ohos/hypium@1.0.21": { - "name": "@ohos/hypium", - "version": "1.0.21", - "integrity": "sha512-iyKGMXxE+9PpCkqEwu0VykN/7hNpb+QOeIuHwkmZnxOpI+dFZt6yhPB7k89EgV1MiSK/ieV/hMjr5Z2mWwRfMQ==", - "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hypium/-/hypium-1.0.21.har", - "registryType": "ohpm" - } - } -} \ No newline at end of file -- Gitee