Fix Docker build error; add multi-year view, PDF export, ntfy notifier
Fix: remove unused 'accessibleMonths' variable (tsc exit code 2) Features: - AllYearsLetter view: all years in chronological order, reachable from "All Years" at the top of the sidebar - PDF export: window.print() with @media print CSS — sidebar, toolbar, and chrome hidden; each year starts on a new page via page-break - "Download all" exports a plain-text file of every year's letter - ntfy notifier: standalone Node.js service (notifier/) that fires a push notification via ntfy on the 1st of each month; configurable via NTFY_TOPIC, NTFY_URL, CRON_SCHEDULE, APP_URL env vars - docker-compose: adds `notifier` service alongside `app`; reads from .env (example in .env.example); NTFY_TEST_ON_START=true sends a test ping on container start Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
54d54c2e1a
commit
7f38c038fb
11 files changed
+275
-2
No files matched your search
@@ -0,0 +1,6 @@
|
||||
FROM node:20-alpine
|
||||
WORKDIR /app
|
||||
COPY package.json ./
|
||||
RUN npm install --omit=dev
|
||||
COPY index.mjs ./
|
||||
CMD ["node", "index.mjs"]
|
||||
@@ -0,0 +1,63 @@
|
||||
import cron from "node-cron";
|
||||
|
||||
const NTFY_URL = process.env.NTFY_URL || "https://ntfy.sh";
|
||||
const NTFY_TOPIC = process.env.NTFY_TOPIC;
|
||||
const CRON_SCHEDULE = process.env.CRON_SCHEDULE || "0 9 1 * *"; // 9 AM on the 1st of each month
|
||||
const APP_URL = process.env.APP_URL || "http://localhost:8080";
|
||||
|
||||
if (!NTFY_TOPIC) {
|
||||
console.error("NTFY_TOPIC is required. Set it in your environment or docker-compose.");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const MONTH_NAMES = [
|
||||
"January", "February", "March", "April", "May", "June",
|
||||
"July", "August", "September", "October", "November", "December",
|
||||
];
|
||||
|
||||
async function sendReminder() {
|
||||
const now = new Date();
|
||||
// We fire on the 1st — remind for the month that just ended
|
||||
const prevMonth = new Date(now.getFullYear(), now.getMonth() - 1, 1);
|
||||
const monthName = MONTH_NAMES[prevMonth.getMonth()];
|
||||
const year = prevMonth.getFullYear();
|
||||
|
||||
const title = `Time to write your ${monthName} letter`;
|
||||
const message = `${monthName} ${year} is done. Take 10 minutes to capture the month before it fades. Open your letter app to answer this month's 6 prompts.`;
|
||||
|
||||
try {
|
||||
const res = await fetch(`${NTFY_URL}/${NTFY_TOPIC}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Title: title,
|
||||
Priority: "default",
|
||||
Tags: "pencil,calendar",
|
||||
Click: APP_URL,
|
||||
"Content-Type": "text/plain",
|
||||
},
|
||||
body: message,
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
console.log(`[${new Date().toISOString()}] Reminder sent for ${monthName} ${year}`);
|
||||
} else {
|
||||
console.error(`[${new Date().toISOString()}] ntfy returned ${res.status}: ${await res.text()}`);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(`[${new Date().toISOString()}] Failed to send reminder:`, err.message);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`[${new Date().toISOString()}] Notifier started`);
|
||||
console.log(` Topic: ${NTFY_URL}/${NTFY_TOPIC}`);
|
||||
console.log(` Schedule: ${CRON_SCHEDULE}`);
|
||||
console.log(` App URL: ${APP_URL}`);
|
||||
|
||||
// Run on schedule
|
||||
cron.schedule(CRON_SCHEDULE, sendReminder, { timezone: "America/Chicago" });
|
||||
|
||||
// Send a startup test ping in dev mode
|
||||
if (process.env.NTFY_TEST_ON_START === "true") {
|
||||
console.log("Sending test notification on startup...");
|
||||
sendReminder();
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "letter-notifier",
|
||||
"version": "1.0.0",
|
||||
"type": "module",
|
||||
"main": "index.mjs",
|
||||
"dependencies": {
|
||||
"node-cron": "^3.0.3"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user