From 430e41adad36a14d834fa8eb93a62dbf997ea464 Mon Sep 17 00:00:00 2001 From: "blucas.wu" <15555602203@163.com> Date: Wed, 4 Dec 2024 09:41:08 +0800 Subject: [PATCH 1/3] feat(harbor): add 'onAfterUpload' param --- packages/page-spy-plugin-data-harbor/src/index.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/page-spy-plugin-data-harbor/src/index.ts b/packages/page-spy-plugin-data-harbor/src/index.ts index 20b2151a..cf85606a 100644 --- a/packages/page-spy-plugin-data-harbor/src/index.ts +++ b/packages/page-spy-plugin-data-harbor/src/index.ts @@ -46,7 +46,10 @@ interface DataHarborConfig { filename?: () => string; // Custom download behavior. - onDownload?: ((data: CacheMessageItem[]) => void) | null; + onDownload?: (data: CacheMessageItem[]) => void; + + // Custom behavior after upload. + onAfterUpload?: (replayUrl: string) => void; } const defaultConfig: Required = { @@ -61,7 +64,8 @@ const defaultConfig: Required = { filename: () => { return new Date().toLocaleString(); }, - onDownload: null, + onDownload: () => {}, + onAfterUpload: () => {}, }; export default class DataHarborPlugin implements PageSpyPlugin { @@ -285,7 +289,9 @@ export default class DataHarborPlugin implements PageSpyPlugin { } if (result) { - return this.getDebugUrl(result); + const url = this.getDebugUrl(result); + this.$harborConfig.onAfterUpload(url); + return url; } } From 57082247b3285bf43cddb29b9a5f9d3d5da00724 Mon Sep 17 00:00:00 2001 From: "blucas.wu" <15555602203@163.com> Date: Wed, 4 Dec 2024 09:46:32 +0800 Subject: [PATCH 2/3] feat(mp-harbor): add 'onAfterUpload' params --- .../page-spy-plugin-mp-data-harbor/src/index.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/page-spy-plugin-mp-data-harbor/src/index.ts b/packages/page-spy-plugin-mp-data-harbor/src/index.ts index 3f383af7..20f4f432 100644 --- a/packages/page-spy-plugin-mp-data-harbor/src/index.ts +++ b/packages/page-spy-plugin-mp-data-harbor/src/index.ts @@ -1,16 +1,11 @@ /* eslint-disable consistent-return */ import type { SpyMessage, - OnInitParams, PageSpyPlugin, PluginOrder, InitConfigBase, } from '@huolala-tech/page-spy-types'; import { removeEndSlash } from '@huolala-tech/page-spy-base/dist/utils'; -import { MemoryHarbor } from './harbor/memoryHarbor'; -import { startUpload } from './utils/upload'; -import { buildSearchParams, getDeviceId, makeData, makeFile } from './utils'; -import { DataType, WholeActionParams } from './harbor/base'; import { getMPSDK, type Client, @@ -19,6 +14,10 @@ import { MPPluginInitParams, setMPSDK, } from '@huolala-tech/page-spy-mp-base'; +import { MemoryHarbor } from './harbor/memoryHarbor'; +import { startUpload } from './utils/upload'; +import { buildSearchParams, getDeviceId, makeData, makeFile } from './utils'; +import { DataType, WholeActionParams } from './harbor/base'; interface DataHarborConfig { // Specify which types of data to collect. @@ -27,6 +26,9 @@ interface DataHarborConfig { // Custom uploaded filename by this. // Default value is `new Date().toLocaleString()`. filename?: () => string; + + // Custom behavior after upload + onAfterUpload?: (replayUrl: string) => void; } const defaultConfig: DataHarborConfig = { @@ -40,6 +42,7 @@ const defaultConfig: DataHarborConfig = { filename: () => { return new Date().toLocaleString(); }, + onAfterUpload: () => {}, }; export default class MPDataHarborPlugin implements PageSpyPlugin { @@ -120,6 +123,8 @@ export default class MPDataHarborPlugin implements PageSpyPlugin { const result = await this.upload(); mp.hideLoading(); if (result) { + this.$harborConfig.onAfterUpload(result); + if (mp.setClipboardData) { mp.showModal({ title: '上传成功', From 596a7d031c8b1921f62268960e589dac32fd54d6 Mon Sep 17 00:00:00 2001 From: "blucas.wu" <15555602203@163.com> Date: Wed, 4 Dec 2024 10:04:14 +0800 Subject: [PATCH 3/3] feat(harbor): add 'remark' in onAfterUpload --- .../page-spy-plugin-data-harbor/src/index.ts | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/packages/page-spy-plugin-data-harbor/src/index.ts b/packages/page-spy-plugin-data-harbor/src/index.ts index cf85606a..a68ff526 100644 --- a/packages/page-spy-plugin-data-harbor/src/index.ts +++ b/packages/page-spy-plugin-data-harbor/src/index.ts @@ -49,7 +49,7 @@ interface DataHarborConfig { onDownload?: (data: CacheMessageItem[]) => void; // Custom behavior after upload. - onAfterUpload?: (replayUrl: string) => void; + onAfterUpload?: (replayUrl: string, remark: string) => void; } const defaultConfig: Required = { @@ -267,30 +267,23 @@ export default class DataHarborPlugin implements PageSpyPlugin { remark: '', }, ): Promise { - let result; - if (type === 'upload' || type === 'download') { - const args: any = await this.getParams(type as any, params); - result = - type === 'upload' ? await startUpload(args) : await startDownload(args); - - if ((params as WholeActionParams).clearCache === true) { - this.clearAndNotify(); - } + if (!isPeriodActionParams(params) || params.startTime > params.endTime) { + throw new Error(t.invalidParams); } - if (type === 'upload-periods' || type === 'download-periods') { - if (!isPeriodActionParams(params) || params.startTime > params.endTime) { - throw new Error(t.invalidParams); - } - const args: any = await this.getParams(type as any, params); - result = - type === 'upload-periods' - ? await startUpload(args) - : await startDownload(args); + + const args: any = await this.getParams(type as any, params); + const isUpload = ['upload', 'upload-periods'].includes(type); + const result = isUpload + ? await startUpload(args) + : await startDownload(args); + + if ((params as WholeActionParams).clearCache === true) { + this.clearAndNotify(); } if (result) { const url = this.getDebugUrl(result); - this.$harborConfig.onAfterUpload(url); + this.$harborConfig.onAfterUpload(url, args.remark); return url; } }