forked from sam/fedifeed
add client-side caching
This commit is contained in:
parent
3b682a12f4
commit
49f6a0b8e2
2 changed files with 13 additions and 1 deletions
8
index.js
8
index.js
|
@ -27,6 +27,12 @@ app.use(
|
|||
})
|
||||
);
|
||||
|
||||
function doCache(res,durationSecs){
|
||||
res.set({
|
||||
"Cache-Control":"max-age="+durationSecs
|
||||
})
|
||||
}
|
||||
|
||||
app.options('/api/feed',cors());
|
||||
app.get('/api/feed',cors(),function(req,res){
|
||||
|
||||
|
@ -79,6 +85,7 @@ app.get('/api/feed',cors(),function(req,res){
|
|||
return res.send('Error fetching or parsing your feed.');
|
||||
}
|
||||
res.status(200);
|
||||
doCache(res,60*60)
|
||||
res.send(data);
|
||||
});
|
||||
|
||||
|
@ -135,6 +142,7 @@ app.get('/apiv2/feed',cors(),function(req,res){
|
|||
|
||||
convertv2(opts).then((data)=>{
|
||||
res.status(200);
|
||||
doCache(res,60*60);
|
||||
res.send(data);
|
||||
}).catch((er)=>{
|
||||
res.status(500);
|
||||
|
|
|
@ -115,6 +115,10 @@ async function itemsForFeed(opts,user,feed) {
|
|||
// console.log(boostData[0]);
|
||||
|
||||
boostData.forEach((boostToot)=>{
|
||||
|
||||
if (!boostToot.id){
|
||||
return;// case where it's a {} b/c the request failed or w/e
|
||||
}
|
||||
|
||||
// inject in-place into items
|
||||
|
||||
|
@ -127,7 +131,7 @@ async function itemsForFeed(opts,user,feed) {
|
|||
}
|
||||
|
||||
if (index == -1){
|
||||
console.warn("warning: couldn't match boost to item: ",boostToot.id)
|
||||
console.warn("warning: couldn't match boost to item: ",boostToot)
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue