Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修改chooseMidea出参的处理,给getVideoInfo增加固定返回,修改readFile等测试样例 #195

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 24 additions & 39 deletions examples/mini-program-example/src/pages/api/file/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -447,46 +447,36 @@ export default class Index extends React.Component {
},
{
id: 'fileSystem_readFile',
func: (apiIndex) => {
inputData: {
filePath: '',
position: 0,
length: 1,
encoding: '',
},
func: (apiIndex, data) => {
TestConsole.consoleTest('fileSystem_readFile')
Taro.chooseImage({
fileSystemManager.readFile({
...data,
success: (res) => {
var tempFilePaths = res.tempFilePaths
Taro.saveFile({
tempFilePath: tempFilePaths[0],
filePath: 'D:/common',
success: (res) => {
TestConsole.consoleNormal('saveFile success ', res)
fileSystemManager.readFile({
filePath: res.savedFilePath,
position: 0,
length: 1,
encoding: '',
success: (res) => {
TestConsole.consoleSuccess.call(this, res, apiIndex)
},
fail: (res) => {
TestConsole.consoleFail.call(this, res, apiIndex)
},
complete: (res) => {
TestConsole.consoleComplete.call(this, res, apiIndex)
},
})
},
fail: (res) => {
TestConsole.consoleNormal('saveFile fail ', res.errMsg)
},
complete: (res) => {
TestConsole.consoleNormal('saveFile complete ', res)
},
})
TestConsole.consoleSuccess.call(this, res, apiIndex)
},
fail: (res) => {
TestConsole.consoleFail.call(this, res, apiIndex)
},
complete: (res) => {
TestConsole.consoleComplete.call(this, res, apiIndex)
},
})
},
},
{
id: 'fileSystem_readFileSync',
func: (apiIndex) => {
inputData: {
encoding: '',
position: 0,
length: 1,
},
func: (apiIndex, data) => {
TestConsole.consoleTest('fileSystem_readFileSync')
Taro.chooseImage({
success: (res) => {
Expand All @@ -496,13 +486,8 @@ export default class Index extends React.Component {
filePath: 'D:/common',
success: function (sucRes) {
TestConsole.consoleNormal('saveFile success ', sucRes)
str = fileSystemManager.readFileSync({
filePath: sucRes.savedFilePath,
encoding: '',
position: 0,
length: 1,
})
TestConsole.consoleNormal('readFileSync success ', str)
fileSystemManager.readFileSync(sucRes.savedFilePath, data.encoding, data.position, data.length)
TestConsole.consoleNormal('readFileSync success ')
},
fail: function (failRes) {
TestConsole.consoleNormal('saveFile fail ', failRes.errMsg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default class Index extends React.Component {
{
id: 'getLocation',
inputData: {
altitude: "false",
altitude: 'false',
highAccuracyExpireTime: 8000,
isHighAccuracy: true,
type: 'wgs84',
Expand Down Expand Up @@ -145,7 +145,7 @@ export default class Index extends React.Component {
zoom: 15,
radius: 1000,
total: 10,
referer: 'myTaro'
referer: 'myTaro',
},
},
func: (apiIndex, data) => {
Expand Down Expand Up @@ -203,7 +203,7 @@ export default class Index extends React.Component {
func: async (apiIndex) => {
try {
TestConsole.consoleTest('openLocation')
const loc = await Taro.getFuzzyLocation({type: 'gcj02'})
const loc = await Taro.getFuzzyLocation({ type: 'gcj02' })
Taro.openLocation({
longitude: loc.longitude,
latitude: loc.latitude,
Expand Down
59 changes: 22 additions & 37 deletions examples/mini-program-example/src/pages/api/media/video/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,35 +164,17 @@ export default class Index extends React.Component {
func: null,
},
{
id: 'chooseVideo_album',
func: (apiIndex) => {
TestConsole.consoleTest('chooseVideo_album')
Taro.chooseVideo({
sourceType: ['album'],
maxDuration: 60,
camera: 'back',
success: (res) => {
TestConsole.consoleSuccess.call(this, res, apiIndex)
},
fail: (res) => {
TestConsole.consoleFail.call(this, res, apiIndex)
},
complete: (res) => {
TestConsole.consoleComplete.call(this, res, apiIndex)
},
}).then((res) => {
TestConsole.consoleReturn.call(this, res, apiIndex)
})
id: 'chooseVideo',
inputData: {
camera: '',
compressed: false,
sourceType: ['album'],
maxDuration: 30,
},
},
{
id: 'chooseVideo_camera',
func: (apiIndex) => {
TestConsole.consoleTest('chooseVideo_camera')
func: (apiIndex, data) => {
TestConsole.consoleTest('chooseVideo')
Taro.chooseVideo({
sourceType: ['camera'],
maxDuration: 60,
camera: 'back',
...data,
success: (res) => {
TestConsole.consoleSuccess.call(this, res, apiIndex)
},
Expand All @@ -208,17 +190,20 @@ export default class Index extends React.Component {
},
},
{
id: 'chooseMedia_image',
func: (apiIndex) => {
TestConsole.consoleTest('chooseMedia_image')
id: 'chooseMedia',
inputData: {
count: 9,
mediaType: ['image'],
sourceType: ['album', 'camera'],
maxDuration: 30,
sizeType: ['original', 'compressed'],
camera: 'back',
mediaId: '',
},
func: (apiIndex, data) => {
TestConsole.consoleTest('chooseMedia')
Taro.chooseMedia({
count: 9,
mediaType: ['image'],
sourceType: ['album', 'camera'],
maxDuration: 30,
camera: 'back',
sizeType: ['original', 'compressed'],
// mediaId: 'test mediaId field',//'mediaId' does not exist in type 'Option'
...data,
success: (res) => {
TestConsole.consoleSuccess.call(this, res, apiIndex)
},
Expand Down
32 changes: 20 additions & 12 deletions packages/taro-mpharmony/src/api/media/audio/InnerAudioContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export class InnerAudioContext implements Taro.InnerAudioContext {
stopStack: CallbackManager
__startTime = 0
__isFirstPlay = true
MIN_PLAYBACKRATE = 0.5
MAX_PLAYBACKRATE = 2.0

constructor () {
this.Instance = new Audio()
Expand Down Expand Up @@ -76,15 +78,21 @@ export class InnerAudioContext implements Taro.InnerAudioContext {
}

get volume () {
return this.Instance?.volume || 0
return this.Instance?.volume || 1
}

set playbackRate (e) {
if (e < this.MIN_PLAYBACKRATE) {
e = this.MIN_PLAYBACKRATE
}
if (e > this.MAX_PLAYBACKRATE) {
e = this.MAX_PLAYBACKRATE
}
this.setProperty('playbackRate', e)
}

get playbackRate () {
return this.Instance?.playbackRate || 0
return this.Instance?.playbackRate || 1
}

set obeyMuteSwitch (_e) {
Expand Down Expand Up @@ -144,25 +152,25 @@ export class InnerAudioContext implements Taro.InnerAudioContext {
}
}

canPlayCallback = () => {}
canPlayCallback = () => { }

playCallback = () => {}
playCallback = () => { }

pauseCallback = () => {}
pauseCallback = () => { }

stopCallback = () => {}
stopCallback = () => { }

endedCallback = () => {}
endedCallback = () => { }

timeUpdateCallback = () => {}
timeUpdateCallback = () => { }

waitingCallback = () => {}
waitingCallback = () => { }

seekingCallback = () => {}
seekingCallback = () => { }

seekedCallback = () => {}
seekedCallback = () => { }

errorCallback = () => {}
errorCallback = () => { }

onCanplay = (callback: Taro.InnerAudioContext.OnCanplayCallback = this.canPlayCallback) =>
this.Instance?.addEventListener('canplay', callback as any)
Expand Down
16 changes: 15 additions & 1 deletion packages/taro-mpharmony/src/api/media/video/chooseMedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,22 @@ export const chooseMedia: typeof Taro.chooseMedia = (options) => {
sizeType: sizeType,
camera: camera,
success: (res: any) => {
const tempFiles: Taro.chooseMedia.ChooseMedia[] = []
res.tempFiles.forEach((tempFile) => {
const tmpFile: Taro.chooseMedia.ChooseMedia = {
tempFilePath: tempFile.path,
size: tempFile.size,
duration: tempFile.duration,
height: tempFile.height,
width: tempFile.width,
fileType: tempFile.type,
thumbTempFilePath: ''
}
tempFiles.push(tmpFile)
})

const result: Taro.chooseMedia.SuccessCallbackResult = {
tempFiles: res.tempFiles,
tempFiles: tempFiles,
type: res.type,
errMsg: res.errMsg,
}
Expand Down
6 changes: 4 additions & 2 deletions packages/taro-mpharmony/src/api/media/video/getVideoInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { MethodHandler } from 'src/utils/handler'

export const getVideoInfo: typeof Taro.getVideoInfo = (options) => {
const name = 'getVideoInfo'
const FPS_NUM = 30
const BRI_NUM = 1000

// options must be an Object
const isObject = shouldBeObject(options)
Expand Down Expand Up @@ -48,8 +50,8 @@ export const getVideoInfo: typeof Taro.getVideoInfo = (options) => {
size: res.size,
height: res.height,
width: res.width,
fps: res.fps,
bitrate: res.bitrate,
fps: FPS_NUM,
bitrate: BRI_NUM,
errMsg: res.errMsg,
}
handle.success(result, { resolve, reject })
Expand Down
40 changes: 32 additions & 8 deletions packages/taro-mpharmony/src/api/storage/setBackgroundFetchToken.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,37 @@
import Taro from '@tarojs/taro'
import { getParameterError, shouldBeObject } from 'src/utils'
import { MethodHandler } from 'src/utils/handler'

// null-implementation
export const setBackgroundFetchToken: typeof Taro.setBackgroundFetchToken = function (option) {
export const setBackgroundFetchToken: typeof Taro.setBackgroundFetchToken = function (options) {
const name = 'setBackgroundFetchToken'
return new Promise<TaroGeneral.CallbackResult>(() => {
try {
option?.fail?.({ errMsg: `${name}:fail` })
} finally {
option?.complete?.({ errMsg: `ok` })
}
})

// options must be an Object
const isObject = shouldBeObject(options)
if (!isObject.flag) {
const res = { errMsg: `${name}:fail ${isObject.msg}` }
console.error(res.errMsg)
return
}

const { token, success, fail, complete } = options as Exclude<typeof options, undefined>
const handle = new MethodHandler({ name, success, fail, complete })

// token must be String
if (typeof token !== 'string') {
return handle.fail({
errMsg: getParameterError({
para: 'token',
correct: 'string',
wrong: token,
}),
})
}

try {
localStorage.setItem('token', token)
handle.success()
} catch (error) {
handle.fail()
}
}