Skip to content

Commit

Permalink
send file
Browse files Browse the repository at this point in the history
  • Loading branch information
trazyn committed Aug 11, 2017
1 parent 199d291 commit bc2b4bc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
14 changes: 11 additions & 3 deletions src/js/pages/Footer/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,20 @@ export default class Input extends Component {
this.refs.input.value += `[${emoji}]`;
}

process(file) {
async process(file) {
if (!file) return;

var mediaid = this.props.upload(file);
var mediaId = await this.props.upload(file);

this.props.sendFile(mediaid);
this.props.sendMessage(this.props.user, {
type: 49 + 6,
file: {
name: file.name,
size: file.size,
mediaId,
extension: file.name.split('.').slice(-1).pop()
},
});
}

render() {
Expand Down
14 changes: 6 additions & 8 deletions src/js/stores/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ class Chat {
isme: true,
CreateTime: +new Date() / 1000,
MsgId: response.data.MsgID,
MsgType: 3,
HeadImgUrl: session.user.User.HeadImgUrl,
}),
};
Expand All @@ -417,11 +418,7 @@ class Chat {
}

@action async sendFileMessage(auth, message, isForward) {
var response = await axios.post((
isForward
? '/cgi-bin/mmwebwx-bin/webwxsendappmsg?fun=async&f=json'
: '/cgi-bin/mmwebwx-bin/webwxsendmsgimg&fun=async'
), {
var response = await axios.post('/cgi-bin/mmwebwx-bin/webwxsendappmsg?fun=async&f=json', {
BaseRequest: {
Sid: auth.wxsid,
Uin: auth.wxuin,
Expand Down Expand Up @@ -461,6 +458,7 @@ class Chat {
isme: true,
CreateTime: +new Date() / 1000,
MsgId: response.data.MsgID,
MsgType: 49 + 6,
HeadImgUrl: session.user.User.HeadImgUrl,
}),
};
Expand Down Expand Up @@ -576,10 +574,10 @@ class Chat {
formdata.append('pass_ticket', auth.passTicket);
formdata.append('filename', file.slice(0, file.size));

var response = axios.post(server, formdata);
var response = await axios.post(server, formdata);

if (response.BaseResponse.Ret === 0) {
return response.MediaId;
if (response.data.BaseResponse.Ret === 0) {
return response.data.MediaId;
}

return false;
Expand Down

0 comments on commit bc2b4bc

Please sign in to comment.