From 0bd12cb694d714320a6a7afb3f81961e79e74f4f Mon Sep 17 00:00:00 2001 From: IITII Date: Mon, 4 Dec 2023 16:28:11 +0800 Subject: [PATCH] ref: env --- bin/redis_sub_utils.js | 4 ++-- config/config.js | 19 ++++++++++++------- services/utils/redis_utils.js | 6 +++--- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/bin/redis_sub_utils.js b/bin/redis_sub_utils.js index d7b3a5f..c66a873 100644 --- a/bin/redis_sub_utils.js +++ b/bin/redis_sub_utils.js @@ -3,7 +3,7 @@ const {get_sent_sub} = require("../services/utils/redis_utils"); const redis = require("../libs/redis_client"); -async function reformat_keys(func, prefix, expire = taskLimit.sub_expire) { +async function reformat_keys(func, prefix) { const sent_urls = await get_sent_sub(prefix) let diff = [] sent_urls.forEach(s => { @@ -19,7 +19,7 @@ async function reformat_keys(func, prefix, expire = taskLimit.sub_expire) { diff.forEach(d => { const [s, ss] = d mul.DEL(`${prefix}${s}`) - mul.SETEX(`${prefix}${ss}`, expire, v) + mul.SET(`${prefix}${ss}`, v) }) await mul.exec() await redis.quit() diff --git a/config/config.js b/config/config.js index 05ddeac..712ca97 100644 --- a/config/config.js +++ b/config/config.js @@ -70,11 +70,11 @@ const config = { }, check: { // 随机时长比例 - randomRate: 0.20, + randomRate: process.env.CHECK_RANDOM_RATE, // 默认任务检查时间间隔, 6h - all: 1000 * 60 * 60 * 6, + all: process.env.CHECK_ALL, // 5 分钟检查一次 redis - period: 1000 * 60 * 5, + period: process.env.CHECK_PERIOD, }, taskName: 'bot_schedule_task', taskLimit: { @@ -88,8 +88,9 @@ const config = { latest: 3, // 第一次运行时最多发送条数 firstMax: 50, + // 重复的太多, 不设置过期了 // 订阅已发送链接过期时间, 5years - sub_expire: 60 * 60 * 24 * 30 * 12 * 5, + // sub_expire: 60 * 60 * 24 * 30 * 12 * 5, // 订阅已发送链接 sub_prefix: { url: 'bot_sent_sub_url_', @@ -101,13 +102,13 @@ const config = { }, }, redis: { - url: process.env.REDIS_URL || 'redis://:review_pic@127.0.0.1:6379', + url: process.env.REDIS_URL || 'redis://:review_pic@redis:6379', }, cookies: { // cookie 设置 acgBox: { - cookie: 'abb76c49380724ba45b0b8adb589f243protectPassword=acgbox', - postBody: {protectPassword: 'acgbox'}, + cookie: process.env.ACG_BOX_COOKIE || 'abb76c49380724ba45b0b8adb589f243protectPassword=acgbox', + postBody: {protectPassword: process.env.ACG_BOX_PASSWORD || 'acgbox'}, }, }, // 并发限制 @@ -185,6 +186,10 @@ if (!config.db.database) { config.db.database = path.resolve(__dirname, config.db.database) mkdir(path.dirname(config.db.database)) +config.check.randomRate = parseFloat(config.check.randomRate) || 0.2 +config.check.all = (parseInt(config.check.all) || 6) * 60 * 60 * 1000 +config.check.period = (parseInt(config.check.period) || 5) * 60 * 1000 + function mkdir(dir) { if (!fs.existsSync(dir)) { fs.mkdirSync(dir, {recursive: true}) diff --git a/services/utils/redis_utils.js b/services/utils/redis_utils.js index 6391db5..430a0ec 100644 --- a/services/utils/redis_utils.js +++ b/services/utils/redis_utils.js @@ -111,13 +111,13 @@ async function get_sent_sub(prefix = taskLimit.sub_prefix.url) { return keys.map(k => k.replace(prefix, '')) } -async function set_sent_sub(url_texts, prefix = taskLimit.sub_prefix, expire = taskLimit.sub_expire) { +async function set_sent_sub(url_texts, prefix = taskLimit.sub_prefix) { if (Array.isArray(url_texts) && url_texts.length === 0) return await redis_init() const mul = redis.multi() url_texts.forEach(({url, text}) => { - mul.SETEX(`${prefix.url}${url}`, expire, text) - mul.SETEX(`${prefix.text}${text}`, expire, url) + mul.SET(`${prefix.url}${url}`, text) + mul.SET(`${prefix.text}${text}`, url) }) await mul.exec() }