Skip to content

Commit

Permalink
fix: resolve the bug of window.blocklet not exist (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
FireTable authored Sep 7, 2023
1 parent 4b8d0e1 commit b87fdcd
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 7 deletions.
4 changes: 4 additions & 0 deletions packages/uploader/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.0.6 (September 07, 2023)

- fix: resolve the bug of window.blocklet not exist

## 0.0.5 (September 06, 2023)

- chore: update deps
Expand Down
2 changes: 1 addition & 1 deletion packages/uploader/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@blocklet/uploader",
"version": "0.0.5",
"version": "0.0.6",
"description": "blocklet upload component",
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/uploader/src/react/plugins/uploaded.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Uploaded extends UIPlugin {
this.uploadedAPIData.loading = true;
this.uploadedAPIData.page += 1;

const folderId = (window.blocklet?.componentId || '').split('/').pop();
const folderId = (window?.blocklet?.componentId || '').split('/').pop();

// use image-bin uploads api, so can hard code /api/uploads
const { data } = await api.get(`/api/uploads`, {
Expand Down
5 changes: 4 additions & 1 deletion packages/uploader/src/react/uploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ function useUploader(props: UploaderProps) {
req.setHeader('x-uploader-file-ext', `${ext}`);

// @ts-ignore get folderId when upload using
req.setHeader('x-component-did', (window.blocklet?.componentId || '').split('/').pop());
if (window?.blocklet?.componentId) {
// @ts-ignore
req.setHeader('x-component-did', (window.blocklet.componentId || '').split('/').pop());
}
},
onAfterResponse: async (req, res) => {
const result = {} as any;
Expand Down
6 changes: 3 additions & 3 deletions packages/uploader/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ export const getImageBinComponent = () =>
window?.blocklet?.componentMountPoints?.find((item: any) => item.did === 'z8ia1mAXo8ZE7ytGF36L5uBf9kD2kenhqFGp9');

// @ts-ignore
export const imageBinMountPoint = getImageBinComponent().mountPoint;
export const imageBinMountPoint = getImageBinComponent()?.mountPoint;

// @ts-ignore
export const prefixPath = imageBinMountPoint || (window.blocklet ? window.blocklet.prefix : '/');
export const prefixPath = imageBinMountPoint || window?.blocklet?.prefix || '/';

export const api = axios.create();

Expand All @@ -64,7 +64,7 @@ api.interceptors.request.use(

export function createImageUrl(filename: string, width = 0, height = 0) {
// @ts-ignore
const { CDN_HOST = '' } = window.blocklet;
const { CDN_HOST = '' } = window?.blocklet || {};
const obj = new URL(CDN_HOST || window.location.origin);
obj.pathname = joinUrl(prefixPath, '/uploads/', filename);

Expand Down
2 changes: 1 addition & 1 deletion packages/uploader/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.5
0.0.6

0 comments on commit b87fdcd

Please sign in to comment.