pref: 多账号信息不直接写入环境变量

feat: docker 初始化
This commit is contained in:
shanmite 2021-06-03 19:16:43 +08:00
parent 32c9197a6d
commit ae9ef7ad79
4 changed files with 55 additions and 5 deletions

6
.dockerignore Normal file
View File

@ -0,0 +1,6 @@
node_modules/
package-lock.json
lib/dyid*.txt
dyid.zip
env.js
my_config.json

14
Dockerfile Normal file
View File

@ -0,0 +1,14 @@
# Latest Nodejs + Alpine Linux
FROM node:lts-alpine
MAINTAINER shanmite@github.com
LABEL version="0.1" description="自动参与B站动态抽奖"
WORKDIR /lottery
COPY ["package.json", "./"]
RUN npm install
CMD echo "Hello"

View File

@ -4,15 +4,16 @@
*/
/**
* # 账号相关参数
* ## 账号相关参数
* `COOKIE` 是必填项
* `NUMBER` 表示是第几个账号
* `PAT` `GITHUB_REPOSITORY` 如果之前在Github Action上运行过脚本, 可填写已下载转发过的动态dyid, 之后可移除
*
* # 多账号
* ## 多账号
* ENABLE_MULTIPLE_ACCOUNT 的值改为true
* 将账号信息依次填写于 MULTIPLE_ACCOUNT , 参考例子类推
* `WAIT` 表示下一个账号运行等待时间(毫秒)
* **按顺序依次执行, 防止访问频繁封禁IP**
*/
const account_parm = {
COOKIE: "",
@ -22,6 +23,7 @@ const account_parm = {
PAT: "",
GITHUB_REPOSITORY: "用户名/仓库名",
ENABLE_MULTIPLE_ACCOUNT: false,
/* 不推荐 */
MULTIPLE_ACCOUNT: JSON.stringify([
{
COOKIE: "",
@ -38,6 +40,24 @@ const account_parm = {
])
}
/**
* 为防止环境变量过长, 请将多账号填在此处
*/
const multiple_account_parm = [
{
COOKIE: "",
NUMBER: 1,
CLEAR: true,
WAIT: 60 * 1000,
},
// {
// COOKIE: "",
// NUMBER: 2,
// CLEAR: true,
// WAIT: 60 * 1000,
// },
]
/**
* 推送相关参数
*/
@ -77,4 +97,4 @@ function initEnv() {
}
module.exports = { initEnv };
module.exports = { initEnv, multiple_account_parm };

14
main.js
View File

@ -1,7 +1,10 @@
const { tooltip, delay } = require("./lib/Base");
let multiple_account = [];
if (!process.env.CI) {
const { initEnv } = require("./env");
const { initEnv, multiple_account_parm } = require("./env");
multiple_account = multiple_account_parm;
initEnv()
}
@ -9,8 +12,12 @@ async function main() {
const { COOKIE, NUMBER, CLEAR, PAT, LOCALLAUNCH, ENABLE_MULTIPLE_ACCOUNT, MULTIPLE_ACCOUNT } = process.env;
if (LOCALLAUNCH || PAT) {
if (ENABLE_MULTIPLE_ACCOUNT) {
let muti_acco = JSON.parse(MULTIPLE_ACCOUNT);
let muti_acco = multiple_account.length
? multiple_account
: JSON.parse(MULTIPLE_ACCOUNT);
process.env.ENABLE_MULTIPLE_ACCOUNT = '';
for (const acco of muti_acco) {
process.env.COOKIE = acco.COOKIE;
process.env.NUMBER = acco.NUMBER;
@ -22,9 +29,12 @@ async function main() {
if (COOKIE) {
const { setVariable } = require("./lib/setVariable");
await setVariable(COOKIE, Number(NUMBER));
const { start, isMe, checkCookie } = require("./lib/lottery-in-nodejs");
const { clear } = require("./lib/clear");
tooltip.log('[LotteryAutoScript] 账号' + NUMBER);
if (await checkCookie(NUMBER)) {
switch (process.argv.slice(2)[0]) {
case 'start':