diff --git a/index.js b/index.js index 52ab2e8..ba33fbc 100644 --- a/index.js +++ b/index.js @@ -95,7 +95,7 @@ app.get('/apiv2/feed',cors(),function(req,res){ res.send('You need to specify a user URL'); } - var feedUrl = req.query.feedUrl; + var feedUrl = req.query.feedurl; var opts = {}; if (req.query.size){ @@ -140,7 +140,7 @@ app.get('/apiv2/feed',cors(),function(req,res){ res.status(500); res.send('Error fetching or parsing your feed.'); // TODO log the error - console.error(er); + console.error(er,er.stack); }) }) diff --git a/lib/convertv2.js b/lib/convertv2.js index 53bb9e6..5996e87 100644 --- a/lib/convertv2.js +++ b/lib/convertv2.js @@ -41,13 +41,11 @@ module.exports = async function (opts) { var feed = await apGet(feedUrl); - var items = itemsForFeed(feed); - var templateData = { opts: opts,// from the request meta: metaForUser(user), - items: itemsForFeed(feed), - nextPageLink: getNextPage(user,feed), + items: itemsForFeed(user,feed), + nextPageLink: getNextPage(opts,user,feed), isIndex: isIndex }; @@ -65,29 +63,60 @@ function metaForUser(user) { } // TODO make function -function itemsForFeed(feed) { - return feed.orderedItems.map((item)=>{ +function itemsForFeed(user,feed) { + + return feed.orderedItems.filter((item)=>{ + // this is temporary, don't handle boosts + return item.type == "Create" && item.object && item.object.type=="Note"; + }).map((item)=>{ + + + //needs to be { type, url } + var enclosures = (item.object.attachment||[]).filter((a)=>{ + return a.type == "Document"; + }).map((a)=>{ + return { + type:a.mediaType, + url:a.url + } + }); + + return { isBoost:false, - title:'', + title:'New Status by '+user.preferredUsername, isReply:!!(item.object && item.object.inReplyTo), hasCw:false, cw:'', + content: item.object&&item.object.content?item.object.content:'',//TODO sanitize then render without entity escapes atomHref:item.published?item.published.replace(/\W+/g,''):Math.random().toString().replace('.',''), - enclosures:[],//type, url + enclosures:enclosures, stringDate:item.published?getTimeDisplay(Date.parse(item.published)):'', author:{ - uri:'',// link to author page - avatar:'',// url of av - fullName:'',// display name + uri:user.url,// link to author page + avatar:user.icon&&user.icon.url?user.icon.url:'', + displayName:user.name, + fullName:user.preferredUsername+'@'+(new URL(user.url).hostname), } } }) } // TODO -function getNextPage(user,feed){ - return null; +function getNextPage(opts,user,feed){ + //based on feed.next + // take feed.next, uriencode it, then take user url, then take options.mastofeedUrl + var base = opts.mastofeedUrl.slice(0,opts.mastofeedUrl.indexOf('?')); + + var ret = '/apiv2/feed?userurl=' + encodeURIComponent(opts.userUrl) + '&feedurl=' +encodeURIComponent(feed.next); + + // add other params to the end + (['theme','header','size','boosts','replies']).forEach((k)=>{ + if (typeof opts[k] != 'undefined'){ + ret+=`&${k}=${ opts[k].toString() }`; + } + }) + return ret; } diff --git a/lib/template.ejs b/lib/template.ejs index ed0aac7..f26e7ed 100644 --- a/lib/template.ejs +++ b/lib/template.ejs @@ -32,7 +32,7 @@ <%= meta.title %>
- <%= meta.description %> + <%- meta.description %>