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 503ecd93..1fd0743f 100644 --- a/packages/page-spy-plugin-mp-data-harbor/src/index.ts +++ b/packages/page-spy-plugin-mp-data-harbor/src/index.ts @@ -174,11 +174,13 @@ export default class MPDataHarborPlugin implements PageSpyPlugin { const path = makeFile(data, filename()); const url = `${this.apiBase}/api/v1/log/upload?${buildSearchParams(tags)}`; + let debugUrl = ''; try { - await startUpload({ + const res = await startUpload({ path, url, }); + debugUrl = this.getDebugUrl(res); if (params?.clearCache !== false) { this.harbor.clear(); @@ -186,12 +188,11 @@ export default class MPDataHarborPlugin implements PageSpyPlugin { } } catch (e: any) { psLog.error(e); - return ''; } // remove the local file const fs = mp.getFileSystemManager(); fs.unlinkSync(path); - return url; + return debugUrl; } onReset() { @@ -252,4 +253,12 @@ export default class MPDataHarborPlugin implements PageSpyPlugin { data: clientInfo, }; } + + getDebugUrl(result: H.UploadResult | null) { + if (!result || !result.success) return ''; + + const debugOrigin = `${this.apiBase}/#/replay`; + const logUrl = `${this.apiBase}/api/v1/log/download?fileId=${result.data.fileId}`; + return `${debugOrigin}?url=${logUrl}`; + } } diff --git a/packages/page-spy-plugin-mp-data-harbor/src/utils/upload.ts b/packages/page-spy-plugin-mp-data-harbor/src/utils/upload.ts index 2e2b6bff..de83a446 100644 --- a/packages/page-spy-plugin-mp-data-harbor/src/utils/upload.ts +++ b/packages/page-spy-plugin-mp-data-harbor/src/utils/upload.ts @@ -9,7 +9,7 @@ export type UploadArgs = { declare var uni: any; export const startUpload = async ({ url, path }: UploadArgs) => { - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { const mp = getMPSDK(); mp.uploadFile({ filePath: path,