"use strict";const e=require("../vendor.js"),l=require("../../gen/Apis.js"),o=async e=>await l.Apis.Login.Auth.PreUpload(e);exports.avatarUpload=l=>new Promise((n,i)=>{if(l.startsWith("wxfile://")){const t=l.match(/[^\/\\]+(?=\.[^\.]+$|$)/)[0],s=l;return void o({filename:t,alc:"public-read"}).then(l=>{if(null==l?void 0:l.success){e.index.getFileSystemManager().readFile({filePath:s,complete(e){console.log("complete",e)},success:function(o){var t,s;console.log(o,"fileRes1"),e.index.request({url:null==(t=null==l?void 0:l.data)?void 0:t.url,method:"PUT",header:{...null==(s=null==l?void 0:l.data)?void 0:s.headers,"x-amz-acl":"public-read"},data:null==o?void 0:o.data,success:function(o){var t,s;if(console.log(o,"resUpadte"),200!==o.statusCode)e.index.showToast({title:"上传失败",icon:"none"}),i();else{let e={url:null==(s=null==(t=null==l?void 0:l.data)?void 0:t.url)?void 0:s.split("?")[0],status:"done",type:"image/png",uid:Date.now()};n([e])}},fail:function(){e.index.showToast({title:"上传失败",icon:"none"}),i()}}),console.log(o,"fileRes")}})}})}e.index.downloadFile({url:l,success:async l=>{if(200===l.statusCode){const t=l.tempFilePath.match(/[^\/\\]+(?=\.[^\.]+$|$)/),s=l.tempFilePath,a=t[0];console.log(t[0]),o({filename:a,alc:"public-read"}).then(l=>{if(null==l?void 0:l.success){e.index.getFileSystemManager().readFile({filePath:s,complete(e){console.log("complete",e)},success:function(o){var t,s;console.log(o,"fileRes1"),e.index.request({url:null==(t=null==l?void 0:l.data)?void 0:t.url,method:"PUT",header:{...null==(s=null==l?void 0:l.data)?void 0:s.headers,"x-amz-acl":"public-read"},data:null==o?void 0:o.data,success:function(o){var t,s;if(console.log(o,"resUpadte"),200!==o.statusCode)e.index.showToast({title:"上传失败",icon:"none"}),i();else{let e={url:null==(s=null==(t=null==l?void 0:l.data)?void 0:t.url)?void 0:s.split("?")[0],status:"done",type:"image/png",uid:Date.now()};n([e])}},fail:function(){e.index.showToast({title:"上传失败",icon:"none"}),i()}}),console.log(o,"fileRes")}})}})}else console.log(`文件下载失败，状态码: ${l.statusCode}`)},fail:e=>{}})}),exports.upload=(l=1,n=2,i=["image"])=>new Promise((t,s)=>{let a=[];e.index.chooseMedia({count:l>9?9:l,mediaType:i,sizeType:["original","compressed"],success:async function(l){var i;console.log("filePath_i",l),null==(i=l.tempFiles)||i.map(i=>{console.log(i,"??kj");let d=i.tempFilePath.match(/[^\/\\]+(?=\.[^\.]+$|$)/);const u=i.tempFilePath,c=u.lastIndexOf("."),r=d[0];c>=-1&&u.substr(c+1);if(l.tempFiles[0].size>1048576*(n||2))return e.index.showToast({title:`${r}文件大小不能超过${n}M`,icon:"none"}),!1;o({filename:r,alc:"public-read"}).then(l=>{if(null==l?void 0:l.success){e.index.getFileSystemManager().readFile({filePath:u,complete(e){console.log("complete",e)},success:function(o){var n,d;console.log(o,"fileRes1"),e.index.request({url:null==(n=null==l?void 0:l.data)?void 0:n.url,method:"PUT",header:{...null==(d=null==l?void 0:l.data)?void 0:d.headers,"x-amz-acl":"public-read"},data:null==o?void 0:o.data,success:function(o){var n,d;if(console.log(o,"resUpadte"),200!==o.statusCode)e.index.showToast({title:"上传失败",icon:"none"}),s();else{const e=Date.now();let o={url:null==(d=null==(n=null==l?void 0:l.data)?void 0:n.url)?void 0:d.split("?")[0],status:"done",type:`${null==i?void 0:i.fileType}/${u.split(".")[1]}`,uid:e,size:null==i?void 0:i.size};null==a||a.push(o),t(a)}},fail:function(){e.index.showToast({title:"上传失败",icon:"none"}),s()}}),console.log(o,"fileRes")}})}})})}})}),exports.uploadImgWatermark=l=>new Promise((n,i)=>{const t=Date.now(),s=null==l?void 0:l.path.lastIndexOf("."),a=s>=-1?null==l?void 0:l.path.substr(s+1):"";console.log(s,a,"fileExt"),o({filename:`${(null==l?void 0:l.name)||""}_${t}.${a}`,alc:"public-read"}).then(o=>{if(null==o?void 0:o.success){e.index.getFileSystemManager().readFile({filePath:(null==l?void 0:l.path)||"",success:function(s){var a,d;e.index.request({url:null==(a=null==o?void 0:o.data)?void 0:a.url,method:"PUT",header:{...null==(d=null==o?void 0:o.data)?void 0:d.headers,"x-amz-acl":"public-read"},data:null==s?void 0:s.data,success:function(s){200!==s.statusCode?i(new Error(`上传失败: ${s.statusCode}`)):e.index.getImageInfo({src:null==l?void 0:l.path,success:e=>{var i,s;console.log(e,"imgInfo");let a={url:null==(s=null==(i=null==o?void 0:o.data)?void 0:i.url)?void 0:s.split("?")[0],status:"done",type:null==e?void 0:e.type,uid:t,size:"",name:`${null==l?void 0:l.name}-${t}`};n(a)}})},fail:function(){i(new Error("网络请求失败"))}})},fail:function(){i(new Error("读取文件失败"))}})}else i(new Error("获取上传链接失败"))}).catch(e=>{i(e)})});
