"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(((i,s)=>{if(l.startsWith("wxfile://")){const n=l.match(/[^\/\\]+(?=\.[^\.]+$|$)/)[0],t=l;o({filename:n,alc:"public-read"}).then((l=>{if(null==l?void 0:l.success){e.index.getFileSystemManager().readFile({filePath:t,complete(e){console.log("complete",e)},success:function(o){var n,t;console.log(o,"fileRes1"),e.index.request({url:null==(n=null==l?void 0:l.data)?void 0:n.url,method:"PUT",header:{...null==(t=null==l?void 0:l.data)?void 0:t.headers,"x-amz-acl":"public-read"},data:null==o?void 0:o.data,success:function(o){var n,t;if(console.log(o,"resUpadte"),200!==o.statusCode)e.index.showToast({title:"上传失败",icon:"none"}),s();else{let e={url:null==(t=null==(n=null==l?void 0:l.data)?void 0:n.url)?void 0:t.split("?")[0],status:"done",type:"image/png",uid:Date.now()};i([e])}},fail:function(){e.index.showToast({title:"上传失败",icon:"none"}),s()}}),console.log(o,"fileRes")}})}}))}else e.index.downloadFile({url:l,success:async l=>{if(200===l.statusCode){const n=l.tempFilePath.match(/[^\/\\]+(?=\.[^\.]+$|$)/),t=l.tempFilePath,a=n[0];console.log(n[0]),o({filename:a,alc:"public-read"}).then((l=>{if(null==l?void 0:l.success){e.index.getFileSystemManager().readFile({filePath:t,complete(e){console.log("complete",e)},success:function(o){var n,t;console.log(o,"fileRes1"),e.index.request({url:null==(n=null==l?void 0:l.data)?void 0:n.url,method:"PUT",header:{...null==(t=null==l?void 0:l.data)?void 0:t.headers,"x-amz-acl":"public-read"},data:null==o?void 0:o.data,success:function(o){var n,t;if(console.log(o,"resUpadte"),200!==o.statusCode)e.index.showToast({title:"上传失败",icon:"none"}),s();else{let e={url:null==(t=null==(n=null==l?void 0:l.data)?void 0:n.url)?void 0:t.split("?")[0],status:"done",type:"image/png",uid:Date.now()};i([e])}},fail:function(){e.index.showToast({title:"上传失败",icon:"none"}),s()}}),console.log(o,"fileRes")}})}}))}else console.log(`文件下载失败，状态码: ${l.statusCode}`)},fail:e=>{}})})),exports.upload=(l=1,i=2,s=["image"])=>new Promise(((n,t)=>{let a=[];e.index.chooseMedia({count:l>9?9:l,mediaType:s,sizeType:["original","compressed"],success:async function(l){var s;console.log("filePath_i",l),null==(s=l.tempFiles)||s.map((s=>{console.log(s,"??kj");let d=s.tempFilePath.match(/[^\/\\]+(?=\.[^\.]+$|$)/);const u=s.tempFilePath,c=u.lastIndexOf("."),r=d[0];c>=-1&&u.substr(c+1);if(l.tempFiles[0].size>1048576*(i||2))return e.index.showToast({title:`${r}文件大小不能超过${i}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 i,d;console.log(o,"fileRes1"),e.index.request({url:null==(i=null==l?void 0:l.data)?void 0:i.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 i,d;if(console.log(o,"resUpadte"),200!==o.statusCode)e.index.showToast({title:"上传失败",icon:"none"}),t();else{const e=Date.now();let o={url:null==(d=null==(i=null==l?void 0:l.data)?void 0:i.url)?void 0:d.split("?")[0],status:"done",type:`${null==s?void 0:s.fileType}/${u.split(".")[1]}`,uid:e,size:null==s?void 0:s.size};null==a||a.push(o),n(a)}},fail:function(){e.index.showToast({title:"上传失败",icon:"none"}),t()}}),console.log(o,"fileRes")}})}}))}))}})}));
