refactor: 重构lib代码(无实质性功能更新,可不更新)

This commit is contained in:
bietiaop 2024-08-22 13:34:08 +08:00
parent a7f06d404b
commit aa3b7928ec
26 changed files with 547 additions and 483 deletions

49
lib/gacha/const.js Normal file
View file

@ -0,0 +1,49 @@
// 池子代码
export const gacha_type_meta_data = {
音擎频段: ['3001'],
独家频段: ['2001'],
常驻频段: ['1001'],
邦布频段: ['5001'],
};
// 欧非阈值
export const FLOORS_MAP = {
邦布频段: [50, 70],
音擎频段: [50, 70],
独家频段: [60, 80],
常驻频段: [60, 80],
};
// 欧非标签
export const HOMO_TAG = [
'非到极致',
'运气不好',
'平稳保底',
'小欧一把',
'欧狗在此',
];
// 欧非表情
export const EMOJI = [
[4, 8, 13],
[1, 10, 5],
[16, 15, 2],
[12, 3, 9],
[6, 14, 7],
];
// 常驻名称
export const NORMAL_LIST = [
'「11号」',
'猫又',
'莱卡恩',
'丽娜',
'格莉丝',
'珂蕾妲',
'拘缚者',
'燃狱齿轮',
'嵌合编译器',
'钢铁肉垫',
'硫磺石',
'啜泣摇篮',
];

89
lib/gacha/core.js Normal file
View file

@ -0,0 +1,89 @@
import { ZZZ_GET_GACHA_LOG_API } from '../mysapi/api.js';
import request from '../../utils/request.js';
import { ZZZGachaLogResp } from '../../model/gacha.js';
/**
* 获取抽卡链接
* @param {string} authKey 米游社认证密钥
* @param {string} gachaType 祈愿类型池子代码
* @param {string} initLogGachaBaseType
* @param {number} page 页数
* @param {string} endId 最后一个数据的 id
* @param {string} size 页面数据大小
* @returns {Promise<string>} 抽卡链接
*/
export const getZZZGachaLink = async (
authKey,
gachaType = '2001',
initLogGachaBaseType = '2',
page = 1,
endId = '0',
size = '20'
) => {
// 暂时直接写死服务器为国服
const serverId = 'prod_gf_cn';
const url = ZZZ_GET_GACHA_LOG_API;
const timestamp = Math.floor(Date.now() / 1000);
// 请求参数
const params = new URLSearchParams({
authkey_ver: '1',
sign_type: '2',
auth_appid: 'webview_gacha',
init_log_gacha_type: gachaType,
init_log_gacha_base_type: initLogGachaBaseType,
gacha_id: '2c1f5692fdfbb733a08733f9eb69d32aed1d37',
timestamp: timestamp.toString(),
lang: 'zh-cn',
device_type: 'mobile',
plat_type: 'ios',
region: serverId,
authkey: authKey,
game_biz: 'nap_cn',
gacha_type: gachaType,
real_gacha_type: initLogGachaBaseType,
page: page,
size: size,
end_id: endId,
});
// 完整链接
return `${url}?${params}`;
};
/**
* 通过米游社认证密钥获取抽卡记录
* @param {string} authKey 米游社认证密钥
* @param {string} gachaType 祈愿类型池子代码
* @param {string} initLogGachaBaseType
* @param {number} page 页数
* @param {string} endId 最后一个数据的 id
* @returns {Promise<ZZZGachaLogResp>} 抽卡记录
*/
export const getZZZGachaLogByAuthkey = async (
authKey,
gachaType = '2001',
initLogGachaBaseType = '2',
page = 1,
endId = '0'
) => {
// 获取抽卡链接
const link = await getZZZGachaLink(
authKey,
gachaType,
initLogGachaBaseType,
page,
endId
);
// 发送请求
const response = await request(link, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
retry: 3,
});
// 获取数据
const data = await response.json();
if (!data || !data?.data) return null;
return new ZZZGachaLogResp(data.data);
};

19
lib/gacha/tool.js Normal file
View file

@ -0,0 +1,19 @@
/**
* 欧非分析
* @param {number} ast
* @param {number[]} lst
*/
export const getLevelFromList = (ast, lst) => {
if (ast === 0) {
return 2;
}
let level = 0;
for (let numIndex = 0; numIndex < lst.length; numIndex++) {
if (ast <= lst[numIndex]) {
level = 4 - numIndex;
break;
}
}
return level;
};