UNPKG

@szmg-fe/tarco

Version:

function library in Taro

59 lines (55 loc) 1.97 kB
/* * @Description: hook of cos * @Date: 2021-03-22 17:39:09 * @Author: Lemon * @LastEditTime: 2021-05-21 17:26:47 */ import { useRef } from "react"; import VodUploader from 'vod-wx-sdk-v2'; import { compose, map } from "@szmg-fe/funba/ramda"; import prop from '@szmg-fe/funba/prop' import { useFinishRender } from "@szmg-fe/hooks/useEffect"; import { hideLoading, showModal } from '@tarojs/taro'; import Task from 'data.task'; import fork from "@szmg-fe/funba/fork"; import { error } from "@szmg-fe/funba/console"; import showLoading from "./showLoading"; /** * * @param http: (params) => task * @returns cos ref */ export default function useVod(http: Task) { const signature = useRef(''); const initVod = compose(fork(error, s => signature.current = s), map(prop('signature')), http); useFinishRender(initVod); return videoFile => { return new Task((rej, resolve) => { VodUploader.start({ mediaFile: videoFile, //必填,把chooseVideo回调的参数(file)传进来 getSignature: callback => callback(signature.current), //必填,获取签名的函数 error: function (result) { hideLoading(); showModal({ title: "上传失败", content: JSON.stringify(result), showCancel: false }); rej(result) }, progress: function (result) { hideLoading(); showLoading("上传中 " + result.percent * 100 + "%"); }, finish: function (result) { hideLoading(); resolve({ type: 'video', fieldId: result.fileId, url: result.videoUrl, }); } }) }) } }