From 1e834612cbf85e151da58a1be68c9c3d7eb5f2d3 Mon Sep 17 00:00:00 2001 From: Jay Date: Sat, 11 Aug 2018 12:58:34 +0800 Subject: [PATCH] 1. fix opay api struct --- background.js | 13 ++++++++++--- route/google/index.js | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/background.js b/background.js index ce55f6c..da110bc 100644 --- a/background.js +++ b/background.js @@ -265,6 +265,7 @@ const checkDonate = async (loginName = null, opayid = null) => { let url = `https://payment.opay.tw/Broadcaster/CheckDonate/${opayid}` let db = await DB.connect() + // console.log('check donate :::: ', loginName, opayid) // donate response format // { // "donateid": "10821396", @@ -276,16 +277,22 @@ const checkDonate = async (loginName = null, opayid = null) => { try { let result = await axios({ url, + data: {}, + headers: { + 'Content-Type': 'application/json' + }, method: 'post' }) - if ('data' in result && Array.isArray(result.data) && result.data.length > 0) { - let ids = result.data.map(t => t.donateid) + console.log(loginName, 'http response :::: ', JSON.stringify(result.data)) + if ('data' in result && 'lstDonate' in result.data && Array.isArray(result.data.lstDonate) && result.data.lstDonate.length > 0) { + console.log(`${loginName} donate :::: ${JSON.stringify(result.data)}`) + let ids = result.data.lstDonate.map(t => t.donateid) let inparams = ids.map((t, idx) => `$${(idx + 1)}`) let dbres = await db.query({ text: `select * from "public"."donate_list" where "donate_id" in (${inparams.join(',')})`, values: [...ids] }) - let list = result.data.filter(t => { + let list = result.data.lstDonate.filter(t => { for (let i of dbres.rows) { if (i.donate_id === t.donateid) return false } diff --git a/route/google/index.js b/route/google/index.js index 7fd4488..4d49127 100644 --- a/route/google/index.js +++ b/route/google/index.js @@ -48,7 +48,7 @@ r.post('/youtube/webhook', getRaw, async (c, n) => { resolve(res) }) }) - // console.log(JSON.stringify(data, null, 2)) + console.log(JSON.stringify(data, null, 2)) try { let ytid = data.feed.entry[0].id[0]