automatic months
This commit is contained in:
parent
e2272414dc
commit
a805914fe6
15
app.js
15
app.js
@ -875,9 +875,16 @@ function loadTinyColor() {
|
||||
async function loadAvailableMonths() {
|
||||
// Load TinyColor first
|
||||
await loadTinyColor();
|
||||
|
||||
// Include all available months
|
||||
const months = ['2025-01', '2025-02'];
|
||||
|
||||
// Fetch available months from server
|
||||
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');
|
||||
|
||||
// Clear existing options
|
||||
@ -1270,4 +1277,4 @@ function setupHoverEvents(sunburstData) {
|
||||
// Reset to default view when a section is no longer emphasized
|
||||
showDefaultView();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
31
server.js
31
server.js
@ -13,15 +13,40 @@ const MIME_TYPES = {
|
||||
};
|
||||
|
||||
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
|
||||
let filePath = '.' + req.url;
|
||||
if (filePath === './') {
|
||||
filePath = './index.html';
|
||||
}
|
||||
|
||||
|
||||
const extname = path.extname(filePath);
|
||||
const contentType = MIME_TYPES[extname] || 'application/octet-stream';
|
||||
|
||||
|
||||
fs.readFile(filePath, (err, data) => {
|
||||
if (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
@ -33,7 +58,7 @@ const server = http.createServer((req, res) => {
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
res.writeHead(200, { 'Content-Type': contentType });
|
||||
res.end(data);
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user