Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/app/main.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const settingsModel = require('./settings.cjs');
const { createApi, ApiError } = require('./api.cjs');
const { buildFiles, buildCourses } = require('./report.cjs');
const { buildIndex } = require('./dedupe.cjs');
const { createCatalog, wordMatcher } = require('../sync/avenue/catalog.cjs');
const { createCatalog, wordMatcher, uniqueDeadlines } = require('../sync/avenue/catalog.cjs');
const extractor = require('./extract.cjs');
const { installCommandLine, commandLineStatus, syncCliCopy, isTemporaryLocation } = require('./command-line.cjs');
const connectAi = require('./connect-ai.cjs');
Expand Down Expand Up @@ -330,7 +330,7 @@ function apiHandlers() {
if (at >= now && at <= horizon) items.push({ course: target.code, title: deadline.title, dueAt: deadline.dueAt, url: deadline.url || '' });
}
}
return { days, items: items.sort((a, b) => Date.parse(a.dueAt) - Date.parse(b.dueAt)) };
return { days, items: uniqueDeadlines(items).sort((a, b) => Date.parse(a.dueAt) - Date.parse(b.dueAt)) };
} catch (error) { return refused(error); }
},
news: async ({ course, since, limit, fresh }) => {
Expand Down
13 changes: 12 additions & 1 deletion src/sync/avenue/catalog.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ const kindsKey = (kinds) => JSON.stringify(Object.keys(kinds || {}).filter((kind

const isFresh = (stamp, now = Date.now()) => Boolean(stamp) && now - Date.parse(stamp) < TTL_MS && now >= Date.parse(stamp);

// An assignment folder and a calendar event often announce the same deadline; keep the first of each.
const uniqueDeadlines = (items) => {
const seen = new Set();
return items.filter((item) => {
const key = `${item.course}|${item.title.trim().toLowerCase()}|${Date.parse(item.dueAt)}`;
if (seen.has(key)) return false;
seen.add(key);
return true;
});
};

function createCatalog(file) {
let data = null;
let loading = null;
Expand Down Expand Up @@ -66,4 +77,4 @@ function createCatalog(file) {
};
}

module.exports = { createCatalog, toRecords, matchRecords, wordMatcher, kindsKey, isFresh, TTL_MS };
module.exports = { createCatalog, uniqueDeadlines, toRecords, matchRecords, wordMatcher, kindsKey, isFresh, TTL_MS };
11 changes: 11 additions & 0 deletions test/avenue-sync.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,14 @@ test('a read racing the first update cannot bring back older data', async () =>
await Promise.all([catalog.get('1'), catalog.put('2', { code: 'NEW' }), catalog.get('2')]);
assert.deepEqual(Object.keys(JSON.parse(fs.readFileSync(file, 'utf8')).courses).sort(), ['1', '2']);
});

test('the same deadline reported twice (folder and calendar) is listed once', () => {
const { uniqueDeadlines } = require('../src/sync/avenue/catalog.cjs');
const items = [
{ course: 'A', title: 'Assignment 4', dueAt: '2026-12-10T23:59:00.000Z' },
{ course: 'A', title: ' assignment 4 ', dueAt: '2026-12-10T23:59:00Z' },
{ course: 'B', title: 'Assignment 4', dueAt: '2026-12-10T23:59:00.000Z' },
{ course: 'A', title: 'Assignment 4', dueAt: '2026-12-11T23:59:00.000Z' },
];
assert.equal(uniqueDeadlines(items).length, 3);
});
Loading