Skip to content

Commit

Permalink
fix: payload match
Browse files Browse the repository at this point in the history
  • Loading branch information
vv314 committed Dec 30, 2023
1 parent a2f2d35 commit 0e689b5
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 32 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function sendUserNotify({ status, message, account, userInfo }) {
function sendGlobalNotify(tasks) {
const message = tasks.map((t) => `账号 ${t.user}:\n${t.data}`).join('\n\n')
const errorTasks = tasks.filter((t) => t.status == 'error')
const allFailed = tasks.length > 1 && errorTasks.length === tasks.length
const allFailed = tasks.length && errorTasks.length === tasks.length
const title = `${NOTIFY_TITLE}${
allFailed
? '😥'
Expand Down
4 changes: 2 additions & 2 deletions src/coupons/DCwpqO.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ async function grabCoupon(cookie) {
}

export default {
grabCoupon: grabCoupon,
getActUrl: getActUrl
grabCoupon,
getActUrl
}
export { getParams }
26 changes: 8 additions & 18 deletions src/coupons/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import fetch from '../fetch.js'
import ShadowGuard from '../shadow/index.js'
import { createMTCookie, getUserInfo } from '../user.js'
import gundamGrab from './gundamGrab.js'
import DCwpqO from './DCwpqO.js'
import { couponId, ECODE } from './const.js'

async function runTask(cookie, guard) {
Expand All @@ -20,24 +19,15 @@ async function runTask(cookie, guard) {

grabResult.push(...mainResult)

try {
const qualityShopResult = await gundamGrab.grabCoupon(
cookie,
couponId.shop.gid,
guard
)

grabResult.push(...qualityShopResult)
} catch {
// 仅对某些用户群体生效
}

// try {
// const DCwpqOResult = await DCwpqO.grabCoupon(cookie)

// grabResult.push(...DCwpqOResult)
// } catch (e) {
// console.log('eeee', e)
// const qualityShopResult = await gundamGrab.grabCoupon(
// cookie,
// couponId.shop.gid,
// guard
// )

// grabResult.push(...qualityShopResult)
// } catch {
// // 仅对某些用户群体生效
// }

Expand Down
8 changes: 1 addition & 7 deletions src/payload.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import fetch from './fetch.js'
import { getRenderList } from './template.js'

function parseInstanceID(moduleId) {
const regFloat = /(\d+\.\d+)/

return moduleId.match(regFloat)?.[1] ?? ''
}

function matchMoudleData(id, jsText) {
const endField = 'isStopTJCoupon'
const reg = new RegExp(
`gdc-fx-new-netunion-red-envelope-${id}.+?(?=${endField})`
`gdc-fx-v2-netunion-red-envelope-${id}.+?(?=${endField})`
)

const res = jsText.match(reg)
Expand Down
10 changes: 7 additions & 3 deletions src/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function getTemplateData(cookie, gundamId) {
}

// 通过接口获取真实的渲染列表
async function getRenderList(gdId, guard) {
async function getRenderList(gdNumId, guard) {
let data

try {
Expand All @@ -40,7 +40,7 @@ async function getRenderList(gdId, guard) {
params: {
el_biz: 'waimai',
el_page: 'gundam.loader',
gdId: gdId,
gdId: gdNumId,
tenant: 'gundam'
},
guard
Expand All @@ -52,7 +52,11 @@ async function getRenderList(gdId, guard) {
throw new Error('renderinfo 接口调用失败:' + e.message)
}

return Object.keys(data).filter((k) => data[k].render)
const renderList = Object.entries(data)
.filter(([_, v]) => v.render)
.map(([k]) => k)

return renderList
}

export { getTemplateData, getRenderList }
2 changes: 1 addition & 1 deletion test/payload.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test('Test getTemplateData', async () => {
})

test('Test getRenderList', async () => {
const renderList = await getRenderList(couponId.main.gid, guard)
const renderList = await getRenderList(531693, guard)

return expect(renderList).toEqual(expect.any(Array))
})
Expand Down

0 comments on commit 0e689b5

Please sign in to comment.