Skip to content

Commit

Permalink
Merge pull request #118 from HuolalaTech/fix/mp-data-harbor
Browse files Browse the repository at this point in the history
Fix/mp data harbor
  • Loading branch information
qkang07 authored Dec 5, 2024
2 parents a841840 + 7538c6a commit 56fbb51
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 14 additions & 4 deletions packages/page-spy-plugin-mp-data-harbor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ export default class MPDataHarborPlugin implements PageSpyPlugin {
config,
);
} else {
const apiScheme = !enableSSL ? 'http://' : 'https://';
// because this plugin is mainly used in mp, so align with mp sdk, default to https
const apiScheme = enableSSL === false ? 'http://' : 'https://';
this.apiBase = removeEndSlash(`${apiScheme}${api}`);
}

Expand Down Expand Up @@ -178,24 +179,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 @@ -256,4 +258,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 56fbb51

Please sign in to comment.