Skip to content

Commit

Permalink
ref: env
Browse files Browse the repository at this point in the history
  • Loading branch information
IITII committed Dec 4, 2023
1 parent dcbb36b commit 0bd12cb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions bin/redis_sub_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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()
Expand Down
19 changes: 12 additions & 7 deletions config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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_',
Expand All @@ -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'},
},
},
// 并发限制
Expand Down Expand Up @@ -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})
Expand Down
6 changes: 3 additions & 3 deletions services/utils/redis_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit 0bd12cb

Please sign in to comment.