diff --git a/packages/uploader/CHANGELOG.md b/packages/uploader/CHANGELOG.md index f3175ed..fce3822 100644 --- a/packages/uploader/CHANGELOG.md +++ b/packages/uploader/CHANGELOG.md @@ -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 diff --git a/packages/uploader/package.json b/packages/uploader/package.json index 1e0dd04..d3311a1 100644 --- a/packages/uploader/package.json +++ b/packages/uploader/package.json @@ -1,6 +1,6 @@ { "name": "@blocklet/uploader", - "version": "0.0.5", + "version": "0.0.6", "description": "blocklet upload component", "publishConfig": { "access": "public" diff --git a/packages/uploader/src/react/plugins/uploaded.jsx b/packages/uploader/src/react/plugins/uploaded.jsx index 1297840..fc5316f 100644 --- a/packages/uploader/src/react/plugins/uploaded.jsx +++ b/packages/uploader/src/react/plugins/uploaded.jsx @@ -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`, { diff --git a/packages/uploader/src/react/uploader.tsx b/packages/uploader/src/react/uploader.tsx index 345fefc..decaf9d 100644 --- a/packages/uploader/src/react/uploader.tsx +++ b/packages/uploader/src/react/uploader.tsx @@ -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; diff --git a/packages/uploader/src/utils.ts b/packages/uploader/src/utils.ts index 0377ed2..47c226c 100644 --- a/packages/uploader/src/utils.ts +++ b/packages/uploader/src/utils.ts @@ -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(); @@ -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); diff --git a/packages/uploader/version b/packages/uploader/version index fa3de58..99d85ec 100644 --- a/packages/uploader/version +++ b/packages/uploader/version @@ -1 +1 @@ -0.0.5 \ No newline at end of file +0.0.6 \ No newline at end of file