From c99b7543bfcd9497125edbaa3fa2bd71d629ed88 Mon Sep 17 00:00:00 2001 From: Evan Feenstra Date: Tue, 19 May 2020 14:08:25 -0700 Subject: [PATCH] use form-data lib to upload --- api/network/modify.ts | 18 ++++++++++++++---- dist/api/network/modify.js | 19 +++++++++++++++---- dist/api/network/modify.js.map | 2 +- package-lock.json | 18 ++++++++++++++---- package.json | 1 + 5 files changed, 45 insertions(+), 13 deletions(-) diff --git a/api/network/modify.ts b/api/network/modify.ts index 6e618fe..7eb3b73 100644 --- a/api/network/modify.ts +++ b/api/network/modify.ts @@ -4,8 +4,8 @@ import * as fetch from 'node-fetch' import {parseLDAT} from '../utils/ldat' import * as rsa from '../crypto/rsa' import * as crypto from 'crypto' -import * as Blob from 'fetch-blob' import * as meme from '../utils/meme' +import * as FormData from 'form-data' const constants = require(path.join(__dirname,'../../config/constants.json')) const msgtypes = constants.message_types @@ -43,11 +43,20 @@ export async function modifyPayload(payload, chat) { console.log("[modify] encImg.length", encImg.length) var encImgBuffer = Buffer.from(encImg,'base64'); + console.log("[modify] encImgBuffer.length", encImgBuffer.length) + const bod = new FormData() + bod.append('file', encImgBuffer, { + contentType: typ||'image/jpg', + filename: 'Image.jpg', + }) const resp = await fetch(`https://${terms.host}/file`, { method: 'POST', - headers: {'Authorization': `Bearer ${meme.mediaToken}`}, - body: new Blob([encImgBuffer], { type: typ||'image/jpg', name:'file', filename:'Image.jpg' }) + headers: { + 'Authorization': `Bearer ${meme.mediaToken}`, + 'Content-Type': 'multipart/form-data' + }, + body:bod }) let json = await resp.json() @@ -73,8 +82,9 @@ export async function modifyPayload(payload, chat) { return payload } // how to link w og msg? ogMediaToken? + } else { + return payload } - return payload } function fillmsg(full, props){ diff --git a/dist/api/network/modify.js b/dist/api/network/modify.js index e8c9822..6b28bd8 100644 --- a/dist/api/network/modify.js +++ b/dist/api/network/modify.js @@ -15,8 +15,8 @@ const fetch = require("node-fetch"); const ldat_1 = require("../utils/ldat"); const rsa = require("../crypto/rsa"); const crypto = require("crypto"); -const Blob = require("fetch-blob"); const meme = require("../utils/meme"); +const FormData = require("form-data"); const constants = require(path.join(__dirname, '../../config/constants.json')); const msgtypes = constants.message_types; function modifyPayload(payload, chat) { @@ -47,10 +47,19 @@ function modifyPayload(payload, chat) { const encImg = rncryptor_1.default.Encrypt(newKey, imgBase64); console.log("[modify] encImg.length", encImg.length); var encImgBuffer = Buffer.from(encImg, 'base64'); + console.log("[modify] encImgBuffer.length", encImgBuffer.length); + const bod = new FormData(); + bod.append('file', encImgBuffer, { + contentType: typ || 'image/jpg', + filename: 'Image.jpg', + }); const resp = yield fetch(`https://${terms.host}/file`, { method: 'POST', - headers: { 'Authorization': `Bearer ${meme.mediaToken}` }, - body: new Blob([encImgBuffer], { type: typ || 'image/jpg', name: 'file', filename: 'Image.jpg' }) + headers: { + 'Authorization': `Bearer ${meme.mediaToken}`, + 'Content-Type': 'multipart/form-data' + }, + body: bod }); let json = yield resp.json(); console.log("[modify] post json", json); @@ -75,7 +84,9 @@ function modifyPayload(payload, chat) { } // how to link w og msg? ogMediaToken? } - return payload; + else { + return payload; + } }); } exports.modifyPayload = modifyPayload; diff --git a/dist/api/network/modify.js.map b/dist/api/network/modify.js.map index 81ab87d..2768d80 100644 --- a/dist/api/network/modify.js.map +++ b/dist/api/network/modify.js.map @@ -1 +1 @@ -{"version":3,"file":"modify.js","sourceRoot":"","sources":["../../../api/network/modify.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,6BAA4B;AAC5B,kDAA0C;AAC1C,oCAAmC;AACnC,wCAAuC;AACvC,qCAAoC;AACpC,iCAAgC;AAChC,mCAAkC;AAClC,sCAAqC;AAErC,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAC,6BAA6B,CAAC,CAAC,CAAA;AAC7E,MAAM,QAAQ,GAAG,SAAS,CAAC,aAAa,CAAA;AAExC,SAAsB,aAAa,CAAC,OAAO,EAAE,IAAI;;QAC/C,IAAG,OAAO,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AU,GAAqB;oBACnC,IAAI,EAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAC,GAAG,IAAE,QAAQ;oBACjC,IAAI,oBAAK,GAAG,IAAI,EAAC,GAAG,EAAC,CAAC;oBACtB,WAAW,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,wBAAwB;iBACzD,CAAA;gBACD,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,UAAU,CAAC,CAAA;gBAE7C,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;gBACjD,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAA;gBAE1C,OAAO,OAAO,CAAC,OAAO,EAAE,EAAC,UAAU,EAAC,QAAQ,EAAC,MAAM,EAAC,CAAC,CAAA,CAAC,4BAA4B;aACnF;YAAC,OAAM,CAAC,EAAE;gBACT,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAA;gBAChC,OAAO,OAAO,CAAA;aACf;YACD,sCAAsC;SACvC;QACD,OAAO,OAAO,CAAA;IAChB,CAAC;CAAA;AAjED,sCAiEC;AAED,SAAS,OAAO,CAAC,IAAI,EAAE,KAAK;IAC3B,uCACI,IAAI,KAAE,OAAO,kCACZ,IAAI,CAAC,OAAO,GACZ,KAAK,KAET;AACF,CAAC"} \ No newline at end of file +{"version":3,"file":"modify.js","sourceRoot":"","sources":["../../../api/network/modify.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,6BAA4B;AAC5B,kDAA0C;AAC1C,oCAAmC;AACnC,wCAAuC;AACvC,qCAAoC;AACpC,iCAAgC;AAChC,sCAAqC;AACrC,sCAAqC;AAErC,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAC,6BAA6B,CAAC,CAAC,CAAA;AAC7E,MAAM,QAAQ,GAAG,SAAS,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,CAAC,IAAI;oBAAE,OAAO,OAAO,CAAA;gBAE7B,iDAAiD;gBACjD,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,IAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAA;gBACtC,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,IAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAA;gBACtC,MAAM,UAAU,GAAqB;oBACnC,IAAI,EAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAC,GAAG,IAAE,QAAQ;oBACjC,IAAI,oBAAK,GAAG,IAAI,EAAC,GAAG,EAAC,CAAC;oBACtB,WAAW,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,wBAAwB;iBACzD,CAAA;gBACD,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,UAAU,CAAC,CAAA;gBAE7C,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;gBACjD,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAA;gBAE1C,OAAO,OAAO,CAAC,OAAO,EAAE,EAAC,UAAU,EAAC,QAAQ,EAAC,MAAM,EAAC,CAAC,CAAA,CAAC,4BAA4B;aACnF;YAAC,OAAM,CAAC,EAAE;gBACT,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAA;gBAChC,OAAO,OAAO,CAAA;aACf;YACD,sCAAsC;SACvC;aAAM;YACL,OAAO,OAAO,CAAA;SACf;IACH,CAAC;CAAA;AA3ED,sCA2EC;AAED,SAAS,OAAO,CAAC,IAAI,EAAE,KAAK;IAC3B,uCACI,IAAI,KAAE,OAAO,kCACZ,IAAI,CAAC,OAAO,GACZ,KAAK,KAET;AACF,CAAC"} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index acfada9..38088a3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4072,12 +4072,12 @@ "integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=" }, "form-data": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz", - "integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.0.tgz", + "integrity": "sha512-CKMFDglpbMi6PyN+brwB9Q/GOw0eAnsrEZDgcsH5Krhz5Od/haKHAX0NmQfha2zPPz0JpWzA7GJHGSnvCRLWsg==", "requires": { "asynckit": "^0.4.0", - "combined-stream": "^1.0.6", + "combined-stream": "^1.0.8", "mime-types": "^2.1.12" } }, @@ -9208,6 +9208,16 @@ "uuid": "^3.3.2" }, "dependencies": { + "form-data": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz", + "integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==", + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.6", + "mime-types": "^2.1.12" + } + }, "punycode": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", diff --git a/package.json b/package.json index 9f27692..11590ac 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "express": "^4.16.4", "express-winston": "^4.0.2", "fetch-blob": "^1.0.5", + "form-data": "^3.0.0", "fs": "^0.0.1-security", "grpc": "^1.24.2", "helmet": "^3.21.1",