maplestory/backend/routes/sunday-maple.js
caadiq a94137bd4d 썬데이 메이플 자동 수집 백엔드
- sequelize 모델: sunday_maple (week_start/variant/image_url 등)
- services/sundayMaple.js: 이벤트 API 조회 + HTML 스크래핑 + rustfs 업로드 + DB 저장 공용 함수
- services/sundayMapleCron.js: 금요일 09:00 KST에 10초 간격 폴링 (최대 5분)
- routes/sunday-maple.js: GET /api/sunday-maple/current
  * 금/토/일만 available
  * DB 없으면 lazy fetch 시도 (cron miss 대비)
- 제목 파싱으로 normal/special variant 판별
- rustfs 경로: maplestory/sunday/{week_start}.png

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 16:30:30 +09:00

45 lines
1.2 KiB
JavaScript

import { Router } from 'express';
import { SundayMaple } from '../models/index.js';
import {
currentWeekFriday,
isInSundayWindow,
fetchAndSaveSundayMaple,
} from '../services/sundayMaple.js';
const router = Router();
// 이번 주 썬데이 메이플 조회 (금~일만 available)
router.get('/current', async (req, res) => {
try {
if (!isInSundayWindow()) {
return res.json({ available: false });
}
const weekStart = currentWeekFriday();
let row = await SundayMaple.findOne({ where: { week_start: weekStart } });
// DB에 없으면 lazy fetch 시도 (cron이 놓친 경우 대비)
if (!row) {
try {
row = await fetchAndSaveSundayMaple();
} catch (err) {
console.error('[sunday-maple] lazy fetch 실패:', err.message);
}
}
if (!row) return res.json({ available: false });
res.json({
available: true,
variant: row.variant,
week_start: row.week_start,
image_url: row.image_url,
event_post_url: row.event_post_url,
});
} catch (err) {
console.error('[sunday-maple/current] 오류:', err);
res.status(500).json({ error: '조회 실패' });
}
});
export default router;