2 lines
2.9 KiB
JavaScript
2 lines
2.9 KiB
JavaScript
/*! For license information please see 2b286cb83c3ba825c8232e7f0e8d98e4.js.LICENSE.txt */
|
|
"use strict";(wx.webpackJsonp=wx.webpackJsonp||[]).push([["sub-common/2b286cb83c3ba825c8232e7f0e8d98e4"],{"./src/use/useUploadImage.ts":function(e,t,n){var o=n("./node_modules/@babel/runtime/helpers/esm/regeneratorRuntime.js"),a=n("./node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js"),c=n("./node_modules/@tarojs/taro/index.js"),s=n.n(c),r=n("./src/common/constant.ts"),i=n("./src/api/cdn.ts");t.default=function(){var e=(0,i.GetSignApi)(),t=e.fetchData,n=(e.state,function uploadCDNImg(e,n,c){var i=e.path;return console.log("filetype::",i),function getFileType(e){return!!e&&(RegExp(".?(".concat(["gif","jpeg","jpg","bmp","png"].join("|"),")$"),"i").test(e.toLowerCase())?"image":!!RegExp(".(".concat(["avi","wmv","mkv","mp4","mov","rm","3gp","flv","mpg","rmvb","quicktime"].join("|"),")$"),"i").test(e.toLowerCase())&&"video")}(i)?new Promise((function(c,i){(function getSecret(e,n){return new Promise(function(){var n=(0,a.default)((0,o.default)().mark((function _callee(n,a){var c,s,r;return(0,o.default)().wrap((function _callee$(o){for(;;)switch(o.prev=o.next){case 0:return c="/".concat(e,"/{filemd5}{day}{hour}{min}{sec}{.suffix}"),s={method:"post",save_key:c},o.next=4,t(s);case 4:(r=o.sent).success?n(r.data):a({code:r.code||"9999",msg:r.msg});case 6:case"end":return o.stop()}}),_callee)})));return function(e,t){return n.apply(this,arguments)}}())})(n).then((function(t){var n=t;console.log("bucket",n.bucket);var o={authorization:n.authorization,policy:n.policy},a=s().uploadFile({url:"".concat(r.UPLOAD_CDN_URL).concat(n.bucket),formData:o,filePath:e.path,name:"file",success:function success(e){c(JSON.parse("".concat(e.data)))},fail:function fail(e){console.log(e),i(e)}});a.progress((function(e){console.log("上传进度",e.progress),e.progress<100?s().showLoading({title:"上传中..."}):s().hideLoading()}))})).catch((function(e){i(e),s().showToast({title:"获取密钥失败!",icon:"none",duration:3800})}))})):(s().showToast({title:"上传文件类型错误",icon:"none",duration:3800}),!1)});return{uploadCDNImg:n,getWxPhoto:function getWxPhoto(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;return new Promise((function(c,r){var i=[];s().chooseImage({count:t,sizeType:["original","compressed"],sourceType:["album","camera"],success:function success(s){return(0,a.default)((0,o.default)().mark((function _callee2(){var a,u,l;return(0,o.default)().wrap((function _callee2$(o){for(;;)switch(o.prev=o.next){case 0:if(o.prev=0,!(t>1)){o.next=14;break}a=0;case 3:if(!(a<s.tempFiles.length)){o.next=11;break}return o.next=6,n(s.tempFiles[a],e);case 6:u=o.sent,i.push(u);case 8:a++,o.next=3;break;case 11:c(i),o.next=18;break;case 14:return o.next=16,n(s.tempFiles[0],e);case 16:l=o.sent,c(l);case 18:o.next=23;break;case 20:o.prev=20,o.t0=o.catch(0),r(o.t0);case 23:case"end":return o.stop()}}),_callee2,null,[[0,20]])})))()}})}))}}}}}]); |