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