automatic months
This commit is contained in:
parent
e2272414dc
commit
a805914fe6
11
app.js
11
app.js
@ -876,8 +876,15 @@ async function loadAvailableMonths() {
|
|||||||
// Load TinyColor first
|
// Load TinyColor first
|
||||||
await loadTinyColor();
|
await loadTinyColor();
|
||||||
|
|
||||||
// Include all available months
|
// Fetch available months from server
|
||||||
const months = ['2025-01', '2025-02'];
|
const response = await fetch('/api/months');
|
||||||
|
const months = await response.json();
|
||||||
|
|
||||||
|
if (months.length === 0) {
|
||||||
|
console.error('No month data files found');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const select = document.getElementById('month-select');
|
const select = document.getElementById('month-select');
|
||||||
|
|
||||||
// Clear existing options
|
// Clear existing options
|
||||||
|
|||||||
25
server.js
25
server.js
@ -13,6 +13,31 @@ const MIME_TYPES = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const server = http.createServer((req, res) => {
|
const server = http.createServer((req, res) => {
|
||||||
|
// API endpoint to list available months
|
||||||
|
if (req.url === '/api/months') {
|
||||||
|
fs.readdir('.', (err, files) => {
|
||||||
|
if (err) {
|
||||||
|
res.writeHead(500, { 'Content-Type': 'application/json' });
|
||||||
|
res.end(JSON.stringify({ error: 'Failed to read directory' }));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find CSV files matching altcats-YYYY-MM.csv pattern
|
||||||
|
const monthPattern = /^altcats-(\d{4}-\d{2})\.csv$/;
|
||||||
|
const months = files
|
||||||
|
.map(file => {
|
||||||
|
const match = file.match(monthPattern);
|
||||||
|
return match ? match[1] : null;
|
||||||
|
})
|
||||||
|
.filter(Boolean)
|
||||||
|
.sort();
|
||||||
|
|
||||||
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||||
|
res.end(JSON.stringify(months));
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Handle URL
|
// Handle URL
|
||||||
let filePath = '.' + req.url;
|
let filePath = '.' + req.url;
|
||||||
if (filePath === './') {
|
if (filePath === './') {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user