diff --git a/common/src/main/ets/default/model/browser/photo/SelectUtil.ts b/common/src/main/ets/default/model/browser/photo/SelectUtil.ts index 390cf26d..bc02d81b 100644 --- a/common/src/main/ets/default/model/browser/photo/SelectUtil.ts +++ b/common/src/main/ets/default/model/browser/photo/SelectUtil.ts @@ -35,34 +35,34 @@ export class SelectUtil { static getCountOfMedia(uriArray: Array, selectedMap: Map): Promise> { let result = [0, 0]; - if (uriArray === undefined || uriArray.length <= 0) { + if (uriArray === null || uriArray === undefined || uriArray.length <= 0) { Log.info(TAG, 'uriArray is null or empty!'); - return new Promise((resolve) => { + return new Promise((resolve): void => { resolve(result); - }) + }); } if (selectedMap === undefined || selectedMap.size <= 0) { Log.info(TAG, 'selectedMap is null or empty!'); - return new Promise((resolve) => { + return new Promise((resolve): void => { resolve(result); - }) + }); } let imageCount: number = 0; let videoCount: number = 0; - for (let i = 0; i < selectedMap.size; i++) { + for (let i = 0; i < uriArray.length; i++) { let mediaItem: MediaItem = selectedMap.get(uriArray[i]); - if (mediaItem.mediaType === UserFileManagerAccess.MEDIA_TYPE_IMAGE) { + if (mediaItem?.mediaType === UserFileManagerAccess.MEDIA_TYPE_IMAGE) { imageCount++; - } else if (mediaItem.mediaType === UserFileManagerAccess.MEDIA_TYPE_VIDEO) { + } else if (mediaItem?.mediaType === UserFileManagerAccess.MEDIA_TYPE_VIDEO) { videoCount++; } } result = [imageCount, videoCount]; - return new Promise((resolve) => { + return new Promise((resolve): void => { resolve(result); - }) + }); } static async grantPermissionForUris(uris: Array, bundleName: string): Promise {