Skip to content

Commit

Permalink
fix mp data harbor upload result url
Browse files Browse the repository at this point in the history
  • Loading branch information
qkang07 committed Nov 29, 2024
1 parent 5414c0f commit 7538c6a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions packages/page-spy-plugin-mp-data-harbor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,24 +174,25 @@ 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();
this.$socketStore?.dispatchEvent('harbor-clear', null);
}
} catch (e: any) {
psLog.error(e);
return '';
}
// remove the local file
const fs = mp.getFileSystemManager();
fs.unlinkSync(path);
return url;
return debugUrl;
}

onReset() {
Expand Down Expand Up @@ -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}`;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<H.UploadResult>((resolve, reject) => {
const mp = getMPSDK();
mp.uploadFile({
filePath: path,
Expand Down

0 comments on commit 7538c6a

Please sign in to comment.