From 66ccd15606ffefc4cd24ee63d9ee795d44020493 Mon Sep 17 00:00:00 2001 From: Tomachi <8929706+book000@users.noreply.github.com> Date: Sat, 28 Jan 2023 16:15:11 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20Docker=E3=81=A7=E5=8B=95=E3=81=8B?= =?UTF-8?q?=E3=81=97=E3=81=9F=E5=A0=B4=E5=90=88=E3=81=AE=E7=92=B0=E5=A2=83?= =?UTF-8?q?=E5=A4=89=E6=95=B0=E3=82=92=E4=BF=AE=E6=AD=A3=20(#28)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 4 ++-- src/config.ts | 17 ++++++++++------- src/main.ts | 8 +++++++- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9a007c2..c55cd04 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,8 +29,8 @@ WORKDIR /app COPY --from=builder /app/output . ENV NODE_ENV=production -ENV CONFIG_FILE=/data/config.json -ENV TOKEN_FILE=/data/token.json +ENV CONFIG_PATH=/data/config.json +ENV NOTIFIED_PATH=/data/notified.json COPY entrypoint.sh . RUN chmod +x entrypoint.sh diff --git a/src/config.ts b/src/config.ts index 435bcbf..66f42f0 100644 --- a/src/config.ts +++ b/src/config.ts @@ -21,15 +21,18 @@ const isConfig = (config: any): config is Configuration => { return ( config && typeof config.discord === 'object' && - // webhook_url がない場合は、token と channel_id がなければならない + // webhook_url があるか token と channel_id があるか (config.discord.webhook_url || (config.discord.token && config.discord.channel_id)) && - // token がある場合は、channel_id がなければならない - (!config.discord.token || config.discord.channel_id) && - // token と channel_id がない場合は、webhook_url がなければならない - (!config.discord.token || - !config.discord.channel_id || - config.discord.webhook_url) + // webhook_url があるとき、string である + (config.discord.webhook_url === undefined || + typeof config.discord.webhook_url === 'string') && + // token があるとき、string である + (config.discord.token === undefined || + typeof config.discord.token === 'string') && + // channel_id があるとき、string である + (config.discord.channel_id === undefined || + typeof config.discord.channel_id === 'string') ) } diff --git a/src/main.ts b/src/main.ts index 0dc3ed9..b0a844a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -10,6 +10,7 @@ function formatDate(dateRaw: string): string { async function main() { const config = loadConfig() + console.log('📡 Fetching campaigns...') const campaigns = await getCampaigns() const isFirst = Notified.isFirst() @@ -17,6 +18,7 @@ async function main() { const newCampaigns = campaignInfos.filter((campaignInfo) => { return !Notified.isNotified(campaignInfo.eventCode) }) + console.log(`📝 ${newCampaigns.length} new campaigns found.`) for (const campaignInfo of newCampaigns) { const { @@ -61,5 +63,9 @@ async function main() { } ;(async () => { - await main() + await main().catch((error) => { + console.error(error) + // eslint-disable-next-line unicorn/no-process-exit + process.exit(1) + }) })()