wechaty-puppet-padplus
Version:
Puppet Padplus for Wechaty
81 lines • 3.62 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const is_type_1 = require("./is-type");
const xml_to_json_1 = require("./xml-to-json");
function emojiPayloadParser(rawPayload) {
return __awaiter(this, void 0, void 0, function* () {
if (!is_type_1.isPayload(rawPayload)) {
return null;
}
// {
// "msg": {
// "emoji": {
// "$": {
// "fromusername": "lylezhuifeng",
// "tousername": "wxid_rdwh63c150bm12",
// "type": "2",
// "idbuffer": "media:0_0",
// "md5": "8dae79800b6ef10195e126042fc94076",
// "len": "310090",
// "productid": "",
// "androidmd5": "8dae79800b6ef10195e126042fc94076",
// "androidlen": "310090",
// "s60v3md5": "8dae79800b6ef10195e126042fc94076",
// "s60v3len": "310090",
// "s60v5md5": "8dae79800b6ef10195e126042fc94076",
// "s60v5len": "310090",
// "cdnurl": "http://emoji.qpic.cn/wx_emoji/l4keeCADqvmX5rSCy4nHXib3IpnTLy2T6CXetFgclb3ICM8zFs2wjNQ/",
// "designerid": "",
// "thumburl": "",
// "encrypturl": "http://emoji.qpic.cn/wx_emoji/b1Nsib7KBEDmYQq4bzAFibrXjUehx9MhaK2GgYMLcFeerjLd7jic3aLibQ/",
// "aeskey": "54a31301a1a2fb1a36ca35b741473d6f",
// "externurl": "http://emoji.qpic.cn/wx_emoji/CEnicDu2nX21RqMM5FdUtC6dAibroWDIdae0FeNAznUhEXQf7MKjtQQcet3Uqjl1Dy/",
// "externmd5": "128bdfe8c926db33f6adc62b955904a2",
// "width": "135",
// "height": "180",
// "tpurl": "",
// "tpauthkey": "",
// "attachedtext": ""
// }
// },
// "gameext": {
// "$": {
// "type": "0",
// "content": "0"
// }
// }
// }
// }
const { content } = rawPayload;
const tryXmlText = content.replace(/^[^\n]+\n/, '');
try {
const jsonPayload = yield xml_to_json_1.xmlToJson(tryXmlText);
const type = parseInt(jsonPayload.msg.emoji.$.type, 10) || 0;
const len = parseInt(jsonPayload.msg.emoji.$.len, 10) || 0;
const width = parseInt(jsonPayload.msg.emoji.$.width, 10) || 0;
const height = parseInt(jsonPayload.msg.emoji.$.height, 10) || 0;
const cdnurl = jsonPayload.msg.emoji.$.cdnurl;
return {
cdnurl,
height,
len,
type,
width,
};
}
catch (e) {
return null;
}
});
}
exports.emojiPayloadParser = emojiPayloadParser;
//# sourceMappingURL=message-emoji-payload-parser.js.map