-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
255 lines (223 loc) · 14.8 KB
/
Copy pathserver.js
File metadata and controls
255 lines (223 loc) · 14.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
const express = require('express');
const RSSParser = require('rss-parser');
const { fetch: undiciFetch } = require('undici');
const path = require('path');
const fs = require('fs');
const app = express();
app.use(express.json());
// ── Custom fetch with browser-like headers ───────────────────
async function fetchXML(url) {
const res = await undiciFetch(url, {
headers: {
'User-Agent':
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
Accept:
'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.9',
'Cache-Control': 'no-cache',
},
});
if (!res.ok) throw new Error(`Status code ${res.status}`);
return res.text();
}
const parser = new RSSParser();
async function parseFeedURL(url) {
const xml = await fetchXML(url);
return parser.parseString(xml);
}
// ── Feeds ────────────────────────────────────────────────────
const FEEDS = [
// ═══ CRYPTOGRAPHY ══════════════════════════════════════════
// Cryptography — Academic & Research
{ id: 'mdpi-cryptography', name: 'MDPI Cryptography', url: 'https://www.mdpi.com/rss/journal/cryptography', topic: 'cryptography', category: 'academic' },
{ id: 'iacr-news', name: 'IACR News', url: 'https://www.iacr.org/news/rss/', topic: 'cryptography', category: 'academic' },
{ id: 'peerj-crypto', name: 'PeerJ CS Cryptography', url: 'https://peerj.com/articles/index.atom?subject=9400&journal=cs', topic: 'cryptography', category: 'academic' },
{ id: 'mit-crypto', name: 'MIT News — Cryptography', url: 'https://news.mit.edu/rss/topic/cryptography', topic: 'cryptography', category: 'academic' },
{ id: 'sciencedaily-encryption', name: 'ScienceDaily Encryption', url: 'https://www.sciencedaily.com/rss/computers_math/encryption.xml', topic: 'cryptography', category: 'academic' },
// Cryptography — Expert Blogs
{ id: 'schneier-crypto', name: 'Schneier on Security', url: 'https://www.schneier.com/tag/cryptography/feed/', topic: 'cryptography', category: 'blogs' },
{ id: 'crypto-engineering', name: 'Cryptography Engineering', url: 'https://blog.cryptographyengineering.com/feed/', topic: 'cryptography', category: 'blogs' },
{ id: 'martin-albrecht', name: 'Martin Albrecht', url: 'https://martinralbrecht.wordpress.com/tag/cryptography/feed/', topic: 'cryptography', category: 'blogs' },
{ id: 'elliptic-news', name: 'Elliptic News', url: 'https://ellipticnews.wordpress.com/feed/', topic: 'cryptography', category: 'blogs' },
{ id: 'light-blue-touchpaper', name: 'Light Blue Touchpaper', url: 'https://www.lightbluetouchpaper.org/category/security-engineering/cryptology/feed/', topic: 'cryptography', category: 'blogs' },
{ id: 'cryptomathic', name: 'Cryptomathic', url: 'https://www.cryptomathic.com/blog/rss.xml', topic: 'cryptography', category: 'blogs' },
{ id: 'cossack-labs', name: 'Cossack Labs', url: 'https://www.cossacklabs.com/blog/index.xml', topic: 'cryptography', category: 'blogs' },
{ id: 'feisty-duck', name: 'Feisty Duck', url: 'https://www.feistyduck.com/newsletter/feed', topic: 'cryptography', category: 'blogs' },
{ id: 'cryptologie', name: 'Cryptologie (David Wong)', url: 'https://cryptologie.net/feed/', topic: 'cryptography', category: 'blogs' },
{ id: 'imperial-violet', name: 'ImperialViolet (Adam Langley)', url: 'https://www.imperialviolet.org/iv-rss.xml', topic: 'cryptography', category: 'blogs' },
{ id: 'unmitigated-risk', name: 'Unmitigated Risk', url: 'https://unmitigatedrisk.com/?feed=rss2', topic: 'cryptography', category: 'blogs' },
// Cryptography — Industry & Government
{ id: 'nist-crypto', name: 'NIST Cryptography', url: 'https://www.nist.gov/news-events/cryptography/rss.xml', topic: 'cryptography', category: 'industry' },
{ id: 'aws-encryption', name: 'AWS Security — Encryption', url: 'https://aws.amazon.com/blogs/security/tag/encryption/feed/', topic: 'cryptography', category: 'industry' },
{ id: 'tuta-blog', name: 'Tuta Blog', url: 'https://tuta.com/blog/feed.xml', topic: 'cryptography', category: 'industry' },
// Cryptography — Security News
{ id: 'securityweek-crypto', name: 'SecurityWeek Cryptography', url: 'https://www.securityweek.com/topics/cryptography/feed/', topic: 'cryptography', category: 'news' },
{ id: 'security-boulevard', name: 'Security Boulevard', url: 'https://securityboulevard.com/tag/cryptography/feed/', topic: 'cryptography', category: 'news' },
{ id: 'hackernoon-crypto', name: 'HackerNoon Cryptography', url: 'https://hackernoon.com/tagged/cryptography/feed', topic: 'cryptography', category: 'news' },
{ id: 'guardian-encryption', name: 'The Guardian — Encryption', url: 'https://www.theguardian.com/technology/encryption/rss', topic: 'cryptography', category: 'news' },
{ id: 'cointelegraph-crypto', name: 'CoinTelegraph Cryptography', url: 'https://cointelegraph.com/rss/tag/cryptography', topic: 'cryptography', category: 'news' },
{ id: 'linux-security-crypto', name: 'Linux Security — Cryptography', url: 'https://linuxsecurity.com/news/cryptography?format=feed&type=rss', topic: 'cryptography', category: 'news' },
{ id: 'decent-cybersecurity', name: 'Decent Cybersecurity', url: 'https://decentcybersecurity.eu/category/cryptography/feed/', topic: 'cryptography', category: 'news' },
{ id: 'sucuri-encryption', name: 'Sucuri — Encryption', url: 'https://blog.sucuri.net/tag/encryption/feed', topic: 'cryptography', category: 'news' },
{ id: 'medianama-encryption', name: 'MediaNama — Encryption', url: 'https://www.medianama.com/tag/encryption/feed/', topic: 'cryptography', category: 'news' },
{ id: 'it-security-guru-crypto', name: 'IT Security Guru — Crypto', url: 'https://www.itsecurityguru.org/search/cryptography/feed/rss2', topic: 'cryptography', category: 'news' },
{ id: 'it-security-guru-enc', name: 'IT Security Guru — Encryption', url: 'https://www.itsecurityguru.org/search/encryption/feed/rss2', topic: 'cryptography', category: 'news' },
// ═══ QUANTUM COMPUTING ═════════════════════════════════════
// Quantum — Academic & Research
{ id: 'quantum-journal', name: 'Quantum Journal', url: 'https://quantum-journal.org/feed/', topic: 'quantum', category: 'academic' },
{ id: 'mit-quantum', name: 'MIT News — Quantum', url: 'https://news.mit.edu/topic/mitquantum-computing-rss.xml', topic: 'quantum', category: 'academic' },
{ id: 'iqc-waterloo', name: 'IQC Waterloo', url: 'https://uwaterloo.ca/institute-for-quantum-computing/news/news.xml', topic: 'quantum', category: 'academic' },
{ id: 'quantum-frontiers', name: 'Quantum Frontiers', url: 'https://quantumfrontiers.com/feed/', topic: 'quantum', category: 'academic' },
{ id: 'qutech-blog', name: 'QuTech Blog', url: 'https://blog.qutech.nl/feed/', topic: 'quantum', category: 'academic' },
{ id: 'fermilab-quantum', name: 'Fermilab — Quantum', url: 'https://news.fnal.gov/tag/quantum-computing/feed/', topic: 'quantum', category: 'academic' },
{ id: 'sciencedaily-quantum', name: 'ScienceDaily Quantum', url: 'https://www.sciencedaily.com/rss/matter_energy/quantum_computing.xml', topic: 'quantum', category: 'academic' },
{ id: 'sigarch-quantum', name: 'SIGARCH — Quantum', url: 'https://www.sigarch.org/tag/quantum-computing/feed/', topic: 'quantum', category: 'academic' },
{ id: 'peerj-quantum', name: 'PeerJ CS Quantum', url: 'https://peerj.com/articles/index.atom?subject=9400&journal=cs', topic: 'quantum', category: 'academic' },
// Quantum — Industry
{ id: 'aws-quantum', name: 'AWS Quantum Computing', url: 'https://aws.amazon.com/blogs/quantum-computing/feed/', topic: 'quantum', category: 'industry' },
{ id: 'qiskit', name: 'Qiskit (IBM)', url: 'https://medium.com/feed/qiskit', topic: 'quantum', category: 'industry' },
{ id: 'qc-ware', name: 'QC Ware', url: 'https://medium.com/feed/@QC_Ware', topic: 'quantum', category: 'industry' },
{ id: 'universal-quantum', name: 'Universal Quantum', url: 'https://medium.com/feed/@universalquantum', topic: 'quantum', category: 'industry' },
{ id: 'quandela', name: 'Quandela', url: 'https://medium.com/feed/quandela', topic: 'quantum', category: 'industry' },
{ id: 'quantum-south', name: 'Quantum South', url: 'https://quantum-south.com/feed/', topic: 'quantum', category: 'industry' },
// Quantum — Blogs
{ id: 'quantum-rittenhouse', name: 'Quantum Rittenhouse', url: 'https://quantum-rittenhouserv.blogspot.com/feeds/posts/default', topic: 'quantum', category: 'blogs' },
{ id: 'fractal-computing', name: 'Fractal Computing', url: 'https://fractalcomputing.substack.com/feed', topic: 'quantum', category: 'blogs' },
// Quantum — News
{ id: 'quantum-insider', name: 'The Quantum Insider', url: 'https://thequantuminsider.com/feed/', topic: 'quantum', category: 'news' },
{ id: 'quantum-zeitgeist', name: 'Quantum Zeitgeist', url: 'https://quantumzeitgeist.com/feed/', topic: 'quantum', category: 'news' },
{ id: 'quantum-computing-report', name: 'QC Report', url: 'https://quantumcomputingreport.com/feed/', topic: 'quantum', category: 'news' },
{ id: 'inside-quantum-tech', name: 'Inside Quantum Technology', url: 'https://www.insidequantumtechnology.com/feed/', topic: 'quantum', category: 'news' },
{ id: 'geekwire-quantum', name: 'GeekWire — Quantum', url: 'https://www.geekwire.com/tag/quantum-computing/feed/', topic: 'quantum', category: 'news' },
{ id: 'nextbigfuture-quantum', name: 'Next Big Future — Quantum', url: 'https://www.nextbigfuture.com/tag/quantum-computers/feed', topic: 'quantum', category: 'news' },
{ id: 'techexplorist-quantum', name: 'Tech Explorist — Quantum', url: 'https://www.techexplorist.com/technology/quantum-computing/feed/', topic: 'quantum', category: 'news' },
{ id: 'meritalk-quantum', name: 'MeriTalk — Quantum', url: 'https://www.meritalk.com/tag/quantum-computing/feed/', topic: 'quantum', category: 'news' },
];
// ── Cache ────────────────────────────────────────────────────
const cache = {};
const CACHE_TTL = 15 * 60 * 1000;
function normalizeItems(items, feedId, feedName) {
return items.map((item) => ({
id: item.guid || item.link || `${feedId}-${item.title}`,
title: item.title,
link: item.link,
description: item.contentSnippet || item.content || item.description,
author: item.creator || item.author || item['dc:creator'],
pubDate: item.pubDate || item.isoDate,
categories: item.categories || [],
feedId,
feedName,
}));
}
async function fetchSingleFeed(feed) {
const cached = cache[feed.id];
if (cached && Date.now() - cached.timestamp < CACHE_TTL) {
return cached.data;
}
const parsed = await parseFeedURL(feed.url);
const data = {
id: feed.id,
name: feed.name,
topic: feed.topic,
category: feed.category,
title: parsed.title,
description: parsed.description,
link: parsed.link,
items: normalizeItems(parsed.items, feed.id, feed.name),
};
cache[feed.id] = { data, timestamp: Date.now() };
return data;
}
// ── Read state persistence (in-memory with async flush) ──────
const READ_STATE_FILE = path.join(__dirname, '.readstate.json');
let readStateCache;
let flushTimer = null;
const FLUSH_DELAY = 1000;
const PRUNE_AGE = 90 * 24 * 60 * 60 * 1000; // 90 days
function loadReadState() {
if (readStateCache) return readStateCache;
try {
readStateCache = JSON.parse(fs.readFileSync(READ_STATE_FILE, 'utf8'));
} catch {
readStateCache = {};
}
return readStateCache;
}
function scheduleFlush() {
if (flushTimer) return;
flushTimer = setTimeout(() => {
flushTimer = null;
const cutoff = Date.now() - PRUNE_AGE;
const pruned = {};
for (const [k, v] of Object.entries(readStateCache)) {
if (v > cutoff) pruned[k] = v;
}
readStateCache = pruned;
fs.writeFile(READ_STATE_FILE, JSON.stringify(pruned), () => {});
}, FLUSH_DELAY);
}
// Flush on exit
process.on('exit', () => {
if (readStateCache) {
try { fs.writeFileSync(READ_STATE_FILE, JSON.stringify(readStateCache)); } catch {}
}
});
process.on('SIGINT', () => process.exit());
process.on('SIGTERM', () => process.exit());
// ── Static files ─────────────────────────────────────────────
app.use(express.static(path.join(__dirname, 'public')));
// ── API routes ───────────────────────────────────────────────
app.get('/api/feeds', (_req, res) => {
res.json(FEEDS.map(({ id, name, topic, category }) => ({ id, name, topic, category })));
});
app.get('/api/feed/:id', async (req, res) => {
const feed = FEEDS.find((f) => f.id === req.params.id);
if (!feed) return res.status(404).json({ error: 'Feed not found' });
try {
const data = await fetchSingleFeed(feed);
res.json(data);
} catch (err) {
console.error(`Failed to fetch feed ${feed.id}:`, err.message);
res.status(502).json({ error: 'Failed to fetch feed', detail: err.message });
}
});
app.get('/api/all', async (_req, res) => {
const results = await Promise.allSettled(FEEDS.map(fetchSingleFeed));
const feeds = [];
const errors = [];
results.forEach((r, i) => {
if (r.status === 'fulfilled') feeds.push(r.value);
else errors.push({ feed: FEEDS[i].id, name: FEEDS[i].name, error: r.reason?.message });
});
res.json({ feeds, errors });
});
// ── Read state API ───────────────────────────────────────────
app.get('/api/read', (_req, res) => {
res.json(loadReadState());
});
app.post('/api/read', (req, res) => {
const { id, read } = req.body;
if (!id) return res.status(400).json({ error: 'Missing article id' });
const state = loadReadState();
if (read === false) {
delete state[id];
} else {
state[id] = Date.now();
}
scheduleFlush();
res.json({ ok: true });
});
app.post('/api/read/bulk', (req, res) => {
const { ids } = req.body;
if (!Array.isArray(ids)) return res.status(400).json({ error: 'ids must be an array' });
const state = loadReadState();
const now = Date.now();
ids.forEach((id) => { state[id] = now; });
scheduleFlush();
res.json({ ok: true });
});
// ── Start ────────────────────────────────────────────────────
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Cryptography RSS Reader running at http://localhost:${PORT}`);
});