Repository navigation
Expand file tree
/
Copy patharxiv.js
More file actions
54 lines (48 loc) · 1.74 KB
/
Copy patharxiv.js
File metadata and controls
54 lines (48 loc) · 1.74 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
export const config = { runtime: 'edge' };
// Fetch AI/ML papers from ArXiv
// Categories: cs.AI, cs.LG (Machine Learning), cs.CL (Computation and Language)
export default async function handler(request) {
try {
const { searchParams } = new URL(request.url);
const category = searchParams.get('category') || 'cs.AI'; // cs.AI, cs.LG, cs.CL
const maxResults = searchParams.get('max_results') || '50';
const sortBy = searchParams.get('sortBy') || 'submittedDate'; // submittedDate, lastUpdatedDate, relevance
// ArXiv API search query
// Search for papers in specified category, sorted by date
const query = `cat:${category}`;
const apiUrl = `http://export.arxiv.org/api/query?search_query=${encodeURIComponent(query)}&start=0&max_results=${maxResults}&sortBy=${sortBy}&sortOrder=descending`;
const response = await fetch(apiUrl, {
headers: {
'User-Agent': 'WorldMonitor/1.0 (AI Research Tracker)',
},
});
if (!response.ok) {
throw new Error(`ArXiv API returned ${response.status}`);
}
const xmlData = await response.text();
// Parse XML to extract key information
// Return raw XML for client-side parsing or transform here
return new Response(xmlData, {
status: 200,
headers: {
'Content-Type': 'application/xml',
'Access-Control-Allow-Origin': '*',
'Cache-Control': 'public, max-age=3600', // 1 hour cache
},
});
} catch (error) {
return new Response(
JSON.stringify({
error: 'Failed to fetch ArXiv data',
message: error.message
}),
{
status: 500,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
},
}
);
}
}