Compare commits

...

2 Commits

Author SHA1 Message Date
hojin.jeong 092df29869 config.json case bugfixe 2025-08-25 16:25:44 +09:00
hojin.jeong 4301e3003f config env bugfixes 2025-08-25 16:23:30 +09:00
2 changed files with 8 additions and 9 deletions

14
app.js
View File

@ -6,22 +6,24 @@ const NTFY = require('./lib/ntfy')
const Constants = require('./lib/constants')
new class LottoAutomation {
#config = {}
#configFilename = process.env.LOTTO_AUTOMATION_CONFIG_FILENAME ?? 'config.json'
#configPath = `${process.env.LOTTO_AUTOMATION_CONFIG_DIR ?? __dirname}/${this.#configFilename}`
#config = {}
#_start() {
this.#_loadConfig()
setImmediate(this.#_buyLotto.bind(this))
}
#_loadConfig() {
if(!Fs.existsSync(Constants.CONFIG_PATH))
throw new Error('Config.json 파일이 존재하지 않습니다.')
if(!Fs.existsSync(this.#configPath))
throw new Error('config.json 파일이 존재하지 않습니다.')
try {
const configString = Fs.readFileSync(Constants.CONFIG_PATH)
const configString = Fs.readFileSync(this.#configPath)
this.#config = JSON.parse(configString)
NTFY.Init(this.#config.ntfyUrl, this.#config.ntfyToken)
} catch(e) {
throw new Error('Config.json 파일이 올바르지 않습니다.')
throw new Error('config.json 파일이 올바르지 않습니다.')
}
}
async #_buyLotto() {
@ -36,7 +38,7 @@ new class LottoAutomation {
const successMessageArr = [
`구매 성공`,
`ROUND: ${buyResult.round}`,
`COST : ${buyResult.cost}`,
`COST: ${buyResult.cost}`,
]
successMessageArr.push(
...buyResult.numbers.map(numberStr => {

View File

@ -36,9 +36,6 @@ class Constants {
'2': '반자동',
'3': '자동'
}
static CONFIG_FILENAME = process.env.LOTTO_AUTOMATION_CONFIG_FILENAME ?? 'Config.json'
static CONFIG_PATH = `${process.env.LOTTO_AUTOMATION_CONFIG_DIR ?? '.'}/${Constants.CONFIG_FILENAME}`
}
module.exports = Constants