Skip to content

Commit

Permalink
feat(harmony): getImageInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Wangyaqi committed May 22, 2024
1 parent a9d6bbf commit 4633269
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 32 deletions.
40 changes: 12 additions & 28 deletions packages/uni-app-harmony/src/service/api/media/getImageInfo.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,18 @@
import picker from '@ohos.file.picker'
import { _chooseMedia } from './media'
import { _getImageInfo } from './media'
import {
API_CHOOSE_IMAGE,
type API_TYPE_CHOOSE_IMAGE,
ChooseImageOptions,
ChooseImageProtocol,
API_GET_IMAGE_INFO,
type API_TYPE_GET_IMAGE_INFO,
GetImageInfoOptions,
GetImageInfoProtocol,
defineAsyncApi,
} from '@dcloudio/uni-api'

export const chooseImage: API_TYPE_CHOOSE_IMAGE =
defineAsyncApi<API_TYPE_CHOOSE_IMAGE>(
API_CHOOSE_IMAGE,
function ({ count } = {}, { resolve, reject }) {
_chooseMedia({
mimeType: picker.PhotoViewMIMETypes.IMAGE_TYPE,
count,
})
.then((res) => {
return {
tempFilePaths: res.tempFiles.map((file) => file.tempFilePath),
tempFiles: res.tempFiles.map((file) => {
return {
path: file.tempFilePath,
size: file.size,
}
}),
}
})
.then(resolve, reject)
export const getImageInfo: API_TYPE_GET_IMAGE_INFO =
defineAsyncApi<API_TYPE_GET_IMAGE_INFO>(
API_GET_IMAGE_INFO,
function ({ src }, { resolve, reject }) {
_getImageInfo(src).then(resolve, reject)
},
ChooseImageProtocol,
ChooseImageOptions
GetImageInfoProtocol,
GetImageInfoOptions
)
3 changes: 3 additions & 0 deletions packages/uni-app-harmony/src/service/api/media/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export * from './chooseImage'
export * from './chooseVideo'
export * from './getImageInfo'
export * from './getVideoInfo'
7 changes: 3 additions & 4 deletions packages/uni-app-harmony/src/service/api/media/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export async function _getVideoInfo(uri: string): Promise<VideoInfo> {

export interface ImageInfo {
path: string
orientation?:
orientation:
| 'up'
| 'down'
| 'left'
Expand All @@ -94,9 +94,8 @@ export interface ImageInfo {
| 'down-mirrored'
| 'left-mirrored'
| 'right-mirrored'
type?: string
height?: number
width?: number
height: number
width: number
}

export async function _getImageInfo(uri: string): Promise<ImageInfo> {
Expand Down

0 comments on commit 4633269

Please sign in to comment.